qpid::client::MessageListener Class Reference

Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions
qpid::client::MessageListener Class Reference

Implement a subclass of MessageListener and subscribe it using the SubscriptionManager to receive messages. More...

`#include <qpid/client/MessageListener.h>`

List of all members.

## Public Member Functions
virtual | ~MessageListener ()
virtual void | received (Message &msg)=0
| Called for each message arriving from the broker.

## Detailed Description

Implement a subclass of MessageListener and subscribe it using the SubscriptionManager to receive messages.

Another way to receive messages is by using a LocalQueue.

## Using a MessageListener

- The received() function is called when a message arrives:

      virtual void received(Message& message)=0;

- Derive your own listener, implement the received() function:

       class Listener : public MessageListener {
        private:
          SubscriptionManager& subscriptions;
        public:
          Listener(SubscriptionManager& subscriptions);
          virtual void received(Message& message);
       };

       Listener::Listener(SubscriptionManager& subs) : subscriptions(subs)
       {}

       void Listener::received(Message& message) {
         std::cout << "Message: " << message.getData() << std::endl;
         if (message.getData() == "That's all, folks!") {
             std::cout << "Shutting down listener for " << message.getDestination()
                      << std::endl;
             subscriptions.cancel(message.getDestination());
         }
       }

       SubscriptionManager subscriptions(session);

       // Create a listener and subscribe it to the queue named "message_queue"
       Listener listener(subscriptions);
       subscriptions.subscribe(listener, "message_queue");

       // Receive messages until the subscription is cancelled
       // by Listener::received()
       subscriptions.run();

## Constructor & Destructor Documentation

virtual qpid::client::MessageListener::~MessageListener | ( |  | ) | `[virtual]`

## Member Function Documentation

virtual void qpid::client::MessageListener::received | ( | Message & | msg | ) | `[pure virtual]`

Called for each message arriving from the broker.

Override in your own subclass to process messages.

The documentation for this class was generated from the following file:

- qpid/client/MessageListener.h