June 2018
Intermediate to advanced
408 pages
11h 23m
English
Now, we will create a Consumer listener class with the @RabbitListener annotated method, which will receive the message from RabbitMQ:
@Servicepublic class Consumer { private static final Logger LOGGER = Logger.getLogger(Consumer.class); @RabbitListener(containerFactory = "listenerContainer", queues = RabbitMqConfiguration.RABBIT_MESSAGE_QUEUE) public void onMessage(Message message) { LOGGER.info("Received Message: " + new String(message.getBody())); }}
This is the message listenerContainer class. Whenever, producer sends a message to the queue, this class will receive it and only the method with the @RabbitListener(containerFactory = "listenerContainer", queues = RabbitMqConfiguration.RABBIT_MESSAGE_QUEUE)
Read now
Unlock full access