Skip to content

Instantly share code, notes, and snippets.

@timpamungkasudemy
Created October 27, 2019 03:39
Show Gist options
  • Save timpamungkasudemy/f927f2d00de77ffd3a192d57d4467667 to your computer and use it in GitHub Desktop.
Save timpamungkasudemy/f927f2d00de77ffd3a192d57d4467667 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