Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
Implement a subclass of MessageListener and subscribe it using the SubscriptionManager to receive messages. More...
#include <qpid/client/MessageListener.h>
Public Member Functions | |
virtual | ~MessageListener () |
virtual void | received (Message &msg)=0 |
Called for each message arriving from the broker. |
Implement a subclass of MessageListener and subscribe it using the SubscriptionManager to receive messages.
Another way to receive messages is by using a LocalQueue.
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();
Definition at line 87 of file MessageListener.h.
virtual qpid::client::MessageListener::~MessageListener | ( | ) | [virtual] |
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.