From ff530085b008663aca994c99b6e9ae3d90c24bf1 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 19 Nov 2009 11:46:00 +0000 Subject: QPID-664: Add spout & drain examples as per python client git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@882118 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 190 ++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 qpid/cpp/examples/messaging/spout.cpp (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp new file mode 100644 index 0000000000..18abe8863a --- /dev/null +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -0,0 +1,190 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +using namespace qpid::messaging; +using qpid::framing::Uuid; +using qpid::sys::AbsTime; +using qpid::sys::now; +using qpid::sys::TIME_INFINITE; + +typedef std::vector string_vector; + +struct Options : public qpid::Options +{ + bool help; + std::string url; + std::string address; + int64_t timeout; + uint count; + std::string id; + std::string replyto; + string_vector properties; + string_vector entries; + std::string content; + qpid::log::Options log; + + Options(const std::string& argv0=std::string()) + : qpid::Options("Options"), + help(false), + url("amqp:tcp:127.0.0.1"), + timeout(TIME_INFINITE), + count(1), + log(argv0) + { + addOptions() + ("broker,b", qpid::optValue(url, "URL"), "url of broker to connect to") + ("address,a", qpid::optValue(address, "ADDRESS"), "address to drain from") + ("timeout,t", qpid::optValue(timeout, "TIMEOUT"), "exit after the specified time") + ("count,c", qpid::optValue(count, "COUNT"), "stop after count messages have been sent, zero disables") + ("id,i", qpid::optValue(id, "ID"), "use the supplied id instead of generating one") + ("reply-to", qpid::optValue(replyto, "REPLY-TO"), "specify reply-to address") + ("property,P", qpid::optValue(properties, "NAME=VALUE"), "specify message property") + ("entry,E", qpid::optValue(entries, "NAME=VALUE"), "specify entry for map content") + ("content", qpid::optValue(content, "CONTENT"), "specify textual content") + ("help", qpid::optValue(help), "print this usage statement"); + add(log); + } + + bool parse(int argc, char** argv) + { + try { + qpid::Options::parse(argc, argv); + if (address.empty()) throw qpid::Exception("Address must be specified!"); + qpid::log::Logger::instance().configure(log); + if (help) { + std::ostringstream msg; + std::cout << msg << *this << std::endl << std::endl + << "Drains messages from the specified address" << std::endl; + return false; + } else { + return true; + } + } catch (const std::exception& e) { + std::cerr << *this << std::endl << std::endl << e.what() << std::endl; + return false; + } + } + + static bool nameval(const std::string& in, std::string& name, std::string& value) + { + std::string::size_type i = in.find("="); + if (i == std::string::npos) { + name = in; + return false; + } else { + name = in.substr(0, i); + if (i+1 < in.size()) { + value = in.substr(i+1); + return true; + } else { + return false; + } + } + } + + static void setProperty(Message& message, const std::string& property) + { + std::string name; + std::string value; + if (nameval(property, name, value)) { + message.getHeaders()[name] = value; + } else { + message.getHeaders()[name] = Variant(); + } + } + + void setProperties(Message& message) const + { + for (string_vector::const_iterator i = properties.begin(); i != properties.end(); ++i) { + setProperty(message, *i); + } + } + + void setEntries(MapContent& content) const + { + for (string_vector::const_iterator i = entries.begin(); i != entries.end(); ++i) { + std::string name; + std::string value; + if (nameval(*i, name, value)) { + content[name] = value; + } else { + content[name] = Variant(); + } + } + } +}; + + +int main(int argc, char** argv) +{ + Options options(argv[0]); + if (options.parse(argc, argv)) { + try { + Connection connection = Connection::open(options.url); + Session session = connection.newSession(); + Sender sender = session.createSender(options.address); + + Message message; + options.setProperties(message); + if (options.entries.size()) { + MapContent content(message); + options.setEntries(content); + content.encode(); + } else if (options.content.size()) { + message.setContent(options.content); + message.setContentType("text/plain; charset=utf8"); + } + AbsTime end(now(), options.timeout); + for (uint count = 0; (count < options.count || options.count == 0) && end > now(); count++) { + if (!options.replyto.empty()) message.setReplyTo(Address(options.replyto)); + std::string id = options.id.empty() ? Uuid(true).str() : options.id; + message.getHeaders()["spout-id"] = (boost::format("%1%:%2%") % id % count).str(); + sender.send(message); + } + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + } + return 1; +} + + -- cgit v1.2.1 From 7e6b260dbd83d78a23b2e77a54972018733eec9c Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 20 Nov 2009 11:00:59 +0000 Subject: Change spout option name to match equivalent python example git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@882500 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 18abe8863a..661397d232 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -76,7 +76,7 @@ struct Options : public qpid::Options ("id,i", qpid::optValue(id, "ID"), "use the supplied id instead of generating one") ("reply-to", qpid::optValue(replyto, "REPLY-TO"), "specify reply-to address") ("property,P", qpid::optValue(properties, "NAME=VALUE"), "specify message property") - ("entry,E", qpid::optValue(entries, "NAME=VALUE"), "specify entry for map content") + ("map,M", qpid::optValue(entries, "NAME=VALUE"), "specify entry for map content") ("content", qpid::optValue(content, "CONTENT"), "specify textual content") ("help", qpid::optValue(help), "print this usage statement"); add(log); -- cgit v1.2.1 From 04db3be5386fbc601d11fab7da48b592c997c590 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 15 Jan 2010 15:17:01 +0000 Subject: QPID-2323: add a Uuid type and allow it as the value of a Variant. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@899657 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 661397d232..62d72a8043 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -39,7 +38,6 @@ #include using namespace qpid::messaging; -using qpid::framing::Uuid; using qpid::sys::AbsTime; using qpid::sys::now; using qpid::sys::TIME_INFINITE; -- cgit v1.2.1 From 1e275cd7e3c1eb5e8e0fbe550b846bbfe2309d51 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 28 Jan 2010 08:37:37 +0000 Subject: QPID-664: change format of connection options string to match address options; make open() a non-static method. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@904000 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 62d72a8043..cbb6b52b34 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -56,6 +56,7 @@ struct Options : public qpid::Options string_vector properties; string_vector entries; std::string content; + std::string connectionOptions; qpid::log::Options log; Options(const std::string& argv0=std::string()) @@ -76,6 +77,7 @@ struct Options : public qpid::Options ("property,P", qpid::optValue(properties, "NAME=VALUE"), "specify message property") ("map,M", qpid::optValue(entries, "NAME=VALUE"), "specify entry for map content") ("content", qpid::optValue(content, "CONTENT"), "specify textual content") + ("connection-options", qpid::optValue(connectionOptions,"OPTIONS"), "connection options string in the form {name1=value1, name2=value2}") ("help", qpid::optValue(help), "print this usage statement"); add(log); } @@ -155,7 +157,8 @@ int main(int argc, char** argv) Options options(argv[0]); if (options.parse(argc, argv)) { try { - Connection connection = Connection::open(options.url); + Connection connection(options.connectionOptions); + connection.open(options.url); Session session = connection.newSession(); Sender sender = session.createSender(options.address); -- cgit v1.2.1 From ed9e0f6f6685439791d3af2985ff36a9707ce5e1 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 19 Mar 2010 17:04:18 +0000 Subject: QPID-664: Prevent dangling pointers when receiver/sender handles stay in scope after connection/session handles goes out of scope. This change require connections to be closed explicitly to avoid leaking memory. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@925332 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index cbb6b52b34..4819c6bc00 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -156,8 +156,8 @@ int main(int argc, char** argv) { Options options(argv[0]); if (options.parse(argc, argv)) { + Connection connection(options.connectionOptions); try { - Connection connection(options.connectionOptions); connection.open(options.url); Session session = connection.newSession(); Sender sender = session.createSender(options.address); @@ -183,6 +183,7 @@ int main(int argc, char** argv) return 0; } catch(const std::exception& error) { std::cout << error.what() << std::endl; + connection.close(); } } return 1; -- cgit v1.2.1 From 7e92a02008a01cc824bc34dd7296791b4d8912e5 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Mon, 29 Mar 2010 16:00:24 +0000 Subject: QPID-664: move Variant and Uuid from messaging to types namespace git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@928814 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 4819c6bc00..e9a6987f5c 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -38,6 +38,7 @@ #include using namespace qpid::messaging; +using namespace qpid::types; using qpid::sys::AbsTime; using qpid::sys::now; using qpid::sys::TIME_INFINITE; -- cgit v1.2.1 From beb68a5d1b8d74f4c53299c81911a3ad85011f17 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Mon, 29 Mar 2010 19:21:26 +0000 Subject: QPID-664: renamed headers as properties (to match python); added priority git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@928878 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index e9a6987f5c..4b67945317 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -125,9 +125,9 @@ struct Options : public qpid::Options std::string name; std::string value; if (nameval(property, name, value)) { - message.getHeaders()[name] = value; + message.getProperties()[name] = value; } else { - message.getHeaders()[name] = Variant(); + message.getProperties()[name] = Variant(); } } @@ -177,7 +177,7 @@ int main(int argc, char** argv) for (uint count = 0; (count < options.count || options.count == 0) && end > now(); count++) { if (!options.replyto.empty()) message.setReplyTo(Address(options.replyto)); std::string id = options.id.empty() ? Uuid(true).str() : options.id; - message.getHeaders()["spout-id"] = (boost::format("%1%:%2%") % id % count).str(); + message.getProperties()["spout-id"] = (boost::format("%1%:%2%") % id % count).str(); sender.send(message); } connection.close(); -- cgit v1.2.1 From e148043f68f2f71b057d191177dcdf83156f642a Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 31 Mar 2010 16:17:17 +0000 Subject: QPID-664: made changes suggested by Alan Conway, also moved 0-10 map/list codecs to common lib git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@929606 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 4b67945317..61b3f88711 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -138,7 +137,7 @@ struct Options : public qpid::Options } } - void setEntries(MapContent& content) const + void setEntries(Variant::Map& content) const { for (string_vector::const_iterator i = entries.begin(); i != entries.end(); ++i) { std::string name; @@ -160,18 +159,18 @@ int main(int argc, char** argv) Connection connection(options.connectionOptions); try { connection.open(options.url); - Session session = connection.newSession(); + Session session = connection.createSession(); Sender sender = session.createSender(options.address); Message message; options.setProperties(message); if (options.entries.size()) { - MapContent content(message); + Variant::Map content; options.setEntries(content); - content.encode(); + encode(content, message); } else if (options.content.size()) { message.setContent(options.content); - message.setContentType("text/plain; charset=utf8"); + message.setContentType("text/plain"); } AbsTime end(now(), options.timeout); for (uint count = 0; (count < options.count || options.count == 0) && end > now(); count++) { -- cgit v1.2.1 From 13d4a7f61d6b4b9935d88e97d14eda29c9ad0950 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 8 Apr 2010 09:49:04 +0000 Subject: QPID-664: changed open() to connect(), moved url parameter to constructor, added detach() and isConnected() git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@931852 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 61b3f88711..9ed8b642c8 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -156,9 +156,9 @@ int main(int argc, char** argv) { Options options(argv[0]); if (options.parse(argc, argv)) { - Connection connection(options.connectionOptions); + Connection connection(options.url, options.connectionOptions); try { - connection.open(options.url); + connection.connect(); Session session = connection.createSession(); Sender sender = session.createSender(options.address); -- cgit v1.2.1 From 0aaa340fa8c3b994790b355950d358af3b0979e2 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 9 Apr 2010 15:08:47 +0000 Subject: QPID-664: changed connect() back to open(),removed detach(),defined new exception hierarchy, added ability to re-use reconnect/replay logic for resource-limit-exceeded errors git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@932451 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 9ed8b642c8..2e9e91bfba 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -158,7 +158,7 @@ int main(int argc, char** argv) if (options.parse(argc, argv)) { Connection connection(options.url, options.connectionOptions); try { - connection.connect(); + connection.open(); Session session = connection.createSession(); Sender sender = session.createSender(options.address); -- cgit v1.2.1 From 41fcacf52840250f19c6652cfe0c055679aad387 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 5 May 2010 11:17:41 +0000 Subject: Some cleanup on examples: * removed obsolete examples (queue-/topic-sender/receiver) * removed the need to include headers with boost dependencies * moved the argument handling in darin and spout closer to that of python (and update docs to reflect that) * changed to ship a manually constructed makefile for messaging examples (generated one doesn't work and maintaining that seems like more work with little benefit) git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@941250 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 93 ++++++++++++++--------------------- 1 file changed, 38 insertions(+), 55 deletions(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 2e9e91bfba..275ca416bc 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -25,16 +25,13 @@ #include #include #include -#include -#include -#include -#include #include #include +#include #include -#include +#include "OptionParser.h" using namespace qpid::messaging; using namespace qpid::types; @@ -44,62 +41,34 @@ using qpid::sys::TIME_INFINITE; typedef std::vector string_vector; -struct Options : public qpid::Options +struct Options : OptionParser { - bool help; std::string url; std::string address; - int64_t timeout; - uint count; + int timeout; + int count; std::string id; std::string replyto; string_vector properties; string_vector entries; std::string content; std::string connectionOptions; - qpid::log::Options log; - - Options(const std::string& argv0=std::string()) - : qpid::Options("Options"), - help(false), - url("amqp:tcp:127.0.0.1"), - timeout(TIME_INFINITE), - count(1), - log(argv0) - { - addOptions() - ("broker,b", qpid::optValue(url, "URL"), "url of broker to connect to") - ("address,a", qpid::optValue(address, "ADDRESS"), "address to drain from") - ("timeout,t", qpid::optValue(timeout, "TIMEOUT"), "exit after the specified time") - ("count,c", qpid::optValue(count, "COUNT"), "stop after count messages have been sent, zero disables") - ("id,i", qpid::optValue(id, "ID"), "use the supplied id instead of generating one") - ("reply-to", qpid::optValue(replyto, "REPLY-TO"), "specify reply-to address") - ("property,P", qpid::optValue(properties, "NAME=VALUE"), "specify message property") - ("map,M", qpid::optValue(entries, "NAME=VALUE"), "specify entry for map content") - ("content", qpid::optValue(content, "CONTENT"), "specify textual content") - ("connection-options", qpid::optValue(connectionOptions,"OPTIONS"), "connection options string in the form {name1=value1, name2=value2}") - ("help", qpid::optValue(help), "print this usage statement"); - add(log); - } - bool parse(int argc, char** argv) + Options() + : OptionParser("Usage: spout [OPTIONS] ADDRESS", "Send messages to the specified address"), + url("127.0.0.1"), + timeout(0), + count(1) { - try { - qpid::Options::parse(argc, argv); - if (address.empty()) throw qpid::Exception("Address must be specified!"); - qpid::log::Logger::instance().configure(log); - if (help) { - std::ostringstream msg; - std::cout << msg << *this << std::endl << std::endl - << "Drains messages from the specified address" << std::endl; - return false; - } else { - return true; - } - } catch (const std::exception& e) { - std::cerr << *this << std::endl << std::endl << e.what() << std::endl; - return false; - } + add("broker,b", url, "url of broker to connect to"); + add("timeout,t", timeout, "exit after the specified time"); + add("count,c", count, "stop after count messages have been sent, zero disables"); + add("id,i", id, "use the supplied id instead of generating one"); + add("reply-to", replyto, "specify reply-to address"); + add("property,P", properties, "specify message property"); + add("map,M", entries, "specify entry for map content"); + add("content", content, "specify textual content"); + add("connection-options", connectionOptions, "connection options string in the form {name1=value1, name2=value2}"); } static bool nameval(const std::string& in, std::string& name, std::string& value) @@ -149,13 +118,24 @@ struct Options : public qpid::Options } } } + + bool checkAddress() + { + if (getArguments().empty()) { + error("Address is required"); + return false; + } else { + address = getArguments()[0]; + return true; + } + } }; int main(int argc, char** argv) { - Options options(argv[0]); - if (options.parse(argc, argv)) { + Options options; + if (options.parse(argc, argv) && options.checkAddress()) { Connection connection(options.url, options.connectionOptions); try { connection.open(); @@ -172,12 +152,15 @@ int main(int argc, char** argv) message.setContent(options.content); message.setContentType("text/plain"); } - AbsTime end(now(), options.timeout); - for (uint count = 0; (count < options.count || options.count == 0) && end > now(); count++) { + AbsTime end(now(), options.timeout * qpid::sys::TIME_SEC); + for (int count = 0; (count < options.count || options.count == 0) && (options.timeout == 0 || end > now()); count++) { if (!options.replyto.empty()) message.setReplyTo(Address(options.replyto)); std::string id = options.id.empty() ? Uuid(true).str() : options.id; - message.getProperties()["spout-id"] = (boost::format("%1%:%2%") % id % count).str(); + std::stringstream spoutid; + spoutid << id << ":" << count; + message.getProperties()["spout-id"] = spoutid.str(); sender.send(message); + std::cout << "Sent " << (count+1) << " of " << options.count << " messages" < Date: Wed, 5 May 2010 14:22:25 +0000 Subject: Allow empty subject for direct- and xml- exchanges git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@941306 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 275ca416bc..05d66f60e6 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -160,7 +160,6 @@ int main(int argc, char** argv) spoutid << id << ":" << count; message.getProperties()["spout-id"] = spoutid.str(); sender.send(message); - std::cout << "Sent " << (count+1) << " of " << options.count << " messages" < Date: Thu, 3 Jun 2010 20:48:53 +0000 Subject: Remove dependency on qpid::sys::AbsTime (which uses boost on Windows) git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@951150 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 05d66f60e6..e100560739 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -25,19 +25,16 @@ #include #include #include -#include #include #include #include +#include #include "OptionParser.h" using namespace qpid::messaging; using namespace qpid::types; -using qpid::sys::AbsTime; -using qpid::sys::now; -using qpid::sys::TIME_INFINITE; typedef std::vector string_vector; @@ -152,8 +149,11 @@ int main(int argc, char** argv) message.setContent(options.content); message.setContentType("text/plain"); } - AbsTime end(now(), options.timeout * qpid::sys::TIME_SEC); - for (int count = 0; (count < options.count || options.count == 0) && (options.timeout == 0 || end > now()); count++) { + std::time_t start = std::time(0); + for (int count = 0; + (count < options.count || options.count == 0) && + (options.timeout == 0 || std::difftime(std::time(0), start) < options.timeout); + count++) { if (!options.replyto.empty()) message.setReplyTo(Address(options.replyto)); std::string id = options.id.empty() ? Uuid(true).str() : options.id; std::stringstream spoutid; -- cgit v1.2.1 From 9b98d16351d428295a9108ff53994bc80f92e46d Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 24 Jun 2010 11:34:18 +0000 Subject: Ensure spout example waits for all messages to be sent before detaching session git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@957513 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index e100560739..57b955c1de 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -161,6 +161,7 @@ int main(int argc, char** argv) message.getProperties()["spout-id"] = spoutid.str(); sender.send(message); } + session.sync(); connection.close(); return 0; } catch(const std::exception& error) { -- cgit v1.2.1 From 5fc71831f13dca8ebfef47544a63ae27691d2542 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 20 May 2011 09:38:08 +0000 Subject: QPID-3268: correct connection option syntax in usage statement git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1125295 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/messaging/spout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qpid/cpp/examples/messaging/spout.cpp') diff --git a/qpid/cpp/examples/messaging/spout.cpp b/qpid/cpp/examples/messaging/spout.cpp index 57b955c1de..cd11a7ad81 100644 --- a/qpid/cpp/examples/messaging/spout.cpp +++ b/qpid/cpp/examples/messaging/spout.cpp @@ -65,7 +65,7 @@ struct Options : OptionParser add("property,P", properties, "specify message property"); add("map,M", entries, "specify entry for map content"); add("content", content, "specify textual content"); - add("connection-options", connectionOptions, "connection options string in the form {name1=value1, name2=value2}"); + add("connection-options", connectionOptions, "connection options string in the form {name1:value1, name2:value2}"); } static bool nameval(const std::string& in, std::string& name, std::string& value) -- cgit v1.2.1