O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a message receiver

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)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required