doublefox1981 wrote:
int main(int argc, char** argv) {
  const char* host = argc>1 ? argv[1] : "192.168.1.233";
  int port = argc>2 ? atoi(argv[2]) : 5672;
  Connection connection;
  try {
    ConnectionSettings Setting;
    Setting.host = host;
    Setting.port = port;
    Setting.username = "uniqueeye";
    Setting.password = "uniqueeye";
    Setting.virtualhost = "/";
    Setting.maxFrameSize = 65535;
    Setting.mechanism = "PLAIN";
    connection.open(Setting);
    Session session =  connection.newSession();
    //--------- Main body of program 
--------------------------------------------
// Create a request queue for clients to use when making
    // requests.
    string request_queue = "request";
    // Use the name of the request queue as the routing key
    session.queueDeclare(arg::queue=request_queue);
    session.exchangeBind(arg::exchange="amq.direct", arg::queue=request_queue, 
arg::bindingKey=request_queue);
    // Create a listener and subscribe it to the request_queue
    std::cout << "Activating request queue listener for: " << request_queue << 
std::endl;
    SubscriptionManager subscriptions(session);
    Listener listener(subscriptions, session);
    subscriptions.subscribe(listener, request_queue);

Here you are setting up a subscription for message from request_queue that will be dispatched to your listener, however you are never starting the dispatching. Consequently incoming messages for this subscription will simply queue up, never being processed.

If you don't want to dispatch messages to the listener (preferring to pull messages off using SubscriptionManager::get()) you should remove the two lines above from your code.

    // Deliver messages until the subscription is cancelled
    // by Listener::received()
    std::cout << "Waiting for requests" << std::endl;
    //subscriptions.run();
    Message Repuest;
    while (1)
    {
      bool HaveMessage = 
subscriptions.get(Repuest,request_queue,1*qpid::sys::TIME_MSEC);
      if(HaveMessage)
      {
        string routingKey;
if (Repuest.getMessageProperties().hasReplyTo()) {
          routingKey = 
Repuest.getMessageProperties().getReplyTo().getRoutingKey();
} else {
          std::cout << "Error: " << "No routing key for request (" << Repuest.getData() << 
")" << std::endl;
} }
     // my other code
      Sleep(1);
    }
//-----------------------------------------------------------------------------
    connection.close();
    return 0;
  } catch(const std::exception& error) {
    std::cout << error.what() << std::endl;
  }
  return 1;
}
this is my sample code, anything wrong with it? ------------------
何文辉



------------------ Original ------------------ From: "Steve Huston (via Nabble)"<[email protected]>;
 Date: 2009年4月14日(星期二) 晚上10:58
To: "doublefox1981"<[email protected]>; Subject: RE: c++ client , memory leak?

SubscriptionManager subscriptions(session); Listener listener(subscriptions, session); subscriptions.run() because this block the thread, so i use subscriptions.get() in my mainloop

That is not necessary... Your MessageListener::received() method will be called when new messages arrive.
but i found the memory used by this process increase all the time, anybody happen this? help me. Thanks

What OS and qpid version is this? What data did you collect to detect the memory leak? -Steve

--------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:dev-subscr...@...


This email is a reply to your post @ http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2633614.html
You can reply by email or by visting the link above.


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to