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);
// 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.
--
View this message in context:
http://n2.nabble.com/c%2B%2B-client-%2C-memory-leak--tp2633382p2636274.html
Sent from the Apache Qpid developers mailing list archive at Nabble.com.