qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew L <khayman...@hotmail.com>
Subject Cancelling subscription prevents subsequent subscriptions?
Date Thu, 12 Aug 2010 18:05:11 GMT

I am trying to use a single SubscriptionManager to create and cancel multiple subscriptions.
 After canceling a subscription, future subscriptions created by the SubscriptionManager would
never be delivered messages.  I modified the example program to test it and got the same results.
 
 
Should this consumer not receive any messages on message_queue2?
 
If I comment out the sub.cancel() and the subsequent manager.run() the application receives
messages on both subscriptions successfully.  
 
#include <qpid/client/Connection.h>
#include <qpid/client/Session.h>
#include <qpid/client/Message.h>
#include <qpid/client/MessageListener.h>
#include <qpid/client/SubscriptionManager.h>
#include <cstdlib>
#include <iostream>
using namespace qpid::client;
using namespace qpid::framing;

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;
}
int main(int argc, char** argv) {
    const char* host = argc>1 ? argv[1] : "127.0.0.1";
    int port = argc>2 ? atoi(argv[2]) : 5672;
    Connection connection;
    try {
      connection.open(host, port);
      Session session =  connection.newSession();
  //--------- Main body of program --------------------------------------------
      SubscriptionManager subscriptions(session);
      // Create a listener and subscribe it to the queue named "message_queue"
      Listener listener(subscriptions), listener2(subscriptions);
      Subscription sub = subscriptions.subscribe(listener,
"message_queue");
      // Receive messages until the subscription is cancelled
      // by Listener::received()
      subscriptions.start();
  //---------------------------------------------------------------------------
        char test;
        std::cout << "input" << std::endl;
        std::cin >> test;
      sub.cancel();
        std::cout << " again " << std::endl;
        std::cin >> test;
        sub = subscriptions.subscribe(listener2, "message_queue2");
      subscriptions.run();
        std::cout << "after start" << std::endl;
        std::cout << " 222" << std::endl;
        std::cin >> test;
      connection.close();
      return 0;
    } catch(const std::exception& error) {
        std::cout << error.what() << std::endl;
    }
    return 1;
}
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message