Skip to content

Instantly share code, notes, and snippets.

@tacsio
Forked from timpamungkasudemy/InvoiceListener.java
Created August 21, 2022 15:34
Show Gist options
  • Save tacsio/a9099a77e71ecc4484e2171ab73f024e to your computer and use it in GitHub Desktop.
Save tacsio/a9099a77e71ecc4484e2171ab73f024e 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