Skip to content

Instantly share code, notes, and snippets.

@timpamungkasudemy
Created October 27, 2019 03:51
Show Gist options
  • Save timpamungkasudemy/4f043e247d286f67b18b420f32ea941c to your computer and use it in GitHub Desktop.
Save timpamungkasudemy/4f043e247d286f67b18b420f32ea941c to your computer and use it in GitHub Desktop.
Sample Listener if you don't have __TypeID__ but have other header (for example : type)
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;
import com.course.finance.message.invoice.InvoiceCreatedMessage;
import com.course.finance.message.invoice.InvoicePaidMessage;
@Service
@RabbitListener(queues = "q.invoice")
public class InvoiceListener {
private static final Logger log = LoggerFactory.getLogger(InvoiceListener.class);
@RabbitHandler
public void listenInvoiceCreated(InvoiceCreatedMessage message) {
log.info("Listening invoice created : {}", message);
}
@RabbitHandler
public void listenInvoicePaid(InvoicePaidMessage message) {
log.info("Listening invoice paid : {}", message);
}
@RabbitHandler(isDefault = true)
public void listenDefault(Message message) {
log.info("Default invoice listener : {}", message.getMessageProperties().getHeaders());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment