summaryrefslogtreecommitdiff
path: root/cpp/examples/messaging/drain.cpp
diff options
context:
space:
mode:
authorJonathan Robie <jonathan@apache.org>2010-08-19 20:41:17 +0000
committerJonathan Robie <jonathan@apache.org>2010-08-19 20:41:17 +0000
commitfba262b85b698d8b952414ca30ff26721552f79c (patch)
tree2036e02ff142d61b1752fcaac58b133739a95886 /cpp/examples/messaging/drain.cpp
parent31a02f6d7c84a7b10b295967f6a06551171e7c28 (diff)
downloadqpid-python-fba262b85b698d8b952414ca30ff26721552f79c.tar.gz
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
Diffstat (limited to 'cpp/examples/messaging/drain.cpp')
-rw-r--r--cpp/examples/messaging/drain.cpp15
1 files changed, 14 insertions, 1 deletions
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();