From fba262b85b698d8b952414ca30ff26721552f79c Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Thu, 19 Aug 2010 20:41:17 +0000 Subject: Added -c count parameter - exits after reading c messages. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@987304 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/examples/messaging/drain.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'cpp/examples/messaging/drain.cpp') diff --git a/cpp/examples/messaging/drain.cpp b/cpp/examples/messaging/drain.cpp index 6edcac2789..8c3abdbb14 100644 --- a/cpp/examples/messaging/drain.cpp +++ b/cpp/examples/messaging/drain.cpp @@ -38,17 +38,20 @@ struct Options : OptionParser std::string connectionOptions; int timeout; bool forever; + int count; Options() : OptionParser("Usage: drain [OPTIONS] ADDRESS", "Drains messages from the specified address"), url("127.0.0.1"), timeout(0), - forever(false) + forever(false), + count(1) { add("broker,b", url, "url of broker to connect to"); add("timeout,t", timeout, "timeout in seconds to wait before exiting"); add("forever,f", forever, "ignore timeout and wait forever"); add("connection-options", connectionOptions, "connection options string in the form {name1=value1, name2=value2}"); + add("count,c", count, "number of messages to read before exiting"); } Duration getTimeout() @@ -56,6 +59,11 @@ struct Options : OptionParser if (forever) return Duration::FOREVER; else return timeout*Duration::SECOND; } + + int getCount() + { + return count; + } bool checkAddress() { @@ -79,7 +87,10 @@ int main(int argc, char** argv) Session session = connection.createSession(); Receiver receiver = session.createReceiver(options.address); Duration timeout = options.getTimeout(); + int count = options.getCount(); Message message; + int i = 0; + while (receiver.fetch(message, timeout)) { std::cout << "Message(properties=" << message.getProperties() << ", content='" ; if (message.getContentType() == "amqp/map") { @@ -91,6 +102,8 @@ int main(int argc, char** argv) } std::cout << "')" << std::endl; session.acknowledge(); + if (count and ++i == count) + break; } receiver.close(); session.close(); -- cgit v1.2.1