From d843260b5ca7b8945144c27e584777c9b6da276a Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 20 Jun 2008 21:23:23 +0000 Subject: Patch from Manuel Teira: https://issues.apache.org/jira/secure/CommentAssignIssue!default.jspa?action=5&id=12398038 - Use standard automake makefiles to build cpp/examples. - Rationalize examples directory structure. Additions to patch: - Fix for VPATH builds. - Fix make distcheck (finally!) git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@670066 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/examples/Makefile | 6 + qpid/cpp/examples/Makefile.am | 86 +++-------- qpid/cpp/examples/README.verify | 26 ++++ qpid/cpp/examples/direct/Makefile.am | 29 ++++ qpid/cpp/examples/direct/declare_queues.cpp | 86 +++++++++++ qpid/cpp/examples/direct/direct_producer.cpp | 109 +++++++++++++ qpid/cpp/examples/direct/listener.cpp | 89 +++++++++++ qpid/cpp/examples/direct/verify | 3 + qpid/cpp/examples/direct/verify.in | 15 ++ qpid/cpp/examples/direct/verify_cpp_python | 4 + qpid/cpp/examples/direct/verify_cpp_python.in | 14 ++ qpid/cpp/examples/direct/verify_python_cpp | 5 + qpid/cpp/examples/direct/verify_python_cpp.in | 15 ++ qpid/cpp/examples/examples/Makefile | 6 - qpid/cpp/examples/examples/README | 127 --------------- qpid/cpp/examples/examples/direct/Makefile | 10 -- .../examples/examples/direct/declare_queues.cpp | 86 ----------- .../examples/examples/direct/direct_producer.cpp | 109 ------------- qpid/cpp/examples/examples/direct/listener.cpp | 89 ----------- qpid/cpp/examples/examples/direct/verify | 3 - qpid/cpp/examples/examples/direct/verify.in | 15 -- .../cpp/examples/examples/direct/verify_cpp_python | 4 - .../examples/examples/direct/verify_cpp_python.in | 14 -- .../cpp/examples/examples/direct/verify_python_cpp | 5 - .../examples/examples/direct/verify_python_cpp.in | 15 -- qpid/cpp/examples/examples/fanout/Makefile | 10 -- .../examples/examples/fanout/fanout_producer.cpp | 107 ------------- qpid/cpp/examples/examples/fanout/listener.cpp | 107 ------------- qpid/cpp/examples/examples/fanout/verify | 6 - qpid/cpp/examples/examples/fanout/verify.in | 43 ------ .../cpp/examples/examples/fanout/verify_cpp_python | 7 - .../examples/examples/fanout/verify_cpp_python.in | 27 ---- .../cpp/examples/examples/fanout/verify_python_cpp | 7 - .../examples/examples/fanout/verify_python_cpp.in | 29 ---- qpid/cpp/examples/examples/pub-sub/Makefile | 10 -- .../examples/examples/pub-sub/topic_listener.cpp | 171 --------------------- .../examples/examples/pub-sub/topic_publisher.cpp | 128 --------------- qpid/cpp/examples/examples/pub-sub/verify | 4 - qpid/cpp/examples/examples/pub-sub/verify.in | 59 ------- .../examples/examples/pub-sub/verify_cpp_python | 6 - .../examples/examples/pub-sub/verify_cpp_python.in | 55 ------- .../examples/examples/pub-sub/verify_python_cpp | 6 - .../examples/examples/pub-sub/verify_python_cpp.in | 59 ------- .../examples/examples/request-response/Makefile | 10 -- .../examples/examples/request-response/client.cpp | 148 ------------------ .../examples/examples/request-response/server.cpp | 145 ----------------- qpid/cpp/examples/examples/request-response/verify | 5 - .../examples/examples/request-response/verify.in | 19 --- .../examples/request-response/verify_cpp_python | 6 - .../examples/request-response/verify_cpp_python.in | 15 -- .../examples/request-response/verify_python_cpp | 5 - .../examples/request-response/verify_python_cpp.in | 18 --- qpid/cpp/examples/examples/xml-exchange/Makefile | 7 - qpid/cpp/examples/examples/xml-exchange/README | 48 ------ .../examples/xml-exchange/declare_queues.cpp | 76 --------- .../examples/examples/xml-exchange/listener.cpp | 89 ----------- .../examples/xml-exchange/xml_producer.cpp | 91 ----------- qpid/cpp/examples/fanout/Makefile.am | 29 ++++ qpid/cpp/examples/fanout/fanout_producer.cpp | 107 +++++++++++++ qpid/cpp/examples/fanout/listener.cpp | 107 +++++++++++++ qpid/cpp/examples/fanout/verify | 6 + qpid/cpp/examples/fanout/verify.in | 43 ++++++ qpid/cpp/examples/fanout/verify_cpp_python | 7 + qpid/cpp/examples/fanout/verify_cpp_python.in | 27 ++++ qpid/cpp/examples/fanout/verify_python_cpp | 7 + qpid/cpp/examples/fanout/verify_python_cpp.in | 29 ++++ qpid/cpp/examples/makedist.mk | 20 +++ qpid/cpp/examples/pub-sub/Makefile.am | 30 ++++ qpid/cpp/examples/pub-sub/topic_listener.cpp | 171 +++++++++++++++++++++ qpid/cpp/examples/pub-sub/topic_publisher.cpp | 128 +++++++++++++++ qpid/cpp/examples/pub-sub/verify | 4 + qpid/cpp/examples/pub-sub/verify.in | 59 +++++++ qpid/cpp/examples/pub-sub/verify_cpp_python | 6 + qpid/cpp/examples/pub-sub/verify_cpp_python.in | 55 +++++++ qpid/cpp/examples/pub-sub/verify_python_cpp | 6 + qpid/cpp/examples/pub-sub/verify_python_cpp.in | 59 +++++++ qpid/cpp/examples/request-response/Makefile.am | 30 ++++ qpid/cpp/examples/request-response/client.cpp | 148 ++++++++++++++++++ qpid/cpp/examples/request-response/server.cpp | 145 +++++++++++++++++ qpid/cpp/examples/request-response/verify | 5 + qpid/cpp/examples/request-response/verify.in | 19 +++ .../examples/request-response/verify_cpp_python | 6 + .../examples/request-response/verify_cpp_python.in | 15 ++ .../examples/request-response/verify_python_cpp | 5 + .../examples/request-response/verify_python_cpp.in | 18 +++ qpid/cpp/examples/verify | 3 +- qpid/cpp/examples/verify_all | 7 +- qpid/cpp/examples/xml-exchange/Makefile.am | 29 ++++ qpid/cpp/examples/xml-exchange/README | 48 ++++++ qpid/cpp/examples/xml-exchange/declare_queues.cpp | 76 +++++++++ qpid/cpp/examples/xml-exchange/listener.cpp | 89 +++++++++++ qpid/cpp/examples/xml-exchange/xml_producer.cpp | 91 +++++++++++ 92 files changed, 2049 insertions(+), 2078 deletions(-) create mode 100644 qpid/cpp/examples/Makefile create mode 100644 qpid/cpp/examples/README.verify create mode 100644 qpid/cpp/examples/direct/Makefile.am create mode 100644 qpid/cpp/examples/direct/declare_queues.cpp create mode 100644 qpid/cpp/examples/direct/direct_producer.cpp create mode 100644 qpid/cpp/examples/direct/listener.cpp create mode 100644 qpid/cpp/examples/direct/verify create mode 100644 qpid/cpp/examples/direct/verify.in create mode 100644 qpid/cpp/examples/direct/verify_cpp_python create mode 100644 qpid/cpp/examples/direct/verify_cpp_python.in create mode 100644 qpid/cpp/examples/direct/verify_python_cpp create mode 100644 qpid/cpp/examples/direct/verify_python_cpp.in delete mode 100644 qpid/cpp/examples/examples/Makefile delete mode 100644 qpid/cpp/examples/examples/README delete mode 100644 qpid/cpp/examples/examples/direct/Makefile delete mode 100644 qpid/cpp/examples/examples/direct/declare_queues.cpp delete mode 100644 qpid/cpp/examples/examples/direct/direct_producer.cpp delete mode 100644 qpid/cpp/examples/examples/direct/listener.cpp delete mode 100644 qpid/cpp/examples/examples/direct/verify delete mode 100644 qpid/cpp/examples/examples/direct/verify.in delete mode 100644 qpid/cpp/examples/examples/direct/verify_cpp_python delete mode 100644 qpid/cpp/examples/examples/direct/verify_cpp_python.in delete mode 100644 qpid/cpp/examples/examples/direct/verify_python_cpp delete mode 100644 qpid/cpp/examples/examples/direct/verify_python_cpp.in delete mode 100644 qpid/cpp/examples/examples/fanout/Makefile delete mode 100644 qpid/cpp/examples/examples/fanout/fanout_producer.cpp delete mode 100644 qpid/cpp/examples/examples/fanout/listener.cpp delete mode 100644 qpid/cpp/examples/examples/fanout/verify delete mode 100644 qpid/cpp/examples/examples/fanout/verify.in delete mode 100644 qpid/cpp/examples/examples/fanout/verify_cpp_python delete mode 100644 qpid/cpp/examples/examples/fanout/verify_cpp_python.in delete mode 100644 qpid/cpp/examples/examples/fanout/verify_python_cpp delete mode 100644 qpid/cpp/examples/examples/fanout/verify_python_cpp.in delete mode 100644 qpid/cpp/examples/examples/pub-sub/Makefile delete mode 100644 qpid/cpp/examples/examples/pub-sub/topic_listener.cpp delete mode 100644 qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp delete mode 100644 qpid/cpp/examples/examples/pub-sub/verify delete mode 100644 qpid/cpp/examples/examples/pub-sub/verify.in delete mode 100644 qpid/cpp/examples/examples/pub-sub/verify_cpp_python delete mode 100644 qpid/cpp/examples/examples/pub-sub/verify_cpp_python.in delete mode 100644 qpid/cpp/examples/examples/pub-sub/verify_python_cpp delete mode 100644 qpid/cpp/examples/examples/pub-sub/verify_python_cpp.in delete mode 100644 qpid/cpp/examples/examples/request-response/Makefile delete mode 100644 qpid/cpp/examples/examples/request-response/client.cpp delete mode 100644 qpid/cpp/examples/examples/request-response/server.cpp delete mode 100644 qpid/cpp/examples/examples/request-response/verify delete mode 100644 qpid/cpp/examples/examples/request-response/verify.in delete mode 100644 qpid/cpp/examples/examples/request-response/verify_cpp_python delete mode 100644 qpid/cpp/examples/examples/request-response/verify_cpp_python.in delete mode 100644 qpid/cpp/examples/examples/request-response/verify_python_cpp delete mode 100644 qpid/cpp/examples/examples/request-response/verify_python_cpp.in delete mode 100644 qpid/cpp/examples/examples/xml-exchange/Makefile delete mode 100644 qpid/cpp/examples/examples/xml-exchange/README delete mode 100644 qpid/cpp/examples/examples/xml-exchange/declare_queues.cpp delete mode 100644 qpid/cpp/examples/examples/xml-exchange/listener.cpp delete mode 100644 qpid/cpp/examples/examples/xml-exchange/xml_producer.cpp create mode 100644 qpid/cpp/examples/fanout/Makefile.am create mode 100644 qpid/cpp/examples/fanout/fanout_producer.cpp create mode 100644 qpid/cpp/examples/fanout/listener.cpp create mode 100644 qpid/cpp/examples/fanout/verify create mode 100644 qpid/cpp/examples/fanout/verify.in create mode 100644 qpid/cpp/examples/fanout/verify_cpp_python create mode 100644 qpid/cpp/examples/fanout/verify_cpp_python.in create mode 100644 qpid/cpp/examples/fanout/verify_python_cpp create mode 100644 qpid/cpp/examples/fanout/verify_python_cpp.in create mode 100644 qpid/cpp/examples/makedist.mk create mode 100644 qpid/cpp/examples/pub-sub/Makefile.am create mode 100644 qpid/cpp/examples/pub-sub/topic_listener.cpp create mode 100644 qpid/cpp/examples/pub-sub/topic_publisher.cpp create mode 100644 qpid/cpp/examples/pub-sub/verify create mode 100644 qpid/cpp/examples/pub-sub/verify.in create mode 100644 qpid/cpp/examples/pub-sub/verify_cpp_python create mode 100644 qpid/cpp/examples/pub-sub/verify_cpp_python.in create mode 100644 qpid/cpp/examples/pub-sub/verify_python_cpp create mode 100644 qpid/cpp/examples/pub-sub/verify_python_cpp.in create mode 100644 qpid/cpp/examples/request-response/Makefile.am create mode 100644 qpid/cpp/examples/request-response/client.cpp create mode 100644 qpid/cpp/examples/request-response/server.cpp create mode 100644 qpid/cpp/examples/request-response/verify create mode 100644 qpid/cpp/examples/request-response/verify.in create mode 100644 qpid/cpp/examples/request-response/verify_cpp_python create mode 100644 qpid/cpp/examples/request-response/verify_cpp_python.in create mode 100644 qpid/cpp/examples/request-response/verify_python_cpp create mode 100644 qpid/cpp/examples/request-response/verify_python_cpp.in create mode 100644 qpid/cpp/examples/xml-exchange/Makefile.am create mode 100644 qpid/cpp/examples/xml-exchange/README create mode 100644 qpid/cpp/examples/xml-exchange/declare_queues.cpp create mode 100644 qpid/cpp/examples/xml-exchange/listener.cpp create mode 100644 qpid/cpp/examples/xml-exchange/xml_producer.cpp (limited to 'qpid/cpp/examples') diff --git a/qpid/cpp/examples/Makefile b/qpid/cpp/examples/Makefile new file mode 100644 index 0000000000..738675c58f --- /dev/null +++ b/qpid/cpp/examples/Makefile @@ -0,0 +1,6 @@ +SUBDIRS=direct fanout pub-sub request-response xml-exchange +all: + for d in $(SUBDIRS); do ( cd $$d; $(MAKE) $@; ) ; done +clean: + for d in $(SUBDIRS); do ( cd $$d; $(MAKE) $@; ) ; done + diff --git a/qpid/cpp/examples/Makefile.am b/qpid/cpp/examples/Makefile.am index b046540b92..be37213d67 100644 --- a/qpid/cpp/examples/Makefile.am +++ b/qpid/cpp/examples/Makefile.am @@ -1,73 +1,23 @@ +SUBDIRS = direct fanout pub-sub request-response +if HAVE_XML + SUBDIRS += xml-exchange +endif -# List all example files here -nobase_pkgdata_DATA= \ - examples/README \ - examples/Makefile \ - examples/request-response/client.cpp \ - examples/request-response/server.cpp \ - examples/request-response/Makefile \ - examples/fanout/Makefile \ - examples/fanout/listener.cpp \ - examples/fanout/fanout_producer.cpp \ - examples/pub-sub/Makefile \ - examples/pub-sub/topic_publisher.cpp \ - examples/pub-sub/topic_listener.cpp \ - examples/direct/Makefile \ - examples/direct/direct_producer.cpp \ - examples/direct/listener.cpp \ - examples/direct/declare_queues.cpp \ - examples/xml-exchange/Makefile \ - examples/xml-exchange/declare_queues.cpp \ - examples/xml-exchange/xml_producer.cpp \ - examples/xml-exchange/listener.cpp - -VERIFY_FILES= verify verify_all \ - examples/request-response/verify \ - examples/request-response/verify.in \ - examples/request-response/verify_cpp_python \ - examples/request-response/verify_cpp_python.in \ - examples/request-response/verify_python_cpp \ - examples/request-response/verify_python_cpp.in \ - examples/fanout/verify \ - examples/fanout/verify.in \ - examples/fanout/verify_cpp_python \ - examples/fanout/verify_cpp_python.in \ - examples/fanout/verify_python_cpp \ - examples/fanout/verify_python_cpp.in \ - examples/pub-sub/verify \ - examples/pub-sub/verify.in \ - examples/pub-sub/verify_cpp_python \ - examples/pub-sub/verify_cpp_python.in \ - examples/pub-sub/verify_python_cpp \ - examples/pub-sub/verify_python_cpp.in \ - examples/direct/verify \ - examples/direct/verify.in \ - examples/direct/verify_cpp_python \ - examples/direct/verify_cpp_python.in \ - examples/direct/verify_python_cpp \ - examples/direct/verify_python_cpp.in - -EXTRA_DIST=$(nobase_pkgdata_DATA) $(VERIFY_FILES) - -# Note: we don't use normal automake SUBDIRS because the example -# makefiles don't understand all the recursive automake targets. - -clean-local: - cd examples; $(MAKE) clean - rm -f examples/*/*.out examples/*/*.wait - -abs_top_builddir=@abs_top_builddir@ -abs_top_srcdir=@abs_top_srcdir@ +MAKEDIST=.libs/Makefile +SUBMAKE=' for d in $(SUBDIRS) ; do $$(MAKE) -C $$$$d $$@ ; done' +$(MAKEDIST): Makefile + @$(MKDIR_P) .libs + @$(ECHO) all: > $(MAKEDIST) + @$(ECHO) $(SUBMAKE) >> $(MAKEDIST) + @$(ECHO) clean: >> $(MAKEDIST) + @$(ECHO) $(SUBMAKE) >> $(MAKEDIST) -# Build the examples - copy sources to the build tree in VPATH build. -all-local: - test -d examples || cp -R $(srcdir)/examples . - cd examples && $(MAKE) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS) -I$(abs_top_srcdir)/src -I$(abs_top_srcdir)/src/gen -I$(abs_top_builddir)/src -I$(abs_top_builddir)/src/gen -L$(abs_top_builddir)/src/.libs -Wl,-rpath,$(abs_top_builddir)/src/.libs" all +examplesdir=$(pkgdatadir)/examples +examples_DATA = README $(MAKEDIST) -if !HAVE_XML -exclude_examples_regexp="xml" # Exclude XML examples. -endif +EXTRA_DIST = $(examples_DATA) README.verify verify verify_all # Verify the examples in the buid tree. -check-local: all-local verify - $(srcdir)/verify_all $(abs_top_srcdir)/.. $(top_builddir)/src/qpidd $(exclude_examples_regexp) +check-local: + $(srcdir)/verify_all $(abs_top_srcdir)/.. $(abs_top_builddir)/src/qpidd $(exclude_examples_regexp) + diff --git a/qpid/cpp/examples/README.verify b/qpid/cpp/examples/README.verify new file mode 100644 index 0000000000..d15adce58d --- /dev/null +++ b/qpid/cpp/examples/README.verify @@ -0,0 +1,26 @@ += Qpid C++ Examples = + +For more information read examples/README. + +== The Verify All Script == + +The verify_all script will run C++ examples against itself and against the +Python examples. The success of the script is determined by comparing its output +against what is expected. + +=== Arguments === + +The verify_all script expects the path to Qpid trunk as an argument, in order to +setup the environment for Python examples. + +== The Verify Script == + +The verify script is capable of running one or many scripts designed to verify +the success of Qpid examples. The verify script is utilized by the verify_all +scripts. + +=== Verifying an individual example === + +This will require you using the verify script, and providing the necessary sub +script(s) it will utilize in the process. Please note that it is your +responsibility to setup the necessary environment for the verification process diff --git a/qpid/cpp/examples/direct/Makefile.am b/qpid/cpp/examples/direct/Makefile.am new file mode 100644 index 0000000000..7a0cf65968 --- /dev/null +++ b/qpid/cpp/examples/direct/Makefile.am @@ -0,0 +1,29 @@ +examplesdir=$(pkgdatadir)/examples/direct + +include $(top_srcdir)/examples/makedist.mk + +noinst_PROGRAMS=direct_producer listener declare_queues +direct_producer_SOURCES=direct_producer.cpp +direct_producer_LDADD=$(CLIENT_LIB) + +listener_SOURCES=listener.cpp +listener_LDADD=$(CLIENT_LIB) + +declare_queues_SOURCES=declare_queues.cpp +declare_queues_LDADD=$(CLIENT_LIB) + +examples_DATA= \ + direct_producer.cpp \ + listener.cpp \ + declare_queues.cpp \ + $(MAKEDIST) + +EXTRA_DIST= \ + $(examples_DATA) \ + verify \ + verify.in \ + verify_cpp_python \ + verify_cpp_python.in \ + verify_python_cpp \ + verify_python_cpp.in + diff --git a/qpid/cpp/examples/direct/declare_queues.cpp b/qpid/cpp/examples/direct/declare_queues.cpp new file mode 100644 index 0000000000..0cdb472665 --- /dev/null +++ b/qpid/cpp/examples/direct/declare_queues.cpp @@ -0,0 +1,86 @@ +/* + * + * 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. + * + */ + +/** + * declare_queues.cpp + * + * This program is one of three programs designed to be used + * together. These programs use the "amq.direct" exchange. + * + * direct_config_queues.cpp (this program): + * + * Creates a queue on a broker, binding a routing key to route + * messages to that queue. + * + * direct_producer.cpp: + * + * Publishes to a broker, specifying a routing key. + * + * listener.cpp + * + * Reads from a queue on the broker using a message listener. + * + */ + +#include +#include + +#include +#include +#include + +using namespace qpid::client; +using namespace qpid::framing; + +using std::string; + + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + + try { + connection.open(host, port); + Session session = connection.newSession(); + + + //--------- Main body of program -------------------------------------------- + + // Create a queue named "message_queue", and route all messages whose + // routing key is "routing_key" to this newly created queue. + + session.queueDeclare(arg::queue="message_queue"); + session.exchangeBind(arg::exchange="amq.direct", arg::queue="message_queue", arg::bindingKey="routing_key"); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; + +} + + + diff --git a/qpid/cpp/examples/direct/direct_producer.cpp b/qpid/cpp/examples/direct/direct_producer.cpp new file mode 100644 index 0000000000..40fc644bf3 --- /dev/null +++ b/qpid/cpp/examples/direct/direct_producer.cpp @@ -0,0 +1,109 @@ +/* + * + * 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. + * + */ + + +/** + * direct_producer.cpp: + * + * This program is one of three programs designed to be used + * together. These programs do not specify the exchange type - the + * default exchange type is the direct exchange. + * + * create_queues.cpp: + * + * Creates a queue on a broker, binding a routing key to route + * messages to that queue. + * + * direct_producer.cpp (this program): + * + * Publishes to a broker, specifying a routing key. + * + * listener.cpp + * + * Reads from a queue on the broker using a message listener. + * + */ + + +#include +#include +#include +#include + + +#include +#include +#include + +#include + +using namespace qpid::client; +using namespace qpid::framing; + +using std::stringstream; +using std::string; + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message message; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + // The routing key is a message property. We will use the same + // routing key for each message, so we'll set this property + // just once. (In most simple cases, there is no need to set + // other message properties.) + + message.getDeliveryProperties().setRoutingKey("routing_key"); + + // Now send some messages ... + + for (int i=0; i<10; i++) { + stringstream message_data; + message_data << "Message " << i; + + message.setData(message_data.str()); + // Asynchronous transfer sends messages as quickly as + // possible without waiting for confirmation. + async(session).messageTransfer(arg::content=message, arg::destination="amq.direct"); + } + + // And send a final message to indicate termination. + + message.setData("That's all, folks!"); + session.messageTransfer(arg::content=message, arg::destination="amq.direct"); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/direct/listener.cpp b/qpid/cpp/examples/direct/listener.cpp new file mode 100644 index 0000000000..d199b5c0bb --- /dev/null +++ b/qpid/cpp/examples/direct/listener.cpp @@ -0,0 +1,89 @@ +/* + * + * 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. + * + */ + +/** + * listener.cpp: This program reads messages from a queue on + * the broker using a message listener. + */ + +#include +#include +#include +#include + +#include +#include +#include + +using namespace qpid::client; +using namespace qpid::framing; + + +class Listener : public MessageListener{ + private: + SubscriptionManager& subscriptions; + public: + Listener(SubscriptionManager& subscriptions); + virtual void received(Message& message); +}; + +Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) +{} + +void Listener::received(Message& message) { + std::cout << "Message: " << message.getData() << std::endl; + if (message.getData() == "That's all, folks!") { + std::cout << "Shutting down listener for " << message.getDestination() + << std::endl; + subscriptions.cancel(message.getDestination()); + } +} + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message msg; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + SubscriptionManager subscriptions(session); + // Create a listener and subscribe it to the queue named "message_queue" + Listener listener(subscriptions); + subscriptions.subscribe(listener, "message_queue"); + // Receive messages until the subscription is cancelled + // by Listener::received() + subscriptions.run(); + + //--------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/direct/verify b/qpid/cpp/examples/direct/verify new file mode 100644 index 0000000000..ac0464ef80 --- /dev/null +++ b/qpid/cpp/examples/direct/verify @@ -0,0 +1,3 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +clients ./declare_queues ./direct_producer ./listener +outputs ./declare_queues.out ./direct_producer.out ./listener.out diff --git a/qpid/cpp/examples/direct/verify.in b/qpid/cpp/examples/direct/verify.in new file mode 100644 index 0000000000..d1e95f1151 --- /dev/null +++ b/qpid/cpp/examples/direct/verify.in @@ -0,0 +1,15 @@ +==== declare_queues.out +==== direct_producer.out +==== listener.out +Message: Message 0 +Message: Message 1 +Message: Message 2 +Message: Message 3 +Message: Message 4 +Message: Message 5 +Message: Message 6 +Message: Message 7 +Message: Message 8 +Message: Message 9 +Message: That's all, folks! +Shutting down listener for message_queue diff --git a/qpid/cpp/examples/direct/verify_cpp_python b/qpid/cpp/examples/direct/verify_cpp_python new file mode 100644 index 0000000000..4dc445ba27 --- /dev/null +++ b/qpid/cpp/examples/direct/verify_cpp_python @@ -0,0 +1,4 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +py=$PYTHON_EXAMPLES/direct +clients ./declare_queues ./direct_producer $py/direct_consumer.py +outputs ./declare_queues.out ./direct_producer.out $py/direct_consumer.py.out diff --git a/qpid/cpp/examples/direct/verify_cpp_python.in b/qpid/cpp/examples/direct/verify_cpp_python.in new file mode 100644 index 0000000000..1a329be59a --- /dev/null +++ b/qpid/cpp/examples/direct/verify_cpp_python.in @@ -0,0 +1,14 @@ +==== declare_queues.out +==== direct_producer.out +==== direct_consumer.py.out +Message 0 +Message 1 +Message 2 +Message 3 +Message 4 +Message 5 +Message 6 +Message 7 +Message 8 +Message 9 +That's all, folks! diff --git a/qpid/cpp/examples/direct/verify_python_cpp b/qpid/cpp/examples/direct/verify_python_cpp new file mode 100644 index 0000000000..fe4893e120 --- /dev/null +++ b/qpid/cpp/examples/direct/verify_python_cpp @@ -0,0 +1,5 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +py=$PYTHON_EXAMPLES/direct +clients $py/declare_queues.py $py/direct_producer.py ./listener +outputs $py/declare_queues.py.out $py/direct_producer.py.out ./listener.out + diff --git a/qpid/cpp/examples/direct/verify_python_cpp.in b/qpid/cpp/examples/direct/verify_python_cpp.in new file mode 100644 index 0000000000..6f35255b18 --- /dev/null +++ b/qpid/cpp/examples/direct/verify_python_cpp.in @@ -0,0 +1,15 @@ +==== declare_queues.py.out +==== direct_producer.py.out +==== listener.out +Message: message 0 +Message: message 1 +Message: message 2 +Message: message 3 +Message: message 4 +Message: message 5 +Message: message 6 +Message: message 7 +Message: message 8 +Message: message 9 +Message: That's all, folks! +Shutting down listener for message_queue diff --git a/qpid/cpp/examples/examples/Makefile b/qpid/cpp/examples/examples/Makefile deleted file mode 100644 index 738675c58f..0000000000 --- a/qpid/cpp/examples/examples/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -SUBDIRS=direct fanout pub-sub request-response xml-exchange -all: - for d in $(SUBDIRS); do ( cd $$d; $(MAKE) $@; ) ; done -clean: - for d in $(SUBDIRS); do ( cd $$d; $(MAKE) $@; ) ; done - diff --git a/qpid/cpp/examples/examples/README b/qpid/cpp/examples/examples/README deleted file mode 100644 index 5e5ae92de3..0000000000 --- a/qpid/cpp/examples/examples/README +++ /dev/null @@ -1,127 +0,0 @@ -= Qpid C++ Examples = - -Apache Qpid Examples in C++ are found inside this directory. A short description -on each example is found below. - -Please note that you will have to start the Qpid broker on port 5672, on your -localhost (127.0.0.1) before running these examples. However, it is possible to -alternatively specify the host and port when running each example. - Ex:- ./declare_queues 127.0.0.1 5673 or declare_queues.exe 127.0.0.1 5673 - -The qpid C++ broker (known as qpidd) is found -- if installed, installed under /usr/lib/qpid/ -- in /path-to-qpid-source/cpp/src/ (and in /usr/local/sbin on a Linux system). - -== Direct == - -This is an example on how to create Point-to-Point applications using Qpid. This -example contains three main components. - - 1. declare_queues - This will bind a queue to the amq.direct exchange, so that the messages sent - to the amq.direct exchange, with a given routing key (routing_key) are - delivered to a specific queue (message_queue). - - 2. direct_producer - Publishes messages to the amq.direct exchange using the given routing key - (routing_key) discussed above. - - 3. listener - Uses a message listener to listen messages from a specific queue - (message_queue) as discussed above. - -In order to run this example, - -On Linux: - # ./declare_queues - # ./direct_producer - # ./listener - -On Windows: - $ declare_queues.exe - $ direct_producer.exe - $ listener.exe - -== Fanout == - -This is an example on how to create Fanout exchange applications using Qpid. -This example has two components unlike the previous. This is because Fanout -exchange not needing a routing key to be specified. - - 1. fanout_producer - Publishes a message to the amq.fanout exchange, without using a routing key. - - 2. listener - Uses a message listener to listen messages from the amq.fanout exchange. - -Another difference between the above example and this example is that in the -above example there is no requirement for the listener to be activated before -the messages being published. However, in this example, it is required that a -listener be active before the messages being published, if not they will be -lost. - -In order to run this example, - -On Linux: - # ./listener - # ./fanout_producer - -On Windows: - $ listener.exe - $ fanout_producer.exe - -== Publisher/Subscriber == - -Showing The ability to create topic Publishers and Subscribers using Qpid is -the main objective of this example. It is required that you subscribe first, -before publishing any message due to the construction of this example. There -are two main applications in this. - - 1. topic_publisher - This application is used to publish messages to the amq.topic exchange using - multipart routing keys, usa.weather, europe.weather, usa.news and europe.news. - - 2. topic_listener - This application is used to subscribe to several private queues, such as usa, - europe, weather and news. In here, each private queue created is bound to the - amq.topic exchange using bindings that match the corresponding parts of the - multipart routing keys. - Ex:- #.news will retrieve news irrespective of destination. - -This example also shows the use of the 'control' routing key which is used by -control messages. - -In order to run this example, - -On Linux: - # ./topic_listener - # ./topic_publisher - -On Windows: - $ topic_listener.exe - $ topic_publisher.exe - -== Request/Response == - -This example shows a simple server that will accept string from a client and -convert them to upper case and send them back to the client. This too has two -main application like the previous sample. - - 1. client - This sends lines of poetry to the server. - - 2. server - This is a simple service that will convert incoming strings to upper case and - send the result to amq.direct exchange on which the client listens. It uses the - request's reply_to property as the response's routing key. - -In order to run this example, - -On Linux: - # ./server - # ./client - -On Windows: - $ server.exe - $ client.exe - diff --git a/qpid/cpp/examples/examples/direct/Makefile b/qpid/cpp/examples/examples/direct/Makefile deleted file mode 100644 index 380b5cfcb4..0000000000 --- a/qpid/cpp/examples/examples/direct/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CXX=g++ -CXXFLAGS= -LDFLAGS=-lqpidclient - -PROGRAMS=declare_queues direct_producer listener - -all: $(PROGRAMS) - -clean: - rm -f $(PROGRAMS) diff --git a/qpid/cpp/examples/examples/direct/declare_queues.cpp b/qpid/cpp/examples/examples/direct/declare_queues.cpp deleted file mode 100644 index 0cdb472665..0000000000 --- a/qpid/cpp/examples/examples/direct/declare_queues.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * 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. - * - */ - -/** - * declare_queues.cpp - * - * This program is one of three programs designed to be used - * together. These programs use the "amq.direct" exchange. - * - * direct_config_queues.cpp (this program): - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * direct_producer.cpp: - * - * Publishes to a broker, specifying a routing key. - * - * listener.cpp - * - * Reads from a queue on the broker using a message listener. - * - */ - -#include -#include - -#include -#include -#include - -using namespace qpid::client; -using namespace qpid::framing; - -using std::string; - - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - - try { - connection.open(host, port); - Session session = connection.newSession(); - - - //--------- Main body of program -------------------------------------------- - - // Create a queue named "message_queue", and route all messages whose - // routing key is "routing_key" to this newly created queue. - - session.queueDeclare(arg::queue="message_queue"); - session.exchangeBind(arg::exchange="amq.direct", arg::queue="message_queue", arg::bindingKey="routing_key"); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; - -} - - - diff --git a/qpid/cpp/examples/examples/direct/direct_producer.cpp b/qpid/cpp/examples/examples/direct/direct_producer.cpp deleted file mode 100644 index 40fc644bf3..0000000000 --- a/qpid/cpp/examples/examples/direct/direct_producer.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * - * 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. - * - */ - - -/** - * direct_producer.cpp: - * - * This program is one of three programs designed to be used - * together. These programs do not specify the exchange type - the - * default exchange type is the direct exchange. - * - * create_queues.cpp: - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * direct_producer.cpp (this program): - * - * Publishes to a broker, specifying a routing key. - * - * listener.cpp - * - * Reads from a queue on the broker using a message listener. - * - */ - - -#include -#include -#include -#include - - -#include -#include -#include - -#include - -using namespace qpid::client; -using namespace qpid::framing; - -using std::stringstream; -using std::string; - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message message; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - // The routing key is a message property. We will use the same - // routing key for each message, so we'll set this property - // just once. (In most simple cases, there is no need to set - // other message properties.) - - message.getDeliveryProperties().setRoutingKey("routing_key"); - - // Now send some messages ... - - for (int i=0; i<10; i++) { - stringstream message_data; - message_data << "Message " << i; - - message.setData(message_data.str()); - // Asynchronous transfer sends messages as quickly as - // possible without waiting for confirmation. - async(session).messageTransfer(arg::content=message, arg::destination="amq.direct"); - } - - // And send a final message to indicate termination. - - message.setData("That's all, folks!"); - session.messageTransfer(arg::content=message, arg::destination="amq.direct"); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/direct/listener.cpp b/qpid/cpp/examples/examples/direct/listener.cpp deleted file mode 100644 index d199b5c0bb..0000000000 --- a/qpid/cpp/examples/examples/direct/listener.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * 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. - * - */ - -/** - * listener.cpp: This program reads messages from a queue on - * the broker using a message listener. - */ - -#include -#include -#include -#include - -#include -#include -#include - -using namespace qpid::client; -using namespace qpid::framing; - - -class Listener : public MessageListener{ - private: - SubscriptionManager& subscriptions; - public: - Listener(SubscriptionManager& subscriptions); - virtual void received(Message& message); -}; - -Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) -{} - -void Listener::received(Message& message) { - std::cout << "Message: " << message.getData() << std::endl; - if (message.getData() == "That's all, folks!") { - std::cout << "Shutting down listener for " << message.getDestination() - << std::endl; - subscriptions.cancel(message.getDestination()); - } -} - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message msg; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - SubscriptionManager subscriptions(session); - // Create a listener and subscribe it to the queue named "message_queue" - Listener listener(subscriptions); - subscriptions.subscribe(listener, "message_queue"); - // Receive messages until the subscription is cancelled - // by Listener::received() - subscriptions.run(); - - //--------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/direct/verify b/qpid/cpp/examples/examples/direct/verify deleted file mode 100644 index ac0464ef80..0000000000 --- a/qpid/cpp/examples/examples/direct/verify +++ /dev/null @@ -1,3 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -clients ./declare_queues ./direct_producer ./listener -outputs ./declare_queues.out ./direct_producer.out ./listener.out diff --git a/qpid/cpp/examples/examples/direct/verify.in b/qpid/cpp/examples/examples/direct/verify.in deleted file mode 100644 index d1e95f1151..0000000000 --- a/qpid/cpp/examples/examples/direct/verify.in +++ /dev/null @@ -1,15 +0,0 @@ -==== declare_queues.out -==== direct_producer.out -==== listener.out -Message: Message 0 -Message: Message 1 -Message: Message 2 -Message: Message 3 -Message: Message 4 -Message: Message 5 -Message: Message 6 -Message: Message 7 -Message: Message 8 -Message: Message 9 -Message: That's all, folks! -Shutting down listener for message_queue diff --git a/qpid/cpp/examples/examples/direct/verify_cpp_python b/qpid/cpp/examples/examples/direct/verify_cpp_python deleted file mode 100644 index 4dc445ba27..0000000000 --- a/qpid/cpp/examples/examples/direct/verify_cpp_python +++ /dev/null @@ -1,4 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=$PYTHON_EXAMPLES/direct -clients ./declare_queues ./direct_producer $py/direct_consumer.py -outputs ./declare_queues.out ./direct_producer.out $py/direct_consumer.py.out diff --git a/qpid/cpp/examples/examples/direct/verify_cpp_python.in b/qpid/cpp/examples/examples/direct/verify_cpp_python.in deleted file mode 100644 index 1a329be59a..0000000000 --- a/qpid/cpp/examples/examples/direct/verify_cpp_python.in +++ /dev/null @@ -1,14 +0,0 @@ -==== declare_queues.out -==== direct_producer.out -==== direct_consumer.py.out -Message 0 -Message 1 -Message 2 -Message 3 -Message 4 -Message 5 -Message 6 -Message 7 -Message 8 -Message 9 -That's all, folks! diff --git a/qpid/cpp/examples/examples/direct/verify_python_cpp b/qpid/cpp/examples/examples/direct/verify_python_cpp deleted file mode 100644 index fe4893e120..0000000000 --- a/qpid/cpp/examples/examples/direct/verify_python_cpp +++ /dev/null @@ -1,5 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=$PYTHON_EXAMPLES/direct -clients $py/declare_queues.py $py/direct_producer.py ./listener -outputs $py/declare_queues.py.out $py/direct_producer.py.out ./listener.out - diff --git a/qpid/cpp/examples/examples/direct/verify_python_cpp.in b/qpid/cpp/examples/examples/direct/verify_python_cpp.in deleted file mode 100644 index 6f35255b18..0000000000 --- a/qpid/cpp/examples/examples/direct/verify_python_cpp.in +++ /dev/null @@ -1,15 +0,0 @@ -==== declare_queues.py.out -==== direct_producer.py.out -==== listener.out -Message: message 0 -Message: message 1 -Message: message 2 -Message: message 3 -Message: message 4 -Message: message 5 -Message: message 6 -Message: message 7 -Message: message 8 -Message: message 9 -Message: That's all, folks! -Shutting down listener for message_queue diff --git a/qpid/cpp/examples/examples/fanout/Makefile b/qpid/cpp/examples/examples/fanout/Makefile deleted file mode 100644 index 7963af7ddf..0000000000 --- a/qpid/cpp/examples/examples/fanout/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CXX=g++ -CXXFLAGS= -LDFLAGS=-lqpidclient - -PROGRAMS=fanout_producer listener - -all: $(PROGRAMS) - -clean: - rm -f $(PROGRAMS) diff --git a/qpid/cpp/examples/examples/fanout/fanout_producer.cpp b/qpid/cpp/examples/examples/fanout/fanout_producer.cpp deleted file mode 100644 index a1ca407847..0000000000 --- a/qpid/cpp/examples/examples/fanout/fanout_producer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * - * 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. - * - */ - - -/** - * fanout_producer.cpp: - * - * This program is one of three programs designed to be used - * together. These programs do not specify the exchange type - the - * default exchange type is the direct exchange. - * - * declare_queues.cpp: - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * fanout_producer.cpp (this program): - * - * Publishes to a broker, specifying a routing key. - * - * listener.cpp - * - * Reads from a queue on the broker using a message listener. - * - */ - - -#include -#include -#include -#include - - -#include -#include -#include - -#include - -using namespace qpid::client; -using namespace qpid::framing; - -using std::stringstream; -using std::string; - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message message; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - // Unlike topic exchanges and direct exchanges, a fanout - // exchange need not set a routing key. - - Message message; - - // Now send some messages ... - - for (int i=0; i<10; i++) { - stringstream message_data; - message_data << "Message " << i; - - message.setData(message_data.str()); - // Asynchronous transfer sends messages as quickly as - // possible without waiting for confirmation. - async(session).messageTransfer(arg::content=message, arg::destination="amq.fanout"); - } - - // And send a final message to indicate termination. - - message.setData("That's all, folks!"); - session.messageTransfer(arg::content=message, arg::destination="amq.fanout"); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/fanout/listener.cpp b/qpid/cpp/examples/examples/fanout/listener.cpp deleted file mode 100644 index b29c82d3d9..0000000000 --- a/qpid/cpp/examples/examples/fanout/listener.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * - * 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. - * - */ - -/** - * listener.cpp: This program reads messages fro a queue on - * the broker using a message listener. - */ - -#include -#include -#include -#include - -#include -#include -#include - -using namespace qpid::client; -using namespace qpid::framing; - - -class Listener : public MessageListener{ - private: - SubscriptionManager& subscriptions; - public: - Listener(SubscriptionManager& subscriptions); - virtual void received(Message& message); -}; - -Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) -{} - -void Listener::received(Message& message) { - std::cout << "Message: " << message.getData() << std::endl; - if (message.getData() == "That's all, folks!") { - std::cout << "Shutting down listener for " << message.getDestination() - << std::endl; - subscriptions.cancel(message.getDestination()); - } -} - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message msg; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - // Each client creates its own private queue, using the - // session id to guarantee a unique name. It then routes - // all messages from the fanout exchange to its own queue - // by binding to the queue. - // - // The binding specifies a binding key, but for a fanout - // exchange, the binding key is optional and is not used - // for routing decisions. It can be useful for tracking - // messages and routing in logs. - - std::string myQueue=session.getId().getName(); - session.queueDeclare(arg::queue=myQueue, arg::exclusive=true, - arg::autoDelete=true); - - session.exchangeBind(arg::exchange="amq.fanout", arg::queue=myQueue, arg::bindingKey="my-key"); - - // Create a listener and subscribe it to my queue. - SubscriptionManager subscriptions(session); - Listener listener(subscriptions); - subscriptions.subscribe(listener, myQueue); - - // Receive messages until the subscription is cancelled - // by Listener::received() - std::cout << "Listening" << std::endl; - subscriptions.run(); - - //--------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/fanout/verify b/qpid/cpp/examples/examples/fanout/verify deleted file mode 100644 index ace4a6dfee..0000000000 --- a/qpid/cpp/examples/examples/fanout/verify +++ /dev/null @@ -1,6 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Listening" ./listener -background "Listening" ./listener -background "Listening" ./listener -clients ./fanout_producer -outputs ./fanout_producer.out "./listener.out | remove_uuid" "./listenerX.out | remove_uuid" "./listenerXX.out | remove_uuid" diff --git a/qpid/cpp/examples/examples/fanout/verify.in b/qpid/cpp/examples/examples/fanout/verify.in deleted file mode 100644 index 8f8612ce67..0000000000 --- a/qpid/cpp/examples/examples/fanout/verify.in +++ /dev/null @@ -1,43 +0,0 @@ -==== fanout_producer.out -==== listener.out | remove_uuid -Listening -Message: Message 0 -Message: Message 1 -Message: Message 2 -Message: Message 3 -Message: Message 4 -Message: Message 5 -Message: Message 6 -Message: Message 7 -Message: Message 8 -Message: Message 9 -Message: That's all, folks! -Shutting down listener for -==== listenerX.out | remove_uuid -Listening -Message: Message 0 -Message: Message 1 -Message: Message 2 -Message: Message 3 -Message: Message 4 -Message: Message 5 -Message: Message 6 -Message: Message 7 -Message: Message 8 -Message: Message 9 -Message: That's all, folks! -Shutting down listener for -==== listenerXX.out | remove_uuid -Listening -Message: Message 0 -Message: Message 1 -Message: Message 2 -Message: Message 3 -Message: Message 4 -Message: Message 5 -Message: Message 6 -Message: Message 7 -Message: Message 8 -Message: Message 9 -Message: That's all, folks! -Shutting down listener for diff --git a/qpid/cpp/examples/examples/fanout/verify_cpp_python b/qpid/cpp/examples/examples/fanout/verify_cpp_python deleted file mode 100644 index 6a1ba7ad7d..0000000000 --- a/qpid/cpp/examples/examples/fanout/verify_cpp_python +++ /dev/null @@ -1,7 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=$PYTHON_EXAMPLES/fanout -background "Subscribed" $py/fanout_consumer.py -background "Subscribed" $py/fanout_consumer.py -clients ./fanout_producer -outputs ./fanout_producer.out "$py/fanout_consumer.py.out | remove_uuid" "$py/fanout_consumer.pyX.out | remove_uuid" - diff --git a/qpid/cpp/examples/examples/fanout/verify_cpp_python.in b/qpid/cpp/examples/examples/fanout/verify_cpp_python.in deleted file mode 100644 index 21bafe06de..0000000000 --- a/qpid/cpp/examples/examples/fanout/verify_cpp_python.in +++ /dev/null @@ -1,27 +0,0 @@ -==== fanout_producer.out -==== fanout_consumer.py.out | remove_uuid -Subscribed to queue -Message 0 -Message 1 -Message 2 -Message 3 -Message 4 -Message 5 -Message 6 -Message 7 -Message 8 -Message 9 -That's all, folks! -==== fanout_consumer.pyX.out | remove_uuid -Subscribed to queue -Message 0 -Message 1 -Message 2 -Message 3 -Message 4 -Message 5 -Message 6 -Message 7 -Message 8 -Message 9 -That's all, folks! diff --git a/qpid/cpp/examples/examples/fanout/verify_python_cpp b/qpid/cpp/examples/examples/fanout/verify_python_cpp deleted file mode 100644 index d9b3361523..0000000000 --- a/qpid/cpp/examples/examples/fanout/verify_python_cpp +++ /dev/null @@ -1,7 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=$PYTHON_EXAMPLES/fanout -background "Listening" ./listener -background "Listening" ./listener -clients $py/fanout_producer.py -outputs $py/fanout_producer.py.out "./listener.out | remove_uuid" "./listenerX.out | remove_uuid" - diff --git a/qpid/cpp/examples/examples/fanout/verify_python_cpp.in b/qpid/cpp/examples/examples/fanout/verify_python_cpp.in deleted file mode 100644 index 8f9e959053..0000000000 --- a/qpid/cpp/examples/examples/fanout/verify_python_cpp.in +++ /dev/null @@ -1,29 +0,0 @@ -==== fanout_producer.py.out -==== listener.out | remove_uuid -Listening -Message: message 0 -Message: message 1 -Message: message 2 -Message: message 3 -Message: message 4 -Message: message 5 -Message: message 6 -Message: message 7 -Message: message 8 -Message: message 9 -Message: That's all, folks! -Shutting down listener for -==== listenerX.out | remove_uuid -Listening -Message: message 0 -Message: message 1 -Message: message 2 -Message: message 3 -Message: message 4 -Message: message 5 -Message: message 6 -Message: message 7 -Message: message 8 -Message: message 9 -Message: That's all, folks! -Shutting down listener for diff --git a/qpid/cpp/examples/examples/pub-sub/Makefile b/qpid/cpp/examples/examples/pub-sub/Makefile deleted file mode 100644 index 4b2dd52efd..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CXX=g++ -CXXFLAGS= -LDFLAGS=-lqpidclient - -PROGRAMS=topic_listener topic_publisher - -all: $(PROGRAMS) - -clean: - rm -f $(PROGRAMS) diff --git a/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp b/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp deleted file mode 100644 index 9996abab19..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * - * 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. - * - */ - -/** - * topic_listener.cpp: - * - * This program is one of three programs designed to be used - * together. These programs use the topic exchange. - * - * topic_config_queues.cpp: - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * topic_publisher.cpp: - * - * Publishes to a broker, specifying a routing key. - * - * topic_listener.cpp (this program): - * - * Reads from a queue on the broker using a message listener. - * - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace qpid::client; -using namespace qpid::framing; - - -class Listener : public MessageListener { - private: - Session& session; - SubscriptionManager subscriptions; - public: - Listener(Session& session); - virtual void prepareQueue(std::string queue, std::string routing_key); - virtual void received(Message& message); - virtual void listen(); - ~Listener() { }; -}; - - -/* - * Listener::Listener - * - * Subscribe to the queue, route it to a client destination for the - * listener. (The destination name merely identifies the destination - * in the listener, you can use any name as long as you use the same - * name for the listener). - */ - -Listener::Listener(Session& session) : - session(session), - subscriptions(session) -{ -} - - -void Listener::prepareQueue(std::string queue, std::string routing_key) { - - /* Create a unique queue name for this consumer by concatenating - * the queue name parameter with the Session ID. - */ - - queue += session.getId().getName(); - std::cout << "Declaring queue: " << queue << std::endl; - - /* Declare an exclusive queue on the broker - */ - - session.queueDeclare(arg::queue=queue, arg::exclusive=true, arg::autoDelete=true); - - /* Route messages to the new queue if they match the routing key. - * - * Also route any messages to with the "control" routing key to - * this queue so we know when it's time to stop. A publisher sends - * a message with the content "That's all, Folks!", using the - * "control" routing key, when it is finished. - */ - - session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey=routing_key); - session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey="control"); - - /* - * subscribe to the queue using the subscription manager. - */ - - std::cout << "Subscribing to queue " << queue << std::endl; - subscriptions.subscribe(*this, queue); -} - -void Listener::received(Message& message) { - std::cout << "Message: " << message.getData() << " from " << message.getDestination() << std::endl; - - if (message.getData() == "That's all, folks!") { - std::cout << "Shutting down listener for " << message.getDestination() << std::endl; - subscriptions.cancel(message.getDestination()); - } -} - -void Listener::listen() { - // Receive messages - subscriptions.run(); -} - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - // Create a listener for the session - - Listener listener(session); - - // Subscribe to messages on the queues we are interested in - - listener.prepareQueue("usa", "usa.#"); - listener.prepareQueue("europe", "europe.#"); - listener.prepareQueue("news", "#.news"); - listener.prepareQueue("weather", "#.weather"); - - std::cout << "Listening for messages ..." << std::endl; - - // Give up control and receive messages - listener.listen(); - - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp b/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp deleted file mode 100644 index ab485fec8f..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * - * 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. - * - */ - - -/** - * topic_publisher.cpp: - * - * This program is one of three programs designed to be used - * together. These programs use the topic exchange. - * - * topic_config_queues.cpp: - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. - * - * topic_publisher.cpp (this program): - * - * Publishes to a broker, specifying a routing key. - * - * topic_listener.cpp - * - * Reads from a queue on the broker using a message listener. - * - */ - - -#include -#include -#include -#include - - -#include -#include -#include - -#include - -using namespace qpid::client; -using namespace qpid::framing; - -using std::stringstream; -using std::string; - -void publish_messages(Session& session, string routing_key) -{ - Message message; - - // Set the routing key once, we'll use the same routing key for all - // messages. - - message.getDeliveryProperties().setRoutingKey(routing_key); - for (int i=0; i<5; i++) { - stringstream message_data; - message_data << "Message " << i; - - message.setData(message_data.str()); - // Asynchronous transfer sends messages as quickly as - // possible without waiting for confirmation. - async(session).messageTransfer(arg::content=message, arg::destination="amq.topic"); - } - -} - -/* - * no_more_messages() - * - * Send a message to indicate that no more messages are coming. - * Use the 'control' routing key (see comments in topic_config_queues.cpp). - * - */ - -void no_more_messages(Session& session) -{ - Message message; - - message.getDeliveryProperties().setRoutingKey("control"); - message.setData("That's all, folks!"); - session.messageTransfer(arg::content=message, arg::destination="amq.topic"); -} - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message message; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - publish_messages(session, "usa.news"); - publish_messages(session, "usa.weather"); - publish_messages(session, "europe.news"); - publish_messages(session, "europe.weather"); - - no_more_messages(session); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/pub-sub/verify b/qpid/cpp/examples/examples/pub-sub/verify deleted file mode 100644 index 3589a4c9da..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/verify +++ /dev/null @@ -1,4 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Listening" ./topic_listener -clients ./topic_publisher -outputs ./topic_publisher.out "topic_listener.out | remove_uuid | sort" diff --git a/qpid/cpp/examples/examples/pub-sub/verify.in b/qpid/cpp/examples/examples/pub-sub/verify.in deleted file mode 100644 index 6413c5c788..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/verify.in +++ /dev/null @@ -1,59 +0,0 @@ -==== topic_publisher.out -==== topic_listener.out | remove_uuid | sort -Declaring queue: europe -Declaring queue: news -Declaring queue: usa -Declaring queue: weather -Listening for messages ... -Message: Message 0 from europe -Message: Message 0 from europe -Message: Message 0 from news -Message: Message 0 from news -Message: Message 0 from usa -Message: Message 0 from usa -Message: Message 0 from weather -Message: Message 0 from weather -Message: Message 1 from europe -Message: Message 1 from europe -Message: Message 1 from news -Message: Message 1 from news -Message: Message 1 from usa -Message: Message 1 from usa -Message: Message 1 from weather -Message: Message 1 from weather -Message: Message 2 from europe -Message: Message 2 from europe -Message: Message 2 from news -Message: Message 2 from news -Message: Message 2 from usa -Message: Message 2 from usa -Message: Message 2 from weather -Message: Message 2 from weather -Message: Message 3 from europe -Message: Message 3 from europe -Message: Message 3 from news -Message: Message 3 from news -Message: Message 3 from usa -Message: Message 3 from usa -Message: Message 3 from weather -Message: Message 3 from weather -Message: Message 4 from europe -Message: Message 4 from europe -Message: Message 4 from news -Message: Message 4 from news -Message: Message 4 from usa -Message: Message 4 from usa -Message: Message 4 from weather -Message: Message 4 from weather -Message: That's all, folks! from europe -Message: That's all, folks! from news -Message: That's all, folks! from usa -Message: That's all, folks! from weather -Shutting down listener for europe -Shutting down listener for news -Shutting down listener for usa -Shutting down listener for weather -Subscribing to queue europe -Subscribing to queue news -Subscribing to queue usa -Subscribing to queue weather diff --git a/qpid/cpp/examples/examples/pub-sub/verify_cpp_python b/qpid/cpp/examples/examples/pub-sub/verify_cpp_python deleted file mode 100644 index f6c6850981..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/verify_cpp_python +++ /dev/null @@ -1,6 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=$PYTHON_EXAMPLES/pubsub -background "Queues created" $py/topic_subscriber.py -clients ./topic_publisher -outputs ./topic_publisher.out "$py/topic_subscriber.py.out | remove_uuid | sort" - diff --git a/qpid/cpp/examples/examples/pub-sub/verify_cpp_python.in b/qpid/cpp/examples/examples/pub-sub/verify_cpp_python.in deleted file mode 100644 index 951d9ad9dd..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/verify_cpp_python.in +++ /dev/null @@ -1,55 +0,0 @@ -==== topic_publisher.out -==== topic_subscriber.py.out | remove_uuid | sort -Message 0 -Message 0 -Message 0 -Message 0 -Message 0 -Message 0 -Message 0 -Message 0 -Message 1 -Message 1 -Message 1 -Message 1 -Message 1 -Message 1 -Message 1 -Message 1 -Message 2 -Message 2 -Message 2 -Message 2 -Message 2 -Message 2 -Message 2 -Message 2 -Message 3 -Message 3 -Message 3 -Message 3 -Message 3 -Message 3 -Message 3 -Message 3 -Message 4 -Message 4 -Message 4 -Message 4 -Message 4 -Message 4 -Message 4 -Message 4 -Messages on 'europe' queue: -Messages on 'news' queue: -Messages on 'usa' queue: -Messages on 'weather' queue: -Queues created - please start the topic producer -Subscribing local queue 'local_europe' to europe-' -Subscribing local queue 'local_news' to news-' -Subscribing local queue 'local_usa' to usa-' -Subscribing local queue 'local_weather' to weather-' -That's all, folks! -That's all, folks! -That's all, folks! -That's all, folks! diff --git a/qpid/cpp/examples/examples/pub-sub/verify_python_cpp b/qpid/cpp/examples/examples/pub-sub/verify_python_cpp deleted file mode 100644 index 2ddaad58c2..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/verify_python_cpp +++ /dev/null @@ -1,6 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -py=$PYTHON_EXAMPLES/pubsub -background "Listening" ./topic_listener -clients $py/topic_publisher.py -outputs $py/topic_publisher.py.out "topic_listener.out | remove_uuid | sort" - diff --git a/qpid/cpp/examples/examples/pub-sub/verify_python_cpp.in b/qpid/cpp/examples/examples/pub-sub/verify_python_cpp.in deleted file mode 100644 index 52e8db9d72..0000000000 --- a/qpid/cpp/examples/examples/pub-sub/verify_python_cpp.in +++ /dev/null @@ -1,59 +0,0 @@ -==== topic_publisher.py.out -==== topic_listener.out | remove_uuid | sort -Declaring queue: europe -Declaring queue: news -Declaring queue: usa -Declaring queue: weather -Listening for messages ... -Message: europe.news 0 from europe -Message: europe.news 0 from news -Message: europe.news 1 from europe -Message: europe.news 1 from news -Message: europe.news 2 from europe -Message: europe.news 2 from news -Message: europe.news 3 from europe -Message: europe.news 3 from news -Message: europe.news 4 from europe -Message: europe.news 4 from news -Message: europe.weather 0 from europe -Message: europe.weather 0 from weather -Message: europe.weather 1 from europe -Message: europe.weather 1 from weather -Message: europe.weather 2 from europe -Message: europe.weather 2 from weather -Message: europe.weather 3 from europe -Message: europe.weather 3 from weather -Message: europe.weather 4 from europe -Message: europe.weather 4 from weather -Message: That's all, folks! from europe -Message: That's all, folks! from news -Message: That's all, folks! from usa -Message: That's all, folks! from weather -Message: usa.news 0 from news -Message: usa.news 0 from usa -Message: usa.news 1 from news -Message: usa.news 1 from usa -Message: usa.news 2 from news -Message: usa.news 2 from usa -Message: usa.news 3 from news -Message: usa.news 3 from usa -Message: usa.news 4 from news -Message: usa.news 4 from usa -Message: usa.weather 0 from usa -Message: usa.weather 0 from weather -Message: usa.weather 1 from usa -Message: usa.weather 1 from weather -Message: usa.weather 2 from usa -Message: usa.weather 2 from weather -Message: usa.weather 3 from usa -Message: usa.weather 3 from weather -Message: usa.weather 4 from usa -Message: usa.weather 4 from weather -Shutting down listener for europe -Shutting down listener for news -Shutting down listener for usa -Shutting down listener for weather -Subscribing to queue europe -Subscribing to queue news -Subscribing to queue usa -Subscribing to queue weather diff --git a/qpid/cpp/examples/examples/request-response/Makefile b/qpid/cpp/examples/examples/request-response/Makefile deleted file mode 100644 index e7ef2590d3..0000000000 --- a/qpid/cpp/examples/examples/request-response/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -CXX=g++ -CXXFLAGS= -LDFLAGS=-lqpidclient - -PROGRAMS=client server - -all: $(PROGRAMS) - -clean: - rm -f $(PROGRAMS) diff --git a/qpid/cpp/examples/examples/request-response/client.cpp b/qpid/cpp/examples/examples/request-response/client.cpp deleted file mode 100644 index 0ee0e78c92..0000000000 --- a/qpid/cpp/examples/examples/request-response/client.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * - * 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. - * - */ - - -/** - * client.cpp - * - * This program is one of two programs that illustrate the - * request/response pattern. - * - * client.cpp (this program) - * - * Make requests of a service, print the response. - * - * service.cpp - * - * Accept requests, reverse the letters in each message, and - * return it as a response. - * - */ - - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -using namespace qpid::client; -using namespace qpid::framing; - -class Listener : public MessageListener{ - private: - SubscriptionManager& subscriptions; - int counter; - public: - Listener(SubscriptionManager& subscriptions); - virtual void received(Message& message); -}; - -Listener::Listener(SubscriptionManager& subs) : subscriptions(subs), counter(0) -{} - -void Listener::received(Message& message) { - std::cout << "Response: " << message.getData() << std::endl; - - ++ counter; - if (counter > 3) { - std::cout << "Shutting down listener for " << message.getDestination() << std::endl; - subscriptions.cancel(message.getDestination()); - } -} - - -using std::stringstream; -using std::string; - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message request; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - // Create a response queue so the server can send us responses - // to our requests. Use the client's session ID as the name - // of the response queue. - - stringstream response_queue; - response_queue << "client" << session.getId().getName(); - - // Use the name of the response queue as the routing key - - session.queueDeclare(arg::queue=response_queue.str()); - session.exchangeBind(arg::exchange="amq.direct", arg::queue=response_queue.str(), arg::bindingKey=response_queue.str()); - - // Each client sends the name of their own response queue so - // the service knows where to route messages. - - request.getDeliveryProperties().setRoutingKey("request"); - request.getMessageProperties().setReplyTo(ReplyTo("amq.direct", response_queue.str())); - - // Create a listener for the response queue and listen for response messages. - std::cout << "Activating response queue listener for: " << response_queue.str() << std::endl; - SubscriptionManager subscriptions(session); - Listener listener(subscriptions); - subscriptions.subscribe(listener, response_queue.str()); - - // Now send some requests ... - - string s[] = { - "Twas brillig, and the slithy toves", - "Did gire and gymble in the wabe.", - "All mimsy were the borogroves,", - "And the mome raths outgrabe." - }; - - - for (int i=0; i<4; i++) { - request.setData(s[i]); - // Asynchronous transfer sends messages as quickly as - // possible without waiting for confirmation. - async(session).messageTransfer(arg::content=request, arg::destination="amq.direct"); - std::cout << "Request: " << s[i] << std::endl; - } - - std::cout << "Waiting for all responses to arrive ..." << std::endl; - subscriptions.run(); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/request-response/server.cpp b/qpid/cpp/examples/examples/request-response/server.cpp deleted file mode 100644 index df189cfdd8..0000000000 --- a/qpid/cpp/examples/examples/request-response/server.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * - * 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. - * - */ - - -/** - * server.cpp - * - * This program is one of two programs that illustrate the - * request/response pattern. - * - * client.cpp - * - * Make requests of a service, print the response. - * - * server.cpp (this program) - * - * Accept requests, reverse the letters in each message, and - * return it as a response. - * - */ - - -#include -#include -#include -#include -#include -#include - - -#include -#include -#include -#include - -#include -#include - -using namespace qpid::client; -using namespace qpid::framing; -using std::stringstream; -using std::string; - -class Listener : public MessageListener{ - private: - SubscriptionManager& subscriptions; - AsyncSession asyncSession; - public: - Listener(SubscriptionManager& subscriptions, Session& session); - virtual void received(Message& message); -}; - -Listener::Listener(SubscriptionManager& subs, Session& session) - : subscriptions(subs), asyncSession(session) -{} - -void Listener::received(Message& request) { - Message response; - - // Get routing key for response from the request's replyTo property - string routingKey; - - if (request.getMessageProperties().hasReplyTo()) { - routingKey = request.getMessageProperties().getReplyTo().getRoutingKey(); - } else { - std::cout << "Error: " << "No routing key for request (" << request.getData() << ")" << std::endl; - return; - } - - std::cout << "Request: " << request.getData() << " (" <1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message message; - try { - connection.open(host, port); - 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(); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/request-response/verify b/qpid/cpp/examples/examples/request-response/verify deleted file mode 100644 index 76007ff8d2..0000000000 --- a/qpid/cpp/examples/examples/request-response/verify +++ /dev/null @@ -1,5 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Waiting" ./server -clients ./client -kill %% # Must kill the server. -outputs "./client.out | remove_uuid" "server.out | remove_uuid" diff --git a/qpid/cpp/examples/examples/request-response/verify.in b/qpid/cpp/examples/examples/request-response/verify.in deleted file mode 100644 index 7925dc5671..0000000000 --- a/qpid/cpp/examples/examples/request-response/verify.in +++ /dev/null @@ -1,19 +0,0 @@ -==== client.out | remove_uuid -Activating response queue listener for: client -Request: Twas brillig, and the slithy toves -Request: Did gire and gymble in the wabe. -Request: All mimsy were the borogroves, -Request: And the mome raths outgrabe. -Waiting for all responses to arrive ... -Response: TWAS BRILLIG, AND THE SLITHY TOVES -Response: DID GIRE AND GYMBLE IN THE WABE. -Response: ALL MIMSY WERE THE BOROGROVES, -Response: AND THE MOME RATHS OUTGRABE. -Shutting down listener for client -==== server.out | remove_uuid -Activating request queue listener for: request -Waiting for requests -Request: Twas brillig, and the slithy toves (client) -Request: Did gire and gymble in the wabe. (client) -Request: All mimsy were the borogroves, (client) -Request: And the mome raths outgrabe. (client) diff --git a/qpid/cpp/examples/examples/request-response/verify_cpp_python b/qpid/cpp/examples/examples/request-response/verify_cpp_python deleted file mode 100644 index 867af3a92b..0000000000 --- a/qpid/cpp/examples/examples/request-response/verify_cpp_python +++ /dev/null @@ -1,6 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Request server running" $PYTHON_EXAMPLES/request-response/server.py -clients ./client -sleep 1 -kill %% # Must kill the server. -outputs "./client.out | remove_uuid" "$PYTHON_EXAMPLES/request-response/server.py.out | remove_uuid" diff --git a/qpid/cpp/examples/examples/request-response/verify_cpp_python.in b/qpid/cpp/examples/examples/request-response/verify_cpp_python.in deleted file mode 100644 index a032293d9b..0000000000 --- a/qpid/cpp/examples/examples/request-response/verify_cpp_python.in +++ /dev/null @@ -1,15 +0,0 @@ -==== client.out | remove_uuid -Activating response queue listener for: client -Request: Twas brillig, and the slithy toves -Request: Did gire and gymble in the wabe. -Request: All mimsy were the borogroves, -Request: And the mome raths outgrabe. -Waiting for all responses to arrive ... -Response: TWAS BRILLIG, AND THE SLITHY TOVES -Response: DID GIRE AND GYMBLE IN THE WABE. -Response: ALL MIMSY WERE THE BOROGROVES, -Response: AND THE MOME RATHS OUTGRABE. -Shutting down listener for client -==== server.py.out | remove_uuid -Request server running - run your client now. -(Times out after 100 seconds ...) diff --git a/qpid/cpp/examples/examples/request-response/verify_python_cpp b/qpid/cpp/examples/examples/request-response/verify_python_cpp deleted file mode 100644 index d6f0fa7152..0000000000 --- a/qpid/cpp/examples/examples/request-response/verify_python_cpp +++ /dev/null @@ -1,5 +0,0 @@ -# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify -background "Waiting" ./server -clients $PYTHON_EXAMPLES/request-response/client.py -kill %% # Must kill the server. -outputs "$PYTHON_EXAMPLES/request-response/client.py.out | remove_uuid" "server.out | remove_uuid" diff --git a/qpid/cpp/examples/examples/request-response/verify_python_cpp.in b/qpid/cpp/examples/examples/request-response/verify_python_cpp.in deleted file mode 100644 index 1500134619..0000000000 --- a/qpid/cpp/examples/examples/request-response/verify_python_cpp.in +++ /dev/null @@ -1,18 +0,0 @@ -==== client.py.out | remove_uuid -Request: Twas brillig, and the slithy toves -Request: Did gyre and gimble in the wabe. -Request: All mimsy were the borogroves, -Request: And the mome raths outgrabe. -Messages on queue: reply_to: -Response: TWAS BRILLIG, AND THE SLITHY TOVES -Response: DID GYRE AND GIMBLE IN THE WABE. -Response: ALL MIMSY WERE THE BOROGROVES, -Response: AND THE MOME RATHS OUTGRABE. -No more messages! -==== server.out | remove_uuid -Activating request queue listener for: request -Waiting for requests -Request: Twas brillig, and the slithy toves (reply_to:) -Request: Did gyre and gimble in the wabe. (reply_to:) -Request: All mimsy were the borogroves, (reply_to:) -Request: And the mome raths outgrabe. (reply_to:) diff --git a/qpid/cpp/examples/examples/xml-exchange/Makefile b/qpid/cpp/examples/examples/xml-exchange/Makefile deleted file mode 100644 index e598dd3be3..0000000000 --- a/qpid/cpp/examples/examples/xml-exchange/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -CXX=g++ -CXXFLAGS= -LDFLAGS=-lqpidclient -PROGRAMS=declare_queues xml_producer listener -all: $(PROGRAMS) -clean: - rm -f $(PROGRAMS) diff --git a/qpid/cpp/examples/examples/xml-exchange/README b/qpid/cpp/examples/examples/xml-exchange/README deleted file mode 100644 index 26b9fac97a..0000000000 --- a/qpid/cpp/examples/examples/xml-exchange/README +++ /dev/null @@ -1,48 +0,0 @@ -This example shows how to program a simple application -using the XML Exchange. - -To run the example, execute the programs in the -following order: - -1 ./declare_queues -2 ./listener -3 ./message_producer (in a separate window) - -The XML Exchange must be explicitly declared. Bindings -are established using queries in XQuery. These queries -can reference message content, message application -properties (which are declared as external variables -in the XQuery), or both. - -Once this is done, message producers publish to the -exchange using the exchange name and a routing key, -just as for other exchange types. Message consumers -read from the queues to which messages are routed. -If a message does not have XML content, or is -missing message application properties needed by -the query, the query is not routed. - -Queries can use message application headers to -provide functionality similar to JMS selectors. -If a query does not use the content of a message, -the message content is not parsed, and need not -be XML. - -The XQuery processor, XQilla, does path-based -document projection, so once the portion of -a document needed to evaluate a query has -been read, it stops parsing the document. -Suppose a long document has a header section. -You can indicate in the query that only -one header section needs to be queried, -and there is no need to parse the entire -document to see if there are further header -sections, using a path like this: - -./message/header[1]/date - -If you used a path like this, all children -of the message element would be read to -see if there are further headers: - -./message/header/date diff --git a/qpid/cpp/examples/examples/xml-exchange/declare_queues.cpp b/qpid/cpp/examples/examples/xml-exchange/declare_queues.cpp deleted file mode 100644 index 1307c473c5..0000000000 --- a/qpid/cpp/examples/examples/xml-exchange/declare_queues.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * 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 - -using namespace qpid::client; -using namespace qpid::framing; - -using std::string; - - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - - try { - connection.open(host, port); - Session session = connection.newSession(); - - - //--------- Main body of program -------------------------------------------- - - // Set up queues, bind them with queries. Note that the XML exchange - // is not in the AMQP specification, so it is called "xml", not "amq.xml". - // Note that the XML exchange is not predeclared in Qpid, it must - // be declared by the application. - - session.queueDeclare(arg::queue="message_queue"); - session.exchangeDeclare(arg::exchange="xml", arg::type="xml"); - - // Application message properties are mapped to external variables - // in the XQuery. An XML Exchange can query message properties much - // like JMS, query the XML content of the message, or both. - - FieldTable binding; - binding.setString("xquery", "declare variable $control external;" - "./message/id mod 2 = 1 or $control = 'end'"); - session.exchangeBind(arg::exchange="xml", arg::queue="message_queue", arg::bindingKey="query_name", arg::arguments=binding); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; - -} - - - diff --git a/qpid/cpp/examples/examples/xml-exchange/listener.cpp b/qpid/cpp/examples/examples/xml-exchange/listener.cpp deleted file mode 100644 index 98646bea95..0000000000 --- a/qpid/cpp/examples/examples/xml-exchange/listener.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * 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. - * - */ - -/** - * listener.cpp: This program reads messages fro a queue on - * the broker using a message listener. - */ - -#include -#include -#include -#include - -#include -#include -#include - -using namespace qpid::client; -using namespace qpid::framing; - - -class Listener : public MessageListener{ - private: - SubscriptionManager& subscriptions; - public: - Listener(SubscriptionManager& subscriptions); - virtual void received(Message& message); -}; - -Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) -{} - -void Listener::received(Message& message) { - std::cout << "Message: " << message.getData() << std::endl; - if (message.getHeaders().getString("control") == "end") { - std::cout << "Shutting down listener for " << message.getDestination() - << std::endl; - subscriptions.cancel(message.getDestination()); - } -} - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message msg; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - SubscriptionManager subscriptions(session); - // Create a listener and subscribe it to the queue named "message_queue" - Listener listener(subscriptions); - subscriptions.subscribe(listener, "message_queue"); - // Receive messages until the subscription is cancelled - // by Listener::received() - subscriptions.run(); - - //--------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/examples/xml-exchange/xml_producer.cpp b/qpid/cpp/examples/examples/xml-exchange/xml_producer.cpp deleted file mode 100644 index 19889e4891..0000000000 --- a/qpid/cpp/examples/examples/xml-exchange/xml_producer.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * 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 - -using namespace qpid::client; -using namespace qpid::framing; - -using std::stringstream; -using std::string; - -int main(int argc, char** argv) { - const char* host = argc>1 ? argv[1] : "127.0.0.1"; - int port = argc>2 ? atoi(argv[2]) : 5672; - Connection connection; - Message message; - try { - connection.open(host, port); - Session session = connection.newSession(); - - //--------- Main body of program -------------------------------------------- - - // Publish some XML messages. Use the control property to - // indicate when we are finished. - // - // In the XML exchange, the routing key and the name of - // the query match. - - message.getDeliveryProperties().setRoutingKey("query_name"); - message.getHeaders().setString("control","continue"); - - // Now send some messages ... - - for (int i=0; i<10; i++) { - stringstream message_data; - message_data << "" << i << ""; - - std::cout << "Message data: " << message_data.str() << std::endl; - - message.setData(message_data.str()); - // Asynchronous transfer sends messages as quickly as - // possible without waiting for confirmation. - async(session).messageTransfer(arg::content=message, arg::destination="xml"); - } - - // And send a final message to indicate termination. - - message.getHeaders().setString("control","end"); - message.setData("That's all, folks!"); - session.messageTransfer(arg::content=message, arg::destination="xml"); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; -} - - diff --git a/qpid/cpp/examples/fanout/Makefile.am b/qpid/cpp/examples/fanout/Makefile.am new file mode 100644 index 0000000000..83cda09cf4 --- /dev/null +++ b/qpid/cpp/examples/fanout/Makefile.am @@ -0,0 +1,29 @@ +examplesdir=$(pkgdatadir)/examples/fanout + +include $(top_srcdir)/examples/makedist.mk + +noinst_PROGRAMS=fanout_producer listener +fanout_producer_SOURCES=fanout_producer.cpp +fanout_producer_LDADD=$(CLIENT_LIB) + +listener_SOURCES=listener.cpp +listener_LDADD=$(CLIENT_LIB) + +examples_DATA= \ + fanout_producer.cpp \ + listener.cpp \ + $(MAKEDIST) + +EXTRA_DIST= \ + $(examples_DATA) \ + verify \ + verify.in \ + verify_cpp_python \ + verify_cpp_python.in \ + verify_python_cpp \ + verify_python_cpp.in + + + + + diff --git a/qpid/cpp/examples/fanout/fanout_producer.cpp b/qpid/cpp/examples/fanout/fanout_producer.cpp new file mode 100644 index 0000000000..a1ca407847 --- /dev/null +++ b/qpid/cpp/examples/fanout/fanout_producer.cpp @@ -0,0 +1,107 @@ +/* + * + * 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. + * + */ + + +/** + * fanout_producer.cpp: + * + * This program is one of three programs designed to be used + * together. These programs do not specify the exchange type - the + * default exchange type is the direct exchange. + * + * declare_queues.cpp: + * + * Creates a queue on a broker, binding a routing key to route + * messages to that queue. + * + * fanout_producer.cpp (this program): + * + * Publishes to a broker, specifying a routing key. + * + * listener.cpp + * + * Reads from a queue on the broker using a message listener. + * + */ + + +#include +#include +#include +#include + + +#include +#include +#include + +#include + +using namespace qpid::client; +using namespace qpid::framing; + +using std::stringstream; +using std::string; + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message message; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + // Unlike topic exchanges and direct exchanges, a fanout + // exchange need not set a routing key. + + Message message; + + // Now send some messages ... + + for (int i=0; i<10; i++) { + stringstream message_data; + message_data << "Message " << i; + + message.setData(message_data.str()); + // Asynchronous transfer sends messages as quickly as + // possible without waiting for confirmation. + async(session).messageTransfer(arg::content=message, arg::destination="amq.fanout"); + } + + // And send a final message to indicate termination. + + message.setData("That's all, folks!"); + session.messageTransfer(arg::content=message, arg::destination="amq.fanout"); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/fanout/listener.cpp b/qpid/cpp/examples/fanout/listener.cpp new file mode 100644 index 0000000000..b29c82d3d9 --- /dev/null +++ b/qpid/cpp/examples/fanout/listener.cpp @@ -0,0 +1,107 @@ +/* + * + * 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. + * + */ + +/** + * listener.cpp: This program reads messages fro a queue on + * the broker using a message listener. + */ + +#include +#include +#include +#include + +#include +#include +#include + +using namespace qpid::client; +using namespace qpid::framing; + + +class Listener : public MessageListener{ + private: + SubscriptionManager& subscriptions; + public: + Listener(SubscriptionManager& subscriptions); + virtual void received(Message& message); +}; + +Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) +{} + +void Listener::received(Message& message) { + std::cout << "Message: " << message.getData() << std::endl; + if (message.getData() == "That's all, folks!") { + std::cout << "Shutting down listener for " << message.getDestination() + << std::endl; + subscriptions.cancel(message.getDestination()); + } +} + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message msg; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + // Each client creates its own private queue, using the + // session id to guarantee a unique name. It then routes + // all messages from the fanout exchange to its own queue + // by binding to the queue. + // + // The binding specifies a binding key, but for a fanout + // exchange, the binding key is optional and is not used + // for routing decisions. It can be useful for tracking + // messages and routing in logs. + + std::string myQueue=session.getId().getName(); + session.queueDeclare(arg::queue=myQueue, arg::exclusive=true, + arg::autoDelete=true); + + session.exchangeBind(arg::exchange="amq.fanout", arg::queue=myQueue, arg::bindingKey="my-key"); + + // Create a listener and subscribe it to my queue. + SubscriptionManager subscriptions(session); + Listener listener(subscriptions); + subscriptions.subscribe(listener, myQueue); + + // Receive messages until the subscription is cancelled + // by Listener::received() + std::cout << "Listening" << std::endl; + subscriptions.run(); + + //--------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/fanout/verify b/qpid/cpp/examples/fanout/verify new file mode 100644 index 0000000000..ace4a6dfee --- /dev/null +++ b/qpid/cpp/examples/fanout/verify @@ -0,0 +1,6 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Listening" ./listener +background "Listening" ./listener +background "Listening" ./listener +clients ./fanout_producer +outputs ./fanout_producer.out "./listener.out | remove_uuid" "./listenerX.out | remove_uuid" "./listenerXX.out | remove_uuid" diff --git a/qpid/cpp/examples/fanout/verify.in b/qpid/cpp/examples/fanout/verify.in new file mode 100644 index 0000000000..8f8612ce67 --- /dev/null +++ b/qpid/cpp/examples/fanout/verify.in @@ -0,0 +1,43 @@ +==== fanout_producer.out +==== listener.out | remove_uuid +Listening +Message: Message 0 +Message: Message 1 +Message: Message 2 +Message: Message 3 +Message: Message 4 +Message: Message 5 +Message: Message 6 +Message: Message 7 +Message: Message 8 +Message: Message 9 +Message: That's all, folks! +Shutting down listener for +==== listenerX.out | remove_uuid +Listening +Message: Message 0 +Message: Message 1 +Message: Message 2 +Message: Message 3 +Message: Message 4 +Message: Message 5 +Message: Message 6 +Message: Message 7 +Message: Message 8 +Message: Message 9 +Message: That's all, folks! +Shutting down listener for +==== listenerXX.out | remove_uuid +Listening +Message: Message 0 +Message: Message 1 +Message: Message 2 +Message: Message 3 +Message: Message 4 +Message: Message 5 +Message: Message 6 +Message: Message 7 +Message: Message 8 +Message: Message 9 +Message: That's all, folks! +Shutting down listener for diff --git a/qpid/cpp/examples/fanout/verify_cpp_python b/qpid/cpp/examples/fanout/verify_cpp_python new file mode 100644 index 0000000000..6a1ba7ad7d --- /dev/null +++ b/qpid/cpp/examples/fanout/verify_cpp_python @@ -0,0 +1,7 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +py=$PYTHON_EXAMPLES/fanout +background "Subscribed" $py/fanout_consumer.py +background "Subscribed" $py/fanout_consumer.py +clients ./fanout_producer +outputs ./fanout_producer.out "$py/fanout_consumer.py.out | remove_uuid" "$py/fanout_consumer.pyX.out | remove_uuid" + diff --git a/qpid/cpp/examples/fanout/verify_cpp_python.in b/qpid/cpp/examples/fanout/verify_cpp_python.in new file mode 100644 index 0000000000..21bafe06de --- /dev/null +++ b/qpid/cpp/examples/fanout/verify_cpp_python.in @@ -0,0 +1,27 @@ +==== fanout_producer.out +==== fanout_consumer.py.out | remove_uuid +Subscribed to queue +Message 0 +Message 1 +Message 2 +Message 3 +Message 4 +Message 5 +Message 6 +Message 7 +Message 8 +Message 9 +That's all, folks! +==== fanout_consumer.pyX.out | remove_uuid +Subscribed to queue +Message 0 +Message 1 +Message 2 +Message 3 +Message 4 +Message 5 +Message 6 +Message 7 +Message 8 +Message 9 +That's all, folks! diff --git a/qpid/cpp/examples/fanout/verify_python_cpp b/qpid/cpp/examples/fanout/verify_python_cpp new file mode 100644 index 0000000000..d9b3361523 --- /dev/null +++ b/qpid/cpp/examples/fanout/verify_python_cpp @@ -0,0 +1,7 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +py=$PYTHON_EXAMPLES/fanout +background "Listening" ./listener +background "Listening" ./listener +clients $py/fanout_producer.py +outputs $py/fanout_producer.py.out "./listener.out | remove_uuid" "./listenerX.out | remove_uuid" + diff --git a/qpid/cpp/examples/fanout/verify_python_cpp.in b/qpid/cpp/examples/fanout/verify_python_cpp.in new file mode 100644 index 0000000000..8f9e959053 --- /dev/null +++ b/qpid/cpp/examples/fanout/verify_python_cpp.in @@ -0,0 +1,29 @@ +==== fanout_producer.py.out +==== listener.out | remove_uuid +Listening +Message: message 0 +Message: message 1 +Message: message 2 +Message: message 3 +Message: message 4 +Message: message 5 +Message: message 6 +Message: message 7 +Message: message 8 +Message: message 9 +Message: That's all, folks! +Shutting down listener for +==== listenerX.out | remove_uuid +Listening +Message: message 0 +Message: message 1 +Message: message 2 +Message: message 3 +Message: message 4 +Message: message 5 +Message: message 6 +Message: message 7 +Message: message 8 +Message: message 9 +Message: That's all, folks! +Shutting down listener for diff --git a/qpid/cpp/examples/makedist.mk b/qpid/cpp/examples/makedist.mk new file mode 100644 index 0000000000..c6d59039df --- /dev/null +++ b/qpid/cpp/examples/makedist.mk @@ -0,0 +1,20 @@ +# Settings to build the examples in automake +AM_CXXFLAGS = $(WARNING_CFLAGS) +INCLUDES = -I$(abs_top_srcdir)/src -I$(abs_top_srcdir)/src/gen -I$(abs_top_builddir)/src -I$(abs_top_builddir)/src/gen +CLIENT_LIB=$(abs_top_builddir)/src/libqpidclient.la + +# Generate a simple non-automake Makefile for distribution. +MAKEDIST=.libs/Makefile + +$(MAKEDIST): Makefile + @$(MKDIR_P) .libs + @$(ECHO) CXX=$(CXX) > $(MAKEDIST) + @$(ECHO) CXXFLAGS=$(CXXFLAGS) >> $(MAKEDIST) + @$(ECHO) LDFLAGS=-lqpidclient >> $(MAKEDIST) + @$(ECHO) >> $(MAKEDIST) + @$(ECHO) all: $(noinst_PROGRAMS) >> $(MAKEDIST) + @$(ECHO) >> $(MAKEDIST) + @$(ECHO) clean: >> $(MAKEDIST) + @$(ECHO) " rm -f $(noinst_PROGRAMS)" >> $(MAKEDIST) + + diff --git a/qpid/cpp/examples/pub-sub/Makefile.am b/qpid/cpp/examples/pub-sub/Makefile.am new file mode 100644 index 0000000000..8446a1c40c --- /dev/null +++ b/qpid/cpp/examples/pub-sub/Makefile.am @@ -0,0 +1,30 @@ +examplesdir=$(pkgdatadir)/examples/pub-sub + +include $(top_srcdir)/examples/makedist.mk + +noinst_PROGRAMS=topic_listener topic_publisher + +topic_listener_SOURCES=topic_listener.cpp +topic_listener_LDADD=$(CLIENT_LIB) + +topic_publisher_SOURCES=topic_publisher.cpp +topic_publisher_LDADD=$(CLIENT_LIB) + +examples_DATA= \ + topic_listener.cpp \ + topic_publisher.cpp \ + $(MAKEDIST) + +EXTRA_DIST= \ + $(examples_DATA) \ + verify \ + verify.in \ + verify_cpp_python \ + verify_cpp_python.in \ + verify_python_cpp \ + verify_python_cpp.in + + + + + diff --git a/qpid/cpp/examples/pub-sub/topic_listener.cpp b/qpid/cpp/examples/pub-sub/topic_listener.cpp new file mode 100644 index 0000000000..9996abab19 --- /dev/null +++ b/qpid/cpp/examples/pub-sub/topic_listener.cpp @@ -0,0 +1,171 @@ +/* + * + * 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. + * + */ + +/** + * topic_listener.cpp: + * + * This program is one of three programs designed to be used + * together. These programs use the topic exchange. + * + * topic_config_queues.cpp: + * + * Creates a queue on a broker, binding a routing key to route + * messages to that queue. + * + * topic_publisher.cpp: + * + * Publishes to a broker, specifying a routing key. + * + * topic_listener.cpp (this program): + * + * Reads from a queue on the broker using a message listener. + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace qpid::client; +using namespace qpid::framing; + + +class Listener : public MessageListener { + private: + Session& session; + SubscriptionManager subscriptions; + public: + Listener(Session& session); + virtual void prepareQueue(std::string queue, std::string routing_key); + virtual void received(Message& message); + virtual void listen(); + ~Listener() { }; +}; + + +/* + * Listener::Listener + * + * Subscribe to the queue, route it to a client destination for the + * listener. (The destination name merely identifies the destination + * in the listener, you can use any name as long as you use the same + * name for the listener). + */ + +Listener::Listener(Session& session) : + session(session), + subscriptions(session) +{ +} + + +void Listener::prepareQueue(std::string queue, std::string routing_key) { + + /* Create a unique queue name for this consumer by concatenating + * the queue name parameter with the Session ID. + */ + + queue += session.getId().getName(); + std::cout << "Declaring queue: " << queue << std::endl; + + /* Declare an exclusive queue on the broker + */ + + session.queueDeclare(arg::queue=queue, arg::exclusive=true, arg::autoDelete=true); + + /* Route messages to the new queue if they match the routing key. + * + * Also route any messages to with the "control" routing key to + * this queue so we know when it's time to stop. A publisher sends + * a message with the content "That's all, Folks!", using the + * "control" routing key, when it is finished. + */ + + session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey=routing_key); + session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey="control"); + + /* + * subscribe to the queue using the subscription manager. + */ + + std::cout << "Subscribing to queue " << queue << std::endl; + subscriptions.subscribe(*this, queue); +} + +void Listener::received(Message& message) { + std::cout << "Message: " << message.getData() << " from " << message.getDestination() << std::endl; + + if (message.getData() == "That's all, folks!") { + std::cout << "Shutting down listener for " << message.getDestination() << std::endl; + subscriptions.cancel(message.getDestination()); + } +} + +void Listener::listen() { + // Receive messages + subscriptions.run(); +} + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + // Create a listener for the session + + Listener listener(session); + + // Subscribe to messages on the queues we are interested in + + listener.prepareQueue("usa", "usa.#"); + listener.prepareQueue("europe", "europe.#"); + listener.prepareQueue("news", "#.news"); + listener.prepareQueue("weather", "#.weather"); + + std::cout << "Listening for messages ..." << std::endl; + + // Give up control and receive messages + listener.listen(); + + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/pub-sub/topic_publisher.cpp b/qpid/cpp/examples/pub-sub/topic_publisher.cpp new file mode 100644 index 0000000000..ab485fec8f --- /dev/null +++ b/qpid/cpp/examples/pub-sub/topic_publisher.cpp @@ -0,0 +1,128 @@ +/* + * + * 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. + * + */ + + +/** + * topic_publisher.cpp: + * + * This program is one of three programs designed to be used + * together. These programs use the topic exchange. + * + * topic_config_queues.cpp: + * + * Creates a queue on a broker, binding a routing key to route + * messages to that queue. + * + * topic_publisher.cpp (this program): + * + * Publishes to a broker, specifying a routing key. + * + * topic_listener.cpp + * + * Reads from a queue on the broker using a message listener. + * + */ + + +#include +#include +#include +#include + + +#include +#include +#include + +#include + +using namespace qpid::client; +using namespace qpid::framing; + +using std::stringstream; +using std::string; + +void publish_messages(Session& session, string routing_key) +{ + Message message; + + // Set the routing key once, we'll use the same routing key for all + // messages. + + message.getDeliveryProperties().setRoutingKey(routing_key); + for (int i=0; i<5; i++) { + stringstream message_data; + message_data << "Message " << i; + + message.setData(message_data.str()); + // Asynchronous transfer sends messages as quickly as + // possible without waiting for confirmation. + async(session).messageTransfer(arg::content=message, arg::destination="amq.topic"); + } + +} + +/* + * no_more_messages() + * + * Send a message to indicate that no more messages are coming. + * Use the 'control' routing key (see comments in topic_config_queues.cpp). + * + */ + +void no_more_messages(Session& session) +{ + Message message; + + message.getDeliveryProperties().setRoutingKey("control"); + message.setData("That's all, folks!"); + session.messageTransfer(arg::content=message, arg::destination="amq.topic"); +} + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message message; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + publish_messages(session, "usa.news"); + publish_messages(session, "usa.weather"); + publish_messages(session, "europe.news"); + publish_messages(session, "europe.weather"); + + no_more_messages(session); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/pub-sub/verify b/qpid/cpp/examples/pub-sub/verify new file mode 100644 index 0000000000..3589a4c9da --- /dev/null +++ b/qpid/cpp/examples/pub-sub/verify @@ -0,0 +1,4 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Listening" ./topic_listener +clients ./topic_publisher +outputs ./topic_publisher.out "topic_listener.out | remove_uuid | sort" diff --git a/qpid/cpp/examples/pub-sub/verify.in b/qpid/cpp/examples/pub-sub/verify.in new file mode 100644 index 0000000000..6413c5c788 --- /dev/null +++ b/qpid/cpp/examples/pub-sub/verify.in @@ -0,0 +1,59 @@ +==== topic_publisher.out +==== topic_listener.out | remove_uuid | sort +Declaring queue: europe +Declaring queue: news +Declaring queue: usa +Declaring queue: weather +Listening for messages ... +Message: Message 0 from europe +Message: Message 0 from europe +Message: Message 0 from news +Message: Message 0 from news +Message: Message 0 from usa +Message: Message 0 from usa +Message: Message 0 from weather +Message: Message 0 from weather +Message: Message 1 from europe +Message: Message 1 from europe +Message: Message 1 from news +Message: Message 1 from news +Message: Message 1 from usa +Message: Message 1 from usa +Message: Message 1 from weather +Message: Message 1 from weather +Message: Message 2 from europe +Message: Message 2 from europe +Message: Message 2 from news +Message: Message 2 from news +Message: Message 2 from usa +Message: Message 2 from usa +Message: Message 2 from weather +Message: Message 2 from weather +Message: Message 3 from europe +Message: Message 3 from europe +Message: Message 3 from news +Message: Message 3 from news +Message: Message 3 from usa +Message: Message 3 from usa +Message: Message 3 from weather +Message: Message 3 from weather +Message: Message 4 from europe +Message: Message 4 from europe +Message: Message 4 from news +Message: Message 4 from news +Message: Message 4 from usa +Message: Message 4 from usa +Message: Message 4 from weather +Message: Message 4 from weather +Message: That's all, folks! from europe +Message: That's all, folks! from news +Message: That's all, folks! from usa +Message: That's all, folks! from weather +Shutting down listener for europe +Shutting down listener for news +Shutting down listener for usa +Shutting down listener for weather +Subscribing to queue europe +Subscribing to queue news +Subscribing to queue usa +Subscribing to queue weather diff --git a/qpid/cpp/examples/pub-sub/verify_cpp_python b/qpid/cpp/examples/pub-sub/verify_cpp_python new file mode 100644 index 0000000000..f6c6850981 --- /dev/null +++ b/qpid/cpp/examples/pub-sub/verify_cpp_python @@ -0,0 +1,6 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +py=$PYTHON_EXAMPLES/pubsub +background "Queues created" $py/topic_subscriber.py +clients ./topic_publisher +outputs ./topic_publisher.out "$py/topic_subscriber.py.out | remove_uuid | sort" + diff --git a/qpid/cpp/examples/pub-sub/verify_cpp_python.in b/qpid/cpp/examples/pub-sub/verify_cpp_python.in new file mode 100644 index 0000000000..951d9ad9dd --- /dev/null +++ b/qpid/cpp/examples/pub-sub/verify_cpp_python.in @@ -0,0 +1,55 @@ +==== topic_publisher.out +==== topic_subscriber.py.out | remove_uuid | sort +Message 0 +Message 0 +Message 0 +Message 0 +Message 0 +Message 0 +Message 0 +Message 0 +Message 1 +Message 1 +Message 1 +Message 1 +Message 1 +Message 1 +Message 1 +Message 1 +Message 2 +Message 2 +Message 2 +Message 2 +Message 2 +Message 2 +Message 2 +Message 2 +Message 3 +Message 3 +Message 3 +Message 3 +Message 3 +Message 3 +Message 3 +Message 3 +Message 4 +Message 4 +Message 4 +Message 4 +Message 4 +Message 4 +Message 4 +Message 4 +Messages on 'europe' queue: +Messages on 'news' queue: +Messages on 'usa' queue: +Messages on 'weather' queue: +Queues created - please start the topic producer +Subscribing local queue 'local_europe' to europe-' +Subscribing local queue 'local_news' to news-' +Subscribing local queue 'local_usa' to usa-' +Subscribing local queue 'local_weather' to weather-' +That's all, folks! +That's all, folks! +That's all, folks! +That's all, folks! diff --git a/qpid/cpp/examples/pub-sub/verify_python_cpp b/qpid/cpp/examples/pub-sub/verify_python_cpp new file mode 100644 index 0000000000..2ddaad58c2 --- /dev/null +++ b/qpid/cpp/examples/pub-sub/verify_python_cpp @@ -0,0 +1,6 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +py=$PYTHON_EXAMPLES/pubsub +background "Listening" ./topic_listener +clients $py/topic_publisher.py +outputs $py/topic_publisher.py.out "topic_listener.out | remove_uuid | sort" + diff --git a/qpid/cpp/examples/pub-sub/verify_python_cpp.in b/qpid/cpp/examples/pub-sub/verify_python_cpp.in new file mode 100644 index 0000000000..52e8db9d72 --- /dev/null +++ b/qpid/cpp/examples/pub-sub/verify_python_cpp.in @@ -0,0 +1,59 @@ +==== topic_publisher.py.out +==== topic_listener.out | remove_uuid | sort +Declaring queue: europe +Declaring queue: news +Declaring queue: usa +Declaring queue: weather +Listening for messages ... +Message: europe.news 0 from europe +Message: europe.news 0 from news +Message: europe.news 1 from europe +Message: europe.news 1 from news +Message: europe.news 2 from europe +Message: europe.news 2 from news +Message: europe.news 3 from europe +Message: europe.news 3 from news +Message: europe.news 4 from europe +Message: europe.news 4 from news +Message: europe.weather 0 from europe +Message: europe.weather 0 from weather +Message: europe.weather 1 from europe +Message: europe.weather 1 from weather +Message: europe.weather 2 from europe +Message: europe.weather 2 from weather +Message: europe.weather 3 from europe +Message: europe.weather 3 from weather +Message: europe.weather 4 from europe +Message: europe.weather 4 from weather +Message: That's all, folks! from europe +Message: That's all, folks! from news +Message: That's all, folks! from usa +Message: That's all, folks! from weather +Message: usa.news 0 from news +Message: usa.news 0 from usa +Message: usa.news 1 from news +Message: usa.news 1 from usa +Message: usa.news 2 from news +Message: usa.news 2 from usa +Message: usa.news 3 from news +Message: usa.news 3 from usa +Message: usa.news 4 from news +Message: usa.news 4 from usa +Message: usa.weather 0 from usa +Message: usa.weather 0 from weather +Message: usa.weather 1 from usa +Message: usa.weather 1 from weather +Message: usa.weather 2 from usa +Message: usa.weather 2 from weather +Message: usa.weather 3 from usa +Message: usa.weather 3 from weather +Message: usa.weather 4 from usa +Message: usa.weather 4 from weather +Shutting down listener for europe +Shutting down listener for news +Shutting down listener for usa +Shutting down listener for weather +Subscribing to queue europe +Subscribing to queue news +Subscribing to queue usa +Subscribing to queue weather diff --git a/qpid/cpp/examples/request-response/Makefile.am b/qpid/cpp/examples/request-response/Makefile.am new file mode 100644 index 0000000000..d2cddf3cfb --- /dev/null +++ b/qpid/cpp/examples/request-response/Makefile.am @@ -0,0 +1,30 @@ +examplesdir=$(pkgdatadir)/examples/request-response + +include $(top_srcdir)/examples/makedist.mk + +noinst_PROGRAMS=client server + +client_SOURCES=client.cpp +client_LDADD=$(CLIENT_LIB) + +server_SOURCES=server.cpp +server_LDADD=$(CLIENT_LIB) + +examples_DATA= \ + server.cpp \ + client.cpp \ + $(MAKEDIST) + +EXTRA_DIST= \ + $(examples_DATA) \ + verify \ + verify.in \ + verify_cpp_python \ + verify_cpp_python.in \ + verify_python_cpp \ + verify_python_cpp.in + + + + + diff --git a/qpid/cpp/examples/request-response/client.cpp b/qpid/cpp/examples/request-response/client.cpp new file mode 100644 index 0000000000..0ee0e78c92 --- /dev/null +++ b/qpid/cpp/examples/request-response/client.cpp @@ -0,0 +1,148 @@ +/* + * + * 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. + * + */ + + +/** + * client.cpp + * + * This program is one of two programs that illustrate the + * request/response pattern. + * + * client.cpp (this program) + * + * Make requests of a service, print the response. + * + * service.cpp + * + * Accept requests, reverse the letters in each message, and + * return it as a response. + * + */ + + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +using namespace qpid::client; +using namespace qpid::framing; + +class Listener : public MessageListener{ + private: + SubscriptionManager& subscriptions; + int counter; + public: + Listener(SubscriptionManager& subscriptions); + virtual void received(Message& message); +}; + +Listener::Listener(SubscriptionManager& subs) : subscriptions(subs), counter(0) +{} + +void Listener::received(Message& message) { + std::cout << "Response: " << message.getData() << std::endl; + + ++ counter; + if (counter > 3) { + std::cout << "Shutting down listener for " << message.getDestination() << std::endl; + subscriptions.cancel(message.getDestination()); + } +} + + +using std::stringstream; +using std::string; + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message request; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + // Create a response queue so the server can send us responses + // to our requests. Use the client's session ID as the name + // of the response queue. + + stringstream response_queue; + response_queue << "client" << session.getId().getName(); + + // Use the name of the response queue as the routing key + + session.queueDeclare(arg::queue=response_queue.str()); + session.exchangeBind(arg::exchange="amq.direct", arg::queue=response_queue.str(), arg::bindingKey=response_queue.str()); + + // Each client sends the name of their own response queue so + // the service knows where to route messages. + + request.getDeliveryProperties().setRoutingKey("request"); + request.getMessageProperties().setReplyTo(ReplyTo("amq.direct", response_queue.str())); + + // Create a listener for the response queue and listen for response messages. + std::cout << "Activating response queue listener for: " << response_queue.str() << std::endl; + SubscriptionManager subscriptions(session); + Listener listener(subscriptions); + subscriptions.subscribe(listener, response_queue.str()); + + // Now send some requests ... + + string s[] = { + "Twas brillig, and the slithy toves", + "Did gire and gymble in the wabe.", + "All mimsy were the borogroves,", + "And the mome raths outgrabe." + }; + + + for (int i=0; i<4; i++) { + request.setData(s[i]); + // Asynchronous transfer sends messages as quickly as + // possible without waiting for confirmation. + async(session).messageTransfer(arg::content=request, arg::destination="amq.direct"); + std::cout << "Request: " << s[i] << std::endl; + } + + std::cout << "Waiting for all responses to arrive ..." << std::endl; + subscriptions.run(); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/request-response/server.cpp b/qpid/cpp/examples/request-response/server.cpp new file mode 100644 index 0000000000..df189cfdd8 --- /dev/null +++ b/qpid/cpp/examples/request-response/server.cpp @@ -0,0 +1,145 @@ +/* + * + * 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. + * + */ + + +/** + * server.cpp + * + * This program is one of two programs that illustrate the + * request/response pattern. + * + * client.cpp + * + * Make requests of a service, print the response. + * + * server.cpp (this program) + * + * Accept requests, reverse the letters in each message, and + * return it as a response. + * + */ + + +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include + +#include +#include + +using namespace qpid::client; +using namespace qpid::framing; +using std::stringstream; +using std::string; + +class Listener : public MessageListener{ + private: + SubscriptionManager& subscriptions; + AsyncSession asyncSession; + public: + Listener(SubscriptionManager& subscriptions, Session& session); + virtual void received(Message& message); +}; + +Listener::Listener(SubscriptionManager& subs, Session& session) + : subscriptions(subs), asyncSession(session) +{} + +void Listener::received(Message& request) { + Message response; + + // Get routing key for response from the request's replyTo property + string routingKey; + + if (request.getMessageProperties().hasReplyTo()) { + routingKey = request.getMessageProperties().getReplyTo().getRoutingKey(); + } else { + std::cout << "Error: " << "No routing key for request (" << request.getData() << ")" << std::endl; + return; + } + + std::cout << "Request: " << request.getData() << " (" <1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message message; + try { + connection.open(host, port); + 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(); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/request-response/verify b/qpid/cpp/examples/request-response/verify new file mode 100644 index 0000000000..76007ff8d2 --- /dev/null +++ b/qpid/cpp/examples/request-response/verify @@ -0,0 +1,5 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Waiting" ./server +clients ./client +kill %% # Must kill the server. +outputs "./client.out | remove_uuid" "server.out | remove_uuid" diff --git a/qpid/cpp/examples/request-response/verify.in b/qpid/cpp/examples/request-response/verify.in new file mode 100644 index 0000000000..7925dc5671 --- /dev/null +++ b/qpid/cpp/examples/request-response/verify.in @@ -0,0 +1,19 @@ +==== client.out | remove_uuid +Activating response queue listener for: client +Request: Twas brillig, and the slithy toves +Request: Did gire and gymble in the wabe. +Request: All mimsy were the borogroves, +Request: And the mome raths outgrabe. +Waiting for all responses to arrive ... +Response: TWAS BRILLIG, AND THE SLITHY TOVES +Response: DID GIRE AND GYMBLE IN THE WABE. +Response: ALL MIMSY WERE THE BOROGROVES, +Response: AND THE MOME RATHS OUTGRABE. +Shutting down listener for client +==== server.out | remove_uuid +Activating request queue listener for: request +Waiting for requests +Request: Twas brillig, and the slithy toves (client) +Request: Did gire and gymble in the wabe. (client) +Request: All mimsy were the borogroves, (client) +Request: And the mome raths outgrabe. (client) diff --git a/qpid/cpp/examples/request-response/verify_cpp_python b/qpid/cpp/examples/request-response/verify_cpp_python new file mode 100644 index 0000000000..867af3a92b --- /dev/null +++ b/qpid/cpp/examples/request-response/verify_cpp_python @@ -0,0 +1,6 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Request server running" $PYTHON_EXAMPLES/request-response/server.py +clients ./client +sleep 1 +kill %% # Must kill the server. +outputs "./client.out | remove_uuid" "$PYTHON_EXAMPLES/request-response/server.py.out | remove_uuid" diff --git a/qpid/cpp/examples/request-response/verify_cpp_python.in b/qpid/cpp/examples/request-response/verify_cpp_python.in new file mode 100644 index 0000000000..a032293d9b --- /dev/null +++ b/qpid/cpp/examples/request-response/verify_cpp_python.in @@ -0,0 +1,15 @@ +==== client.out | remove_uuid +Activating response queue listener for: client +Request: Twas brillig, and the slithy toves +Request: Did gire and gymble in the wabe. +Request: All mimsy were the borogroves, +Request: And the mome raths outgrabe. +Waiting for all responses to arrive ... +Response: TWAS BRILLIG, AND THE SLITHY TOVES +Response: DID GIRE AND GYMBLE IN THE WABE. +Response: ALL MIMSY WERE THE BOROGROVES, +Response: AND THE MOME RATHS OUTGRABE. +Shutting down listener for client +==== server.py.out | remove_uuid +Request server running - run your client now. +(Times out after 100 seconds ...) diff --git a/qpid/cpp/examples/request-response/verify_python_cpp b/qpid/cpp/examples/request-response/verify_python_cpp new file mode 100644 index 0000000000..d6f0fa7152 --- /dev/null +++ b/qpid/cpp/examples/request-response/verify_python_cpp @@ -0,0 +1,5 @@ +# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify +background "Waiting" ./server +clients $PYTHON_EXAMPLES/request-response/client.py +kill %% # Must kill the server. +outputs "$PYTHON_EXAMPLES/request-response/client.py.out | remove_uuid" "server.out | remove_uuid" diff --git a/qpid/cpp/examples/request-response/verify_python_cpp.in b/qpid/cpp/examples/request-response/verify_python_cpp.in new file mode 100644 index 0000000000..1500134619 --- /dev/null +++ b/qpid/cpp/examples/request-response/verify_python_cpp.in @@ -0,0 +1,18 @@ +==== client.py.out | remove_uuid +Request: Twas brillig, and the slithy toves +Request: Did gyre and gimble in the wabe. +Request: All mimsy were the borogroves, +Request: And the mome raths outgrabe. +Messages on queue: reply_to: +Response: TWAS BRILLIG, AND THE SLITHY TOVES +Response: DID GYRE AND GIMBLE IN THE WABE. +Response: ALL MIMSY WERE THE BOROGROVES, +Response: AND THE MOME RATHS OUTGRABE. +No more messages! +==== server.out | remove_uuid +Activating request queue listener for: request +Waiting for requests +Request: Twas brillig, and the slithy toves (reply_to:) +Request: Did gyre and gimble in the wabe. (reply_to:) +Request: All mimsy were the borogroves, (reply_to:) +Request: And the mome raths outgrabe. (reply_to:) diff --git a/qpid/cpp/examples/verify b/qpid/cpp/examples/verify index 251097930e..247e75d4a9 100755 --- a/qpid/cpp/examples/verify +++ b/qpid/cpp/examples/verify @@ -8,7 +8,8 @@ # If $QPID_HOST or $QPID_PORT are set, use them to connect. # -export QPID_DATA_DIR= +QPID_DATA_DIR= +export QPID_DATA_DIR cleanup() { test -n "$QPIDD" && $QPIDD -q # Private broker diff --git a/qpid/cpp/examples/verify_all b/qpid/cpp/examples/verify_all index 0e797202ff..9fbaa4a8df 100755 --- a/qpid/cpp/examples/verify_all +++ b/qpid/cpp/examples/verify_all @@ -9,9 +9,10 @@ exclude_regexp=$3 python=${QPID_PYTHON_DIR:-$topsrcdir/python} trap "$qpidd -q" exit -export QPID_PORT=`$qpidd -dp0 --no-module-dir --data-dir "" --auth no` || { echo "Can't run qpidd" ; exit 1; } -export PYTHON_EXAMPLES=$python/examples -export PYTHONPATH=$python:$PYTHONPATH +QPID_PORT=`$qpidd -dp0 --no-module-dir --data-dir "" --auth no` || { echo "Can't run qpidd" ; exit 1; } +PYTHON_EXAMPLES=$python/examples +PYTHONPATH=$python:$PYTHONPATH +export QPID_PORT PYTHON_EXAMPLES PYTHONPATH test -d $PYTHON_EXAMPLES || echo "WARNING: No python examples. $PYTHON_EXAMPLES not found." find="find examples" diff --git a/qpid/cpp/examples/xml-exchange/Makefile.am b/qpid/cpp/examples/xml-exchange/Makefile.am new file mode 100644 index 0000000000..1b25a8750d --- /dev/null +++ b/qpid/cpp/examples/xml-exchange/Makefile.am @@ -0,0 +1,29 @@ +examplesdir=$(pkgdatadir)/examples/xml-exchange + +include $(top_srcdir)/examples/makedist.mk + +noinst_PROGRAMS=declare_queues xml_producer listener + +declare_queues_SOURCES=declare_queues.cpp +declare_queues_LDADD=$(CLIENT_LIB) + +xml_producer_SOURCES=xml_producer.cpp +xml_producer_LDADD=$(CLIENT_LIB) + +listener_SOURCES=listener.cpp +listener_LDADD=$(CLIENT_LIB) + +EXTRA_DIST= \ + README + +examples_DATA= \ + $(EXTRA_DIST) \ + declare_queues.cpp \ + listener.cpp \ + xml_producer.cpp \ + $(MAKEDIST) + + + + + diff --git a/qpid/cpp/examples/xml-exchange/README b/qpid/cpp/examples/xml-exchange/README new file mode 100644 index 0000000000..26b9fac97a --- /dev/null +++ b/qpid/cpp/examples/xml-exchange/README @@ -0,0 +1,48 @@ +This example shows how to program a simple application +using the XML Exchange. + +To run the example, execute the programs in the +following order: + +1 ./declare_queues +2 ./listener +3 ./message_producer (in a separate window) + +The XML Exchange must be explicitly declared. Bindings +are established using queries in XQuery. These queries +can reference message content, message application +properties (which are declared as external variables +in the XQuery), or both. + +Once this is done, message producers publish to the +exchange using the exchange name and a routing key, +just as for other exchange types. Message consumers +read from the queues to which messages are routed. +If a message does not have XML content, or is +missing message application properties needed by +the query, the query is not routed. + +Queries can use message application headers to +provide functionality similar to JMS selectors. +If a query does not use the content of a message, +the message content is not parsed, and need not +be XML. + +The XQuery processor, XQilla, does path-based +document projection, so once the portion of +a document needed to evaluate a query has +been read, it stops parsing the document. +Suppose a long document has a header section. +You can indicate in the query that only +one header section needs to be queried, +and there is no need to parse the entire +document to see if there are further header +sections, using a path like this: + +./message/header[1]/date + +If you used a path like this, all children +of the message element would be read to +see if there are further headers: + +./message/header/date diff --git a/qpid/cpp/examples/xml-exchange/declare_queues.cpp b/qpid/cpp/examples/xml-exchange/declare_queues.cpp new file mode 100644 index 0000000000..1307c473c5 --- /dev/null +++ b/qpid/cpp/examples/xml-exchange/declare_queues.cpp @@ -0,0 +1,76 @@ +/* + * + * 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 + +using namespace qpid::client; +using namespace qpid::framing; + +using std::string; + + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + + try { + connection.open(host, port); + Session session = connection.newSession(); + + + //--------- Main body of program -------------------------------------------- + + // Set up queues, bind them with queries. Note that the XML exchange + // is not in the AMQP specification, so it is called "xml", not "amq.xml". + // Note that the XML exchange is not predeclared in Qpid, it must + // be declared by the application. + + session.queueDeclare(arg::queue="message_queue"); + session.exchangeDeclare(arg::exchange="xml", arg::type="xml"); + + // Application message properties are mapped to external variables + // in the XQuery. An XML Exchange can query message properties much + // like JMS, query the XML content of the message, or both. + + FieldTable binding; + binding.setString("xquery", "declare variable $control external;" + "./message/id mod 2 = 1 or $control = 'end'"); + session.exchangeBind(arg::exchange="xml", arg::queue="message_queue", arg::bindingKey="query_name", arg::arguments=binding); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; + +} + + + diff --git a/qpid/cpp/examples/xml-exchange/listener.cpp b/qpid/cpp/examples/xml-exchange/listener.cpp new file mode 100644 index 0000000000..98646bea95 --- /dev/null +++ b/qpid/cpp/examples/xml-exchange/listener.cpp @@ -0,0 +1,89 @@ +/* + * + * 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. + * + */ + +/** + * listener.cpp: This program reads messages fro a queue on + * the broker using a message listener. + */ + +#include +#include +#include +#include + +#include +#include +#include + +using namespace qpid::client; +using namespace qpid::framing; + + +class Listener : public MessageListener{ + private: + SubscriptionManager& subscriptions; + public: + Listener(SubscriptionManager& subscriptions); + virtual void received(Message& message); +}; + +Listener::Listener(SubscriptionManager& subs) : subscriptions(subs) +{} + +void Listener::received(Message& message) { + std::cout << "Message: " << message.getData() << std::endl; + if (message.getHeaders().getString("control") == "end") { + std::cout << "Shutting down listener for " << message.getDestination() + << std::endl; + subscriptions.cancel(message.getDestination()); + } +} + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message msg; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + SubscriptionManager subscriptions(session); + // Create a listener and subscribe it to the queue named "message_queue" + Listener listener(subscriptions); + subscriptions.subscribe(listener, "message_queue"); + // Receive messages until the subscription is cancelled + // by Listener::received() + subscriptions.run(); + + //--------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + diff --git a/qpid/cpp/examples/xml-exchange/xml_producer.cpp b/qpid/cpp/examples/xml-exchange/xml_producer.cpp new file mode 100644 index 0000000000..19889e4891 --- /dev/null +++ b/qpid/cpp/examples/xml-exchange/xml_producer.cpp @@ -0,0 +1,91 @@ +/* + * + * 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 + +using namespace qpid::client; +using namespace qpid::framing; + +using std::stringstream; +using std::string; + +int main(int argc, char** argv) { + const char* host = argc>1 ? argv[1] : "127.0.0.1"; + int port = argc>2 ? atoi(argv[2]) : 5672; + Connection connection; + Message message; + try { + connection.open(host, port); + Session session = connection.newSession(); + + //--------- Main body of program -------------------------------------------- + + // Publish some XML messages. Use the control property to + // indicate when we are finished. + // + // In the XML exchange, the routing key and the name of + // the query match. + + message.getDeliveryProperties().setRoutingKey("query_name"); + message.getHeaders().setString("control","continue"); + + // Now send some messages ... + + for (int i=0; i<10; i++) { + stringstream message_data; + message_data << "" << i << ""; + + std::cout << "Message data: " << message_data.str() << std::endl; + + message.setData(message_data.str()); + // Asynchronous transfer sends messages as quickly as + // possible without waiting for confirmation. + async(session).messageTransfer(arg::content=message, arg::destination="xml"); + } + + // And send a final message to indicate termination. + + message.getHeaders().setString("control","end"); + message.setData("That's all, folks!"); + session.messageTransfer(arg::content=message, arg::destination="xml"); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; +} + + -- cgit v1.2.1