Skip to content

Instantly share code, notes, and snippets.

@tacsio
Forked from timpamungkasudemy/ListenerSample.java
Created August 21, 2022 15:34
Show Gist options
  • Save tacsio/036a0fb0e8181b3a634221be460d21b4 to your computer and use it in GitHub Desktop.
Save tacsio/036a0fb0e8181b3a634221be460d21b4 to your computer and use it in GitHub Desktop.
Sample Listener if you don't have __TypeID__ but have other header (for example : type)
public class ListenerSample {
// Adjust the header name if required, on @Header parameter
@RabbitListener(queues = "q.finance.invoice")
public void listenInvoiceCreated(@Payload String message, @Header(AmqpHeaders.DELIVERY_TAG) long tag,
@Header("type") String type) throws IOException {
if (StringUtils.equalsIgnoreCase(type, "invoice.paid")) {
log.info("Delegate to invoice paid handler");
} else if (StringUtils.equalsIgnoreCase(type, "invoice.created")) {
log.info("Delegate to invoice created handler");
} else {
log.info("Delegate to default handler");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment