Book Image

Mastering Spring Application Development

By : Anjana Mankale
Book Image

Mastering Spring Application Development

By: Anjana Mankale

Overview of this book

Table of Contents (19 chapters)
Mastering Spring Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with multiple queues in ApacheMQ


In the preceding section, we demonstrated sending messages using Map Message to Order Queue. Now, we can have a look at how to work with multiple queues in ApacheMQ:

  1. Start the Apache ActiveMQ server, and in the console, click on Queues and create two queues.

  2. Let us create two queues and name the queues as follows:

    • PacktTestQueue1

    • PacktTestQueue2

  3. Create a new Spring project with the same dependency as the first example in the chapter.

  4. Create a PacktMessageListener class that implements the MessageListener interface. The class overrides the onMessage(Message message) method.

  5. Spring's DefaultMessageListener consumes the messages from the queue and calls the onMessage(Message message) method.

    PacktMessageListener:
    package com.packt.jms;
    
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.TextMessage;
    
    public class  PacktMessageListener implements MessageListener{
      private PacktMessageSender packtmessagesender...