From f83677056891e436bf5ba99e79240df2a44528cd Mon Sep 17 00:00:00 2001 From: "Stephen D. Huston" Date: Fri, 21 Oct 2011 14:42:12 +0000 Subject: Merged out from trunk git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/QPID-2519@1187375 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/examples/CMakeLists.txt | 13 +- cpp/examples/Makefile.am | 16 +- cpp/examples/README.verify | 42 --- cpp/examples/direct/CMakeLists.txt | 22 -- cpp/examples/direct/Makefile.am | 47 --- cpp/examples/direct/declare_queues.cpp | 85 ----- cpp/examples/direct/direct_declare_queues.vcproj | 394 --------------------- cpp/examples/direct/direct_direct_producer.vcproj | 394 --------------------- cpp/examples/direct/direct_listener.vcproj | 394 --------------------- cpp/examples/direct/direct_producer.cpp | 109 ------ cpp/examples/direct/listener.cpp | 109 ------ cpp/examples/direct/verify | 23 -- cpp/examples/direct/verify.in | 15 - cpp/examples/examples.sln | 24 ++ cpp/examples/failover/CMakeLists.txt | 22 -- cpp/examples/failover/Makefile.am | 47 --- cpp/examples/failover/declare_queues.cpp | 61 ---- .../failover/failover_declare_queues.vcproj | 394 --------------------- .../failover/failover_replaying_sender.vcproj | 394 --------------------- .../failover/failover_resuming_receiver.vcproj | 394 --------------------- cpp/examples/failover/replaying_sender.cpp | 97 ----- cpp/examples/failover/resuming_receiver.cpp | 127 ------- cpp/examples/fanout/CMakeLists.txt | 21 -- cpp/examples/fanout/Makefile.am | 42 --- cpp/examples/fanout/fanout_fanout_producer.vcproj | 394 --------------------- cpp/examples/fanout/fanout_listener.vcproj | 394 --------------------- cpp/examples/fanout/fanout_producer.cpp | 105 ------ cpp/examples/fanout/listener.cpp | 125 ------- cpp/examples/fanout/verify | 25 -- cpp/examples/fanout/verify.in | 43 --- cpp/examples/messaging/drain.cpp | 4 +- cpp/examples/messaging/server.cpp | 4 +- cpp/examples/messaging/spout.cpp | 2 +- cpp/examples/old-examples.sln | 147 -------- cpp/examples/old_api/CMakeLists.txt | 25 ++ cpp/examples/old_api/Makefile.am | 48 +++ cpp/examples/old_api/README.verify | 42 +++ cpp/examples/old_api/direct/CMakeLists.txt | 22 ++ cpp/examples/old_api/direct/Makefile.am | 47 +++ cpp/examples/old_api/direct/declare_queues.cpp | 85 +++++ .../old_api/direct/direct_declare_queues.vcproj | 394 +++++++++++++++++++++ .../old_api/direct/direct_direct_producer.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/direct/direct_listener.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/direct/direct_producer.cpp | 109 ++++++ cpp/examples/old_api/direct/listener.cpp | 109 ++++++ cpp/examples/old_api/direct/verify | 23 ++ cpp/examples/old_api/direct/verify.in | 15 + cpp/examples/old_api/failover/CMakeLists.txt | 22 ++ cpp/examples/old_api/failover/Makefile.am | 47 +++ cpp/examples/old_api/failover/declare_queues.cpp | 61 ++++ .../failover/failover_declare_queues.vcproj | 394 +++++++++++++++++++++ .../failover/failover_replaying_sender.vcproj | 394 +++++++++++++++++++++ .../failover/failover_resuming_receiver.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/failover/replaying_sender.cpp | 97 +++++ .../old_api/failover/resuming_receiver.cpp | 127 +++++++ cpp/examples/old_api/fanout/CMakeLists.txt | 21 ++ cpp/examples/old_api/fanout/Makefile.am | 42 +++ .../old_api/fanout/fanout_fanout_producer.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/fanout/fanout_listener.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/fanout/fanout_producer.cpp | 105 ++++++ cpp/examples/old_api/fanout/listener.cpp | 125 +++++++ cpp/examples/old_api/fanout/verify | 25 ++ cpp/examples/old_api/fanout/verify.in | 43 +++ cpp/examples/old_api/old-examples.sln | 123 +++++++ cpp/examples/old_api/pub-sub/CMakeLists.txt | 21 ++ cpp/examples/old_api/pub-sub/Makefile.am | 43 +++ .../old_api/pub-sub/pub-sub_topic_listener.vcproj | 394 +++++++++++++++++++++ .../old_api/pub-sub/pub-sub_topic_publisher.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/pub-sub/topic_listener.cpp | 173 +++++++++ cpp/examples/old_api/pub-sub/topic_publisher.cpp | 129 +++++++ cpp/examples/old_api/pub-sub/verify | 23 ++ cpp/examples/old_api/pub-sub/verify.in | 59 +++ .../old_api/request-response/CMakeLists.txt | 21 ++ cpp/examples/old_api/request-response/Makefile.am | 43 +++ cpp/examples/old_api/request-response/client.cpp | 163 +++++++++ .../request-response_client.vcproj | 394 +++++++++++++++++++++ .../request-response_server.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/request-response/server.cpp | 161 +++++++++ cpp/examples/old_api/request-response/verify | 24 ++ cpp/examples/old_api/request-response/verify.in | 19 + cpp/examples/old_api/tradedemo/CMakeLists.txt | 22 ++ cpp/examples/old_api/tradedemo/Makefile.am | 46 +++ cpp/examples/old_api/tradedemo/declare_queues.cpp | 98 +++++ cpp/examples/old_api/tradedemo/topic_listener.cpp | 183 ++++++++++ cpp/examples/old_api/tradedemo/topic_publisher.cpp | 271 ++++++++++++++ .../tradedemo/tradedemo_declare_queues.vcproj | 394 +++++++++++++++++++++ .../tradedemo/tradedemo_topic_listener.vcproj | 394 +++++++++++++++++++++ .../tradedemo/tradedemo_topic_publisher.vcproj | 394 +++++++++++++++++++++ cpp/examples/old_api/verify | 121 +++++++ cpp/examples/old_api/verify_all | 46 +++ cpp/examples/old_api/xml-exchange/CMakeLists.txt | 24 ++ cpp/examples/old_api/xml-exchange/Makefile.am | 49 +++ cpp/examples/old_api/xml-exchange/README.txt | 53 +++ .../old_api/xml-exchange/declare_queues.cpp | 98 +++++ cpp/examples/old_api/xml-exchange/listener.cpp | 107 ++++++ cpp/examples/old_api/xml-exchange/xml_producer.cpp | 113 ++++++ cpp/examples/pub-sub/CMakeLists.txt | 21 -- cpp/examples/pub-sub/Makefile.am | 43 --- cpp/examples/pub-sub/pub-sub_topic_listener.vcproj | 394 --------------------- .../pub-sub/pub-sub_topic_publisher.vcproj | 394 --------------------- cpp/examples/pub-sub/topic_listener.cpp | 173 --------- cpp/examples/pub-sub/topic_publisher.cpp | 129 ------- cpp/examples/pub-sub/verify | 23 -- cpp/examples/pub-sub/verify.in | 59 --- cpp/examples/qmf-console/ping.cpp | 4 +- cpp/examples/qmf-console/printevents.cpp | 4 +- cpp/examples/request-response/CMakeLists.txt | 21 -- cpp/examples/request-response/Makefile.am | 43 --- cpp/examples/request-response/client.cpp | 163 --------- .../request-response_client.vcproj | 394 --------------------- .../request-response_server.vcproj | 394 --------------------- cpp/examples/request-response/server.cpp | 161 --------- cpp/examples/request-response/verify | 24 -- cpp/examples/request-response/verify.in | 19 - cpp/examples/tradedemo/CMakeLists.txt | 22 -- cpp/examples/tradedemo/Makefile.am | 46 --- cpp/examples/tradedemo/declare_queues.cpp | 98 ----- cpp/examples/tradedemo/topic_listener.cpp | 183 ---------- cpp/examples/tradedemo/topic_publisher.cpp | 271 -------------- .../tradedemo/tradedemo_declare_queues.vcproj | 394 --------------------- .../tradedemo/tradedemo_topic_listener.vcproj | 394 --------------------- .../tradedemo/tradedemo_topic_publisher.vcproj | 394 --------------------- cpp/examples/verify | 121 ------- cpp/examples/verify_all | 46 --- cpp/examples/xml-exchange/CMakeLists.txt | 24 -- cpp/examples/xml-exchange/Makefile.am | 49 --- cpp/examples/xml-exchange/README.txt | 53 --- cpp/examples/xml-exchange/declare_queues.cpp | 98 ----- cpp/examples/xml-exchange/listener.cpp | 107 ------ cpp/examples/xml-exchange/xml_producer.cpp | 113 ------ 130 files changed, 9417 insertions(+), 9371 deletions(-) delete mode 100644 cpp/examples/README.verify delete mode 100644 cpp/examples/direct/CMakeLists.txt delete mode 100644 cpp/examples/direct/Makefile.am delete mode 100644 cpp/examples/direct/declare_queues.cpp delete mode 100644 cpp/examples/direct/direct_declare_queues.vcproj delete mode 100644 cpp/examples/direct/direct_direct_producer.vcproj delete mode 100644 cpp/examples/direct/direct_listener.vcproj delete mode 100644 cpp/examples/direct/direct_producer.cpp delete mode 100644 cpp/examples/direct/listener.cpp delete mode 100644 cpp/examples/direct/verify delete mode 100644 cpp/examples/direct/verify.in delete mode 100644 cpp/examples/failover/CMakeLists.txt delete mode 100644 cpp/examples/failover/Makefile.am delete mode 100644 cpp/examples/failover/declare_queues.cpp delete mode 100644 cpp/examples/failover/failover_declare_queues.vcproj delete mode 100644 cpp/examples/failover/failover_replaying_sender.vcproj delete mode 100644 cpp/examples/failover/failover_resuming_receiver.vcproj delete mode 100644 cpp/examples/failover/replaying_sender.cpp delete mode 100644 cpp/examples/failover/resuming_receiver.cpp delete mode 100644 cpp/examples/fanout/CMakeLists.txt delete mode 100644 cpp/examples/fanout/Makefile.am delete mode 100644 cpp/examples/fanout/fanout_fanout_producer.vcproj delete mode 100644 cpp/examples/fanout/fanout_listener.vcproj delete mode 100644 cpp/examples/fanout/fanout_producer.cpp delete mode 100644 cpp/examples/fanout/listener.cpp delete mode 100644 cpp/examples/fanout/verify delete mode 100644 cpp/examples/fanout/verify.in delete mode 100644 cpp/examples/old-examples.sln create mode 100644 cpp/examples/old_api/CMakeLists.txt create mode 100644 cpp/examples/old_api/Makefile.am create mode 100644 cpp/examples/old_api/README.verify create mode 100644 cpp/examples/old_api/direct/CMakeLists.txt create mode 100644 cpp/examples/old_api/direct/Makefile.am create mode 100644 cpp/examples/old_api/direct/declare_queues.cpp create mode 100644 cpp/examples/old_api/direct/direct_declare_queues.vcproj create mode 100644 cpp/examples/old_api/direct/direct_direct_producer.vcproj create mode 100644 cpp/examples/old_api/direct/direct_listener.vcproj create mode 100644 cpp/examples/old_api/direct/direct_producer.cpp create mode 100644 cpp/examples/old_api/direct/listener.cpp create mode 100644 cpp/examples/old_api/direct/verify create mode 100644 cpp/examples/old_api/direct/verify.in create mode 100644 cpp/examples/old_api/failover/CMakeLists.txt create mode 100644 cpp/examples/old_api/failover/Makefile.am create mode 100644 cpp/examples/old_api/failover/declare_queues.cpp create mode 100644 cpp/examples/old_api/failover/failover_declare_queues.vcproj create mode 100644 cpp/examples/old_api/failover/failover_replaying_sender.vcproj create mode 100644 cpp/examples/old_api/failover/failover_resuming_receiver.vcproj create mode 100644 cpp/examples/old_api/failover/replaying_sender.cpp create mode 100644 cpp/examples/old_api/failover/resuming_receiver.cpp create mode 100644 cpp/examples/old_api/fanout/CMakeLists.txt create mode 100644 cpp/examples/old_api/fanout/Makefile.am create mode 100644 cpp/examples/old_api/fanout/fanout_fanout_producer.vcproj create mode 100644 cpp/examples/old_api/fanout/fanout_listener.vcproj create mode 100644 cpp/examples/old_api/fanout/fanout_producer.cpp create mode 100644 cpp/examples/old_api/fanout/listener.cpp create mode 100644 cpp/examples/old_api/fanout/verify create mode 100644 cpp/examples/old_api/fanout/verify.in create mode 100644 cpp/examples/old_api/old-examples.sln create mode 100644 cpp/examples/old_api/pub-sub/CMakeLists.txt create mode 100644 cpp/examples/old_api/pub-sub/Makefile.am create mode 100644 cpp/examples/old_api/pub-sub/pub-sub_topic_listener.vcproj create mode 100644 cpp/examples/old_api/pub-sub/pub-sub_topic_publisher.vcproj create mode 100644 cpp/examples/old_api/pub-sub/topic_listener.cpp create mode 100644 cpp/examples/old_api/pub-sub/topic_publisher.cpp create mode 100644 cpp/examples/old_api/pub-sub/verify create mode 100644 cpp/examples/old_api/pub-sub/verify.in create mode 100644 cpp/examples/old_api/request-response/CMakeLists.txt create mode 100644 cpp/examples/old_api/request-response/Makefile.am create mode 100644 cpp/examples/old_api/request-response/client.cpp create mode 100644 cpp/examples/old_api/request-response/request-response_client.vcproj create mode 100644 cpp/examples/old_api/request-response/request-response_server.vcproj create mode 100644 cpp/examples/old_api/request-response/server.cpp create mode 100644 cpp/examples/old_api/request-response/verify create mode 100644 cpp/examples/old_api/request-response/verify.in create mode 100644 cpp/examples/old_api/tradedemo/CMakeLists.txt create mode 100644 cpp/examples/old_api/tradedemo/Makefile.am create mode 100644 cpp/examples/old_api/tradedemo/declare_queues.cpp create mode 100644 cpp/examples/old_api/tradedemo/topic_listener.cpp create mode 100644 cpp/examples/old_api/tradedemo/topic_publisher.cpp create mode 100644 cpp/examples/old_api/tradedemo/tradedemo_declare_queues.vcproj create mode 100644 cpp/examples/old_api/tradedemo/tradedemo_topic_listener.vcproj create mode 100644 cpp/examples/old_api/tradedemo/tradedemo_topic_publisher.vcproj create mode 100755 cpp/examples/old_api/verify create mode 100755 cpp/examples/old_api/verify_all create mode 100644 cpp/examples/old_api/xml-exchange/CMakeLists.txt create mode 100644 cpp/examples/old_api/xml-exchange/Makefile.am create mode 100644 cpp/examples/old_api/xml-exchange/README.txt create mode 100644 cpp/examples/old_api/xml-exchange/declare_queues.cpp create mode 100644 cpp/examples/old_api/xml-exchange/listener.cpp create mode 100644 cpp/examples/old_api/xml-exchange/xml_producer.cpp delete mode 100644 cpp/examples/pub-sub/CMakeLists.txt delete mode 100644 cpp/examples/pub-sub/Makefile.am delete mode 100644 cpp/examples/pub-sub/pub-sub_topic_listener.vcproj delete mode 100644 cpp/examples/pub-sub/pub-sub_topic_publisher.vcproj delete mode 100644 cpp/examples/pub-sub/topic_listener.cpp delete mode 100644 cpp/examples/pub-sub/topic_publisher.cpp delete mode 100644 cpp/examples/pub-sub/verify delete mode 100644 cpp/examples/pub-sub/verify.in delete mode 100644 cpp/examples/request-response/CMakeLists.txt delete mode 100644 cpp/examples/request-response/Makefile.am delete mode 100644 cpp/examples/request-response/client.cpp delete mode 100644 cpp/examples/request-response/request-response_client.vcproj delete mode 100644 cpp/examples/request-response/request-response_server.vcproj delete mode 100644 cpp/examples/request-response/server.cpp delete mode 100644 cpp/examples/request-response/verify delete mode 100644 cpp/examples/request-response/verify.in delete mode 100644 cpp/examples/tradedemo/CMakeLists.txt delete mode 100644 cpp/examples/tradedemo/Makefile.am delete mode 100644 cpp/examples/tradedemo/declare_queues.cpp delete mode 100644 cpp/examples/tradedemo/topic_listener.cpp delete mode 100644 cpp/examples/tradedemo/topic_publisher.cpp delete mode 100644 cpp/examples/tradedemo/tradedemo_declare_queues.vcproj delete mode 100644 cpp/examples/tradedemo/tradedemo_topic_listener.vcproj delete mode 100644 cpp/examples/tradedemo/tradedemo_topic_publisher.vcproj delete mode 100755 cpp/examples/verify delete mode 100755 cpp/examples/verify_all delete mode 100644 cpp/examples/xml-exchange/CMakeLists.txt delete mode 100644 cpp/examples/xml-exchange/Makefile.am delete mode 100644 cpp/examples/xml-exchange/README.txt delete mode 100644 cpp/examples/xml-exchange/declare_queues.cpp delete mode 100644 cpp/examples/xml-exchange/listener.cpp delete mode 100644 cpp/examples/xml-exchange/xml_producer.cpp (limited to 'cpp/examples') diff --git a/cpp/examples/CMakeLists.txt b/cpp/examples/CMakeLists.txt index da8e39e944..1b28cfd031 100644 --- a/cpp/examples/CMakeLists.txt +++ b/cpp/examples/CMakeLists.txt @@ -77,25 +77,14 @@ macro(add_example subdir example) endmacro(add_example) install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.txt - ${CMAKE_CURRENT_SOURCE_DIR}/README.verify - ${CMAKE_CURRENT_SOURCE_DIR}/verify - ${CMAKE_CURRENT_SOURCE_DIR}/verify_all DESTINATION ${QPID_INSTALL_EXAMPLESDIR} COMPONENT ${QPID_COMPONENT_EXAMPLES}) if (MSVC) install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/examples.sln - ${CMAKE_CURRENT_SOURCE_DIR}/old-examples.sln DESTINATION ${QPID_INSTALL_EXAMPLESDIR} COMPONENT ${QPID_COMPONENT_EXAMPLES}) endif (MSVC) -add_subdirectory(direct) -add_subdirectory(failover) -add_subdirectory(fanout) -add_subdirectory(pub-sub) -#add_subdirectory(qmf-agent) add_subdirectory(qmf-console) -add_subdirectory(request-response) -add_subdirectory(tradedemo) -add_subdirectory(xml-exchange) add_subdirectory(messaging) +add_subdirectory(old_api) diff --git a/cpp/examples/Makefile.am b/cpp/examples/Makefile.am index c6cc308d98..6b2bb73587 100644 --- a/cpp/examples/Makefile.am +++ b/cpp/examples/Makefile.am @@ -16,15 +16,7 @@ # specific language governing permissions and limitations # under the License. # -SUBDIRS = direct fanout pub-sub request-response failover qmf-console tradedemo messaging -if HAVE_XML - SUBDIRS += xml-exchange - broker_args = "--no-module-dir --data-dir \"\" --auth no --load-module $(top_builddir)/src/.libs/xml.so" -endif -if !HAVE_XML - exclude_examples_regexp="xml" # Exclude XML examples. - broker_args = "--no-module-dir --data-dir \"\" --auth no" -endif +SUBDIRS = qmf-console messaging old_api MAKEDIST=.libs/Makefile @@ -37,13 +29,9 @@ $(MAKEDIST): Makefile examplesdir=$(pkgdatadir)/examples dist_examples_DATA = README.txt $(MAKEDIST) -EXTRA_DIST = README.verify verify verify_all examples.sln CMakeLists.txt +EXTRA_DIST = examples.sln CMakeLists.txt # For older versions of automake abs_top_srcdir = @abs_top_srcdir@ abs_top_builddir = @abs_top_builddir@ -# Verify the examples in the buid tree. -check-local: - $(srcdir)/verify_all $(abs_top_srcdir)/.. $(abs_top_builddir) $(broker_args) $(exclude_examples_regexp) - diff --git a/cpp/examples/README.verify b/cpp/examples/README.verify deleted file mode 100644 index e1370764c9..0000000000 --- a/cpp/examples/README.verify +++ /dev/null @@ -1,42 +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. -# -= Qpid C++ Examples = - -For more information read examples/README. - -== The Verify All Script == - -The verify_all script will run each C++ example and compare its output -against what is expected. - -=== Arguments === - -The verify_all script expects the path to Qpid trunk as an argument. - -== 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/cpp/examples/direct/CMakeLists.txt b/cpp/examples/direct/CMakeLists.txt deleted file mode 100644 index 2ec1b2b813..0000000000 --- a/cpp/examples/direct/CMakeLists.txt +++ /dev/null @@ -1,22 +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. -# - -add_example(direct declare_queues) -add_example(direct direct_producer) -add_example(direct listener) diff --git a/cpp/examples/direct/Makefile.am b/cpp/examples/direct/Makefile.am deleted file mode 100644 index b07db2cfd6..0000000000 --- a/cpp/examples/direct/Makefile.am +++ /dev/null @@ -1,47 +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. -# -examplesdir=$(pkgdatadir)/examples/direct - -MAKELDFLAGS=$(CLIENTFLAGS) -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) \ - CMakeLists.txt \ - verify \ - verify.in \ - direct_declare_queues.vcproj \ - direct_direct_producer.vcproj \ - direct_listener.vcproj diff --git a/cpp/examples/direct/declare_queues.cpp b/cpp/examples/direct/declare_queues.cpp deleted file mode 100644 index 9a51d1982b..0000000000 --- a/cpp/examples/direct/declare_queues.cpp +++ /dev/null @@ -1,85 +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. - * - * declare_queues.cpp: (this program): - * - * Creates a queue named "message_queue" on a broker, binding the - * queue to the "amq.direct" exchange, using the routing key - * "routing_key". - * - * direct_producer.cpp - * - * Publishes to the "amq.direct" exchange, specifying the routing - * key "routing_key" - * - * listener.cpp - * - * Reads from the "message_queue" queue on the broker using a - * message listener. - * - */ - -#include -#include - - -using namespace qpid::client; -using namespace qpid::framing; - - -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/cpp/examples/direct/direct_declare_queues.vcproj b/cpp/examples/direct/direct_declare_queues.vcproj deleted file mode 100644 index 083474b9ef..0000000000 --- a/cpp/examples/direct/direct_declare_queues.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/direct/direct_direct_producer.vcproj b/cpp/examples/direct/direct_direct_producer.vcproj deleted file mode 100644 index f091fbf291..0000000000 --- a/cpp/examples/direct/direct_direct_producer.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/direct/direct_listener.vcproj b/cpp/examples/direct/direct_listener.vcproj deleted file mode 100644 index dce1d3ec28..0000000000 --- a/cpp/examples/direct/direct_listener.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/direct/direct_producer.cpp b/cpp/examples/direct/direct_producer.cpp deleted file mode 100644 index ecc9675189..0000000000 --- a/cpp/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. - * - * create_queues.cpp: - * - * Creates a queue named "message_queue" on a broker, binding the - * queue to the "amq.direct" exchange, using the routing key - * "routing_key". - * - * direct_producer.cpp (this program): - * - * Publishes to the "amq.direct" exchange, specifying the routing - * key "routing_key" - * - * listener.cpp - * - * Reads from the "message_queue" queue on the broker using a - * message listener. - * - */ - - -#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; - int count = argc>3 ? atoi(argv[3]) : 10; - - Connection connection; - 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 message; - message.getDeliveryProperties().setRoutingKey("routing_key"); - - // Now send some messages ... - - for (int i=0; i -#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; - - 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/cpp/examples/direct/verify b/cpp/examples/direct/verify deleted file mode 100644 index f598bacc1f..0000000000 --- a/cpp/examples/direct/verify +++ /dev/null @@ -1,23 +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. -# - - -# 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/cpp/examples/direct/verify.in b/cpp/examples/direct/verify.in deleted file mode 100644 index d1e95f1151..0000000000 --- a/cpp/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/cpp/examples/examples.sln b/cpp/examples/examples.sln index 8511fe3cce..6f96105d97 100644 --- a/cpp/examples/examples.sln +++ b/cpp/examples/examples.sln @@ -32,6 +32,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "messaging_drain", "messagin EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "messaging_spout", "messaging\messaging_spout.vcproj", "{D3115AC9-91C4-4D79-BCAC-DE837C70F1EA}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_console", "qmf-console\qmf-console_console.vcproj", "{490473E1-FECA-1BAD-2E13-3FFA2B8669C3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_ping", "qmf-console\qmf-console_ping.vcproj", "{C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_printevents", "qmf-console\qmf-console_printevents.vcproj", "{72C74624-FECA-1BAD-2E13-3FFA2B8669C3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_queuestats", "qmf-console\qmf-console_queuestats.vcproj", "{B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -88,6 +96,22 @@ Global {D3115AC9-91C4-4D79-BCAC-DE837C70F1EA}.Release|Win32.Build.0 = Release|Win32 {D3115AC9-91C4-4D79-BCAC-DE837C70F1EA}.Release|x64.ActiveCfg = Release|x64 {D3115AC9-91C4-4D79-BCAC-DE837C70F1EA}.Release|x64.Build.0 = Release|x64 + {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.ActiveCfg = Debug|Win32 + {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.Build.0 = Debug|Win32 + {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.ActiveCfg = Release|Win32 + {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.Build.0 = Release|Win32 + {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Debug|Win32.ActiveCfg = Debug|Win32 + {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Debug|Win32.Build.0 = Debug|Win32 + {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Release|Win32.ActiveCfg = Release|Win32 + {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Release|Win32.Build.0 = Release|Win32 + {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.ActiveCfg = Debug|Win32 + {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.Build.0 = Debug|Win32 + {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.ActiveCfg = Release|Win32 + {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.Build.0 = Release|Win32 + {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.ActiveCfg = Debug|Win32 + {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.Build.0 = Debug|Win32 + {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.ActiveCfg = Release|Win32 + {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/cpp/examples/failover/CMakeLists.txt b/cpp/examples/failover/CMakeLists.txt deleted file mode 100644 index 05db8fad51..0000000000 --- a/cpp/examples/failover/CMakeLists.txt +++ /dev/null @@ -1,22 +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. -# - -add_example(failover declare_queues) -add_example(failover resuming_receiver) -add_example(failover replaying_sender) diff --git a/cpp/examples/failover/Makefile.am b/cpp/examples/failover/Makefile.am deleted file mode 100644 index 48846fdf79..0000000000 --- a/cpp/examples/failover/Makefile.am +++ /dev/null @@ -1,47 +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. -# -examplesdir=$(pkgdatadir)/examples/failover - -MAKELDFLAGS=$(CLIENTFLAGS) -include $(top_srcdir)/examples/makedist.mk - -noinst_PROGRAMS=declare_queues resuming_receiver replaying_sender - -declare_queues_SOURCES=declare_queues.cpp -declare_queues_LDADD=$(CLIENT_LIB) - -resuming_receiver_SOURCES=resuming_receiver.cpp -resuming_receiver_LDADD=$(CLIENT_LIB) - -replaying_sender_SOURCES=replaying_sender.cpp -replaying_sender_LDADD=$(CLIENT_LIB) - -examples_DATA= \ - declare_queues.cpp \ - resuming_receiver.cpp \ - replaying_sender.cpp \ - $(MAKEDIST) - -# FIXME aconway 2008-10-10: add verify scripts. - -EXTRA_DIST= \ - CMakeLists.txt \ - failover_declare_queues.vcproj \ - failover_replaying_sender.vcproj \ - failover_resuming_receiver.vcproj diff --git a/cpp/examples/failover/declare_queues.cpp b/cpp/examples/failover/declare_queues.cpp deleted file mode 100644 index a677870c53..0000000000 --- a/cpp/examples/failover/declare_queues.cpp +++ /dev/null @@ -1,61 +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 std; - -int main(int argc, char ** argv) -{ - ConnectionSettings settings; - if (argc > 1) settings.host = argv[1]; - if (argc > 2) settings.port = atoi(argv[2]); - - FailoverManager connection(settings); - try { - bool complete = false; - while (!complete) { - Session session = connection.connect().newSession(); - try { - session.queueDeclare(arg::queue="message_queue"); - complete = true; - } catch (const qpid::TransportFailure&) {} - } - connection.close(); - return 0; - } catch (const std::exception& error) { - std::cout << "Failed:" << error.what() << std::endl; - return 1; - } - -} - - - - - diff --git a/cpp/examples/failover/failover_declare_queues.vcproj b/cpp/examples/failover/failover_declare_queues.vcproj deleted file mode 100644 index c87c72affd..0000000000 --- a/cpp/examples/failover/failover_declare_queues.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/failover/failover_replaying_sender.vcproj b/cpp/examples/failover/failover_replaying_sender.vcproj deleted file mode 100644 index 6d22fa6770..0000000000 --- a/cpp/examples/failover/failover_replaying_sender.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/failover/failover_resuming_receiver.vcproj b/cpp/examples/failover/failover_resuming_receiver.vcproj deleted file mode 100644 index ba5061e248..0000000000 --- a/cpp/examples/failover/failover_resuming_receiver.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/failover/replaying_sender.cpp b/cpp/examples/failover/replaying_sender.cpp deleted file mode 100644 index 22a7e1ebd3..0000000000 --- a/cpp/examples/failover/replaying_sender.cpp +++ /dev/null @@ -1,97 +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; -using namespace qpid::client; -using namespace qpid::framing; - -using namespace std; - -class Sender : public FailoverManager::Command -{ - public: - Sender(const std::string& queue, uint count); - void execute(AsyncSession& session, bool isRetry); - uint getSent(); - private: - MessageReplayTracker sender; - const uint count; - uint sent; - Message message; - -}; - -Sender::Sender(const std::string& queue, uint count_) : sender(10), count(count_), sent(0) -{ - message.getDeliveryProperties().setRoutingKey(queue); -} - -void Sender::execute(AsyncSession& session, bool isRetry) -{ - if (isRetry) sender.replay(session); - else sender.init(session); - while (sent < count) { - stringstream message_data; - message_data << ++sent; - message.setData(message_data.str()); - message.getHeaders().setInt("sn", sent); - sender.send(message); - if (count > 1000 && !(sent % 1000)) { - std::cout << "sent " << sent << " of " << count << std::endl; - } - } - message.setData("That's all, folks!"); - sender.send(message); -} - -uint Sender::getSent() -{ - return sent; -} - -int main(int argc, char ** argv) -{ - ConnectionSettings settings; - if (argc > 1) settings.host = argv[1]; - if (argc > 2) settings.port = atoi(argv[2]); - - FailoverManager connection(settings); - Sender sender("message_queue", argc > 3 ? atoi(argv[3]) : 1000); - try { - connection.execute(sender); - std::cout << "Sent " << sender.getSent() << " messages." << std::endl; - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << "Failed: " << error.what() << std::endl; - } - return 1; -} diff --git a/cpp/examples/failover/resuming_receiver.cpp b/cpp/examples/failover/resuming_receiver.cpp deleted file mode 100644 index d1886ce861..0000000000 --- a/cpp/examples/failover/resuming_receiver.cpp +++ /dev/null @@ -1,127 +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 - - -using namespace qpid; -using namespace qpid::client; -using namespace qpid::framing; - -using namespace std; - - -class Listener : public MessageListener, - public FailoverManager::Command, - public FailoverManager::ReconnectionStrategy -{ - public: - Listener(); - void received(Message& message); - void execute(AsyncSession& session, bool isRetry); - void check(); - void editUrlList(std::vector& urls); - private: - Subscription subscription; - uint count; - uint skipped; - uint lastSn; - bool gaps; -}; - -Listener::Listener() : count(0), skipped(0), lastSn(0), gaps(false) {} - -void Listener::received(Message & message) -{ - if (message.getData() == "That's all, folks!") { - std::cout << "Shutting down listener for " << message.getDestination() - << std::endl; - - std::cout << "Listener received " << count << " messages (" << skipped << " skipped)" << std::endl; - subscription.cancel(); - } else { - uint sn = message.getHeaders().getAsInt("sn"); - if (lastSn < sn) { - if (sn - lastSn > 1) { - std::cout << "Error: gap in sequence between " << lastSn << " and " << sn << std::endl; - gaps = true; - } - lastSn = sn; - ++count; - } else { - ++skipped; - } - } -} - -void Listener::check() -{ - if (gaps) throw Exception("Detected gaps in sequence; messages appear to have been lost."); -} - -void Listener::execute(AsyncSession& session, bool isRetry) -{ - if (isRetry) { - std::cout << "Resuming from " << count << std::endl; - } - SubscriptionManager subs(session); - subscription = subs.subscribe(*this, "message_queue"); - subs.run(); -} - -void Listener::editUrlList(std::vector& urls) -{ - /** - * A more realistic algorithm would be to search through the list - * for prefered hosts and ensure they come first in the list. - */ - if (urls.size() > 1) std::rotate(urls.begin(), urls.begin() + 1, urls.end()); -} - -int main(int argc, char ** argv) -{ - ConnectionSettings settings; - if (argc > 1) settings.host = argv[1]; - if (argc > 2) settings.port = atoi(argv[2]); - - Listener listener; - FailoverManager connection(settings, &listener); - - try { - connection.execute(listener); - connection.close(); - listener.check(); - std::cout << "Completed without error." << std::endl; - return 0; - } catch(const std::exception& error) { - std::cout << "Failure: " << error.what() << std::endl; - } - return 1; -} - - - diff --git a/cpp/examples/fanout/CMakeLists.txt b/cpp/examples/fanout/CMakeLists.txt deleted file mode 100644 index 3f89d67650..0000000000 --- a/cpp/examples/fanout/CMakeLists.txt +++ /dev/null @@ -1,21 +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. -# - -add_example(fanout fanout_producer) -add_example(fanout listener) diff --git a/cpp/examples/fanout/Makefile.am b/cpp/examples/fanout/Makefile.am deleted file mode 100644 index 6e2e821eae..0000000000 --- a/cpp/examples/fanout/Makefile.am +++ /dev/null @@ -1,42 +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. -# -examplesdir=$(pkgdatadir)/examples/fanout - -MAKELDFLAGS=$(CLIENTFLAGS) -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) \ - CMakeLists.txt \ - verify \ - verify.in \ - fanout_fanout_producer.vcproj \ - fanout_listener.vcproj diff --git a/cpp/examples/fanout/fanout_fanout_producer.vcproj b/cpp/examples/fanout/fanout_fanout_producer.vcproj deleted file mode 100644 index daff5f3cf0..0000000000 --- a/cpp/examples/fanout/fanout_fanout_producer.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/fanout/fanout_listener.vcproj b/cpp/examples/fanout/fanout_listener.vcproj deleted file mode 100644 index f0e91b7dc6..0000000000 --- a/cpp/examples/fanout/fanout_listener.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/fanout/fanout_producer.cpp b/cpp/examples/fanout/fanout_producer.cpp deleted file mode 100644 index decd4d314d..0000000000 --- a/cpp/examples/fanout/fanout_producer.cpp +++ /dev/null @@ -1,105 +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 two programs designed to be used - * together. - * - * fanout_producer.cpp (this program): - * - * Publishes messages to the "amq.fanout" exchange. - * - * listener.cpp - * - * Creates a private queue, binds it to the "amq.fanout" - * exchange, and reads messages from its queue as they - * arrive. Messages sent before the listener binds the queue are - * not received. - * - * Multiple listeners can run at the same time. - * - */ - - -#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; - 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/cpp/examples/fanout/listener.cpp b/cpp/examples/fanout/listener.cpp deleted file mode 100644 index cd3071c29a..0000000000 --- a/cpp/examples/fanout/listener.cpp +++ /dev/null @@ -1,125 +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 is one of two programs designed to be used - * together. - * - * fanout_producer.cpp - * - * Publishes messages to the "amq.fanout" exchange. - * - * listener.cpp (this program) - * - * Creates a private queue, binds it to the "amq.fanout" - * exchange, and reads messages from its queue as they - * arrive. Messages sent before the listener binds the queue are - * not received. - * - * Multiple listeners can run at the same time. - * - */ - - -#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; - 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/cpp/examples/fanout/verify b/cpp/examples/fanout/verify deleted file mode 100644 index 2eaadff56b..0000000000 --- a/cpp/examples/fanout/verify +++ /dev/null @@ -1,25 +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. -# - -# 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/cpp/examples/fanout/verify.in b/cpp/examples/fanout/verify.in deleted file mode 100644 index 8f8612ce67..0000000000 --- a/cpp/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/cpp/examples/messaging/drain.cpp b/cpp/examples/messaging/drain.cpp index 5c938e9742..563e5e5060 100644 --- a/cpp/examples/messaging/drain.cpp +++ b/cpp/examples/messaging/drain.cpp @@ -45,12 +45,12 @@ struct Options : OptionParser url("127.0.0.1"), timeout(0), forever(false), - count(1) + count(0) { add("broker,b", url, "url of broker to connect to"); add("timeout,t", timeout, "timeout in seconds to wait before exiting"); add("forever,f", forever, "ignore timeout and wait forever"); - add("connection-options", connectionOptions, "connection options string in the form {name1=value1, name2=value2}"); + add("connection-options", connectionOptions, "connection options string in the form {name1:value1, name2:value2}"); add("count,c", count, "number of messages to read before exiting"); } diff --git a/cpp/examples/messaging/server.cpp b/cpp/examples/messaging/server.cpp index ab72694c61..aa271d91f9 100644 --- a/cpp/examples/messaging/server.cpp +++ b/cpp/examples/messaging/server.cpp @@ -39,8 +39,8 @@ using std::string; int main(int argc, char** argv) { const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672"; - std::string connectionOptions = argc > 3 ? argv[3] : ""; - + std::string connectionOptions = argc > 2 ? argv[2] : ""; + Connection connection(url, connectionOptions); try { connection.open(); diff --git a/cpp/examples/messaging/spout.cpp b/cpp/examples/messaging/spout.cpp index 57b955c1de..cd11a7ad81 100644 --- a/cpp/examples/messaging/spout.cpp +++ b/cpp/examples/messaging/spout.cpp @@ -65,7 +65,7 @@ struct Options : OptionParser add("property,P", properties, "specify message property"); add("map,M", entries, "specify entry for map content"); add("content", content, "specify textual content"); - add("connection-options", connectionOptions, "connection options string in the form {name1=value1, name2=value2}"); + add("connection-options", connectionOptions, "connection options string in the form {name1:value1, name2:value2}"); } static bool nameval(const std::string& in, std::string& name, std::string& value) diff --git a/cpp/examples/old-examples.sln b/cpp/examples/old-examples.sln deleted file mode 100644 index 7f2fa3e8b0..0000000000 --- a/cpp/examples/old-examples.sln +++ /dev/null @@ -1,147 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -# -# -# 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 -# -# -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "direct_declare_queues", "direct\direct_declare_queues.vcproj", "{18165D4D-FECA-1BAD-4346-8C4DF2536AA5}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "direct_direct_producer", "direct\direct_direct_producer.vcproj", "{9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "direct_listener", "direct\direct_listener.vcproj", "{95CE1459-FECA-1BAD-4346-8C4DF2536AA5}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "failover_declare_queues", "failover\failover_declare_queues.vcproj", "{7817898E-FECA-1BAD-8026-8D997AD361D0}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "failover_replaying_sender", "failover\failover_replaying_sender.vcproj", "{085D6A66-FECA-1BAD-8026-8D997AD361D0}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "failover_resuming_receiver", "failover\failover_resuming_receiver.vcproj", "{B0DAF702-FECA-1BAD-8026-8D997AD361D0}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fanout_fanout_producer", "fanout\fanout_fanout_producer.vcproj", "{972AB76B-FECA-1BAD-8826-8C64F27AA1C5}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fanout_listener", "fanout\fanout_listener.vcproj", "{95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pub_sub_topic_listener", "pub-sub\pub-sub_topic_listener.vcproj", "{A415E66A-FECA-1BAD-A430-FD5330E23A2D}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pub_sub_topic_publisher", "pub-sub\pub-sub_topic_publisher.vcproj", "{05158653-FECA-1BAD-A430-FD5330E23A2D}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_console", "qmf-console\qmf-console_console.vcproj", "{490473E1-FECA-1BAD-2E13-3FFA2B8669C3}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_ping", "qmf-console\qmf-console_ping.vcproj", "{C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_printevents", "qmf-console\qmf-console_printevents.vcproj", "{72C74624-FECA-1BAD-2E13-3FFA2B8669C3}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qmf_console_queuestats", "qmf-console\qmf-console_queuestats.vcproj", "{B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "request_response_client", "request-response\request-response_client.vcproj", "{2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "request_response_server", "request-response\request-response_server.vcproj", "{46817425-FECA-1BAD-BD3A-8A467D0C5CCC}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tradedemo_declare_queues", "tradedemo\tradedemo_declare_queues.vcproj", "{9057502D-FECA-1BAD-23CE-CD4095BD3C8B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tradedemo_topic_listener", "tradedemo\tradedemo_topic_listener.vcproj", "{5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tradedemo_topic_publisher", "tradedemo\tradedemo_topic_publisher.vcproj", "{E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.ActiveCfg = Debug|Win32 - {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.Build.0 = Debug|Win32 - {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.ActiveCfg = Release|Win32 - {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.Build.0 = Release|Win32 - {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.ActiveCfg = Debug|Win32 - {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.Build.0 = Debug|Win32 - {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.ActiveCfg = Release|Win32 - {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.Build.0 = Release|Win32 - {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.ActiveCfg = Debug|Win32 - {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.Build.0 = Debug|Win32 - {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.ActiveCfg = Release|Win32 - {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.Build.0 = Release|Win32 - {7817898E-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.ActiveCfg = Debug|Win32 - {7817898E-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.Build.0 = Debug|Win32 - {7817898E-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.ActiveCfg = Release|Win32 - {7817898E-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.Build.0 = Release|Win32 - {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.ActiveCfg = Debug|Win32 - {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.Build.0 = Debug|Win32 - {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.ActiveCfg = Release|Win32 - {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.Build.0 = Release|Win32 - {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.ActiveCfg = Debug|Win32 - {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.Build.0 = Debug|Win32 - {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.ActiveCfg = Release|Win32 - {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.Build.0 = Release|Win32 - {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.ActiveCfg = Debug|Win32 - {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.Build.0 = Debug|Win32 - {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.ActiveCfg = Release|Win32 - {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.Build.0 = Release|Win32 - {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.ActiveCfg = Debug|Win32 - {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.Build.0 = Debug|Win32 - {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.ActiveCfg = Release|Win32 - {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.Build.0 = Release|Win32 - {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.ActiveCfg = Debug|Win32 - {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.Build.0 = Debug|Win32 - {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.ActiveCfg = Release|Win32 - {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.Build.0 = Release|Win32 - {05158653-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.ActiveCfg = Debug|Win32 - {05158653-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.Build.0 = Debug|Win32 - {05158653-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.ActiveCfg = Release|Win32 - {05158653-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.Build.0 = Release|Win32 - {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.ActiveCfg = Debug|Win32 - {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.Build.0 = Debug|Win32 - {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.ActiveCfg = Release|Win32 - {490473E1-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.Build.0 = Release|Win32 - {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Debug|Win32.ActiveCfg = Debug|Win32 - {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Debug|Win32.Build.0 = Debug|Win32 - {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Release|Win32.ActiveCfg = Release|Win32 - {C1FFDE95-3442-49AE-9985-7EEE3D45B4A3}.Release|Win32.Build.0 = Release|Win32 - {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.ActiveCfg = Debug|Win32 - {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.Build.0 = Debug|Win32 - {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.ActiveCfg = Release|Win32 - {72C74624-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.Build.0 = Release|Win32 - {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.ActiveCfg = Debug|Win32 - {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Debug|Win32.Build.0 = Debug|Win32 - {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.ActiveCfg = Release|Win32 - {B21825EA-FECA-1BAD-2E13-3FFA2B8669C3}.Release|Win32.Build.0 = Release|Win32 - {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.ActiveCfg = Debug|Win32 - {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.Build.0 = Debug|Win32 - {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.ActiveCfg = Release|Win32 - {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.Build.0 = Release|Win32 - {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.ActiveCfg = Debug|Win32 - {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.Build.0 = Debug|Win32 - {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.ActiveCfg = Release|Win32 - {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.Build.0 = Release|Win32 - {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.ActiveCfg = Debug|Win32 - {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.Build.0 = Debug|Win32 - {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.ActiveCfg = Release|Win32 - {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.Build.0 = Release|Win32 - {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.ActiveCfg = Debug|Win32 - {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.Build.0 = Debug|Win32 - {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.ActiveCfg = Release|Win32 - {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.Build.0 = Release|Win32 - {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.ActiveCfg = Debug|Win32 - {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.Build.0 = Debug|Win32 - {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.ActiveCfg = Release|Win32 - {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/cpp/examples/old_api/CMakeLists.txt b/cpp/examples/old_api/CMakeLists.txt new file mode 100644 index 0000000000..701f9be860 --- /dev/null +++ b/cpp/examples/old_api/CMakeLists.txt @@ -0,0 +1,25 @@ +# +# 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. +# +add_subdirectory(direct) +add_subdirectory(failover) +add_subdirectory(fanout) +add_subdirectory(pub-sub) +add_subdirectory(request-response) +add_subdirectory(tradedemo) +add_subdirectory(xml-exchange) diff --git a/cpp/examples/old_api/Makefile.am b/cpp/examples/old_api/Makefile.am new file mode 100644 index 0000000000..04216ffa97 --- /dev/null +++ b/cpp/examples/old_api/Makefile.am @@ -0,0 +1,48 @@ +# +# 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. +# +SUBDIRS = direct pub-sub fanout request-response failover tradedemo +if HAVE_XML + SUBDIRS += xml-exchange + broker_args = "--no-module-dir --data-dir \"\" --auth no --load-module $(top_builddir)/src/.libs/xml.so" +endif +if !HAVE_XML + exclude_examples_regexp="xml" # Exclude XML examples. + broker_args = "--no-module-dir --data-dir \"\" --auth no" +endif + +MAKEDIST=.libs/Makefile + +$(MAKEDIST): Makefile + mkdir -p .libs + @(echo 'all clean:' ; \ + echo ' for d in $(SUBDIRS) ; do $$(MAKE) -C $$$$d $$@ ; done' ; \ + ) > $(MAKEDIST) + +examplesdir=$(pkgdatadir)/examples/old_api +dist_examples_DATA = $(MAKEDIST) +EXTRA_DIST = README.verify verify verify_all CMakeLists.txt + +# For older versions of automake +abs_top_srcdir = @abs_top_srcdir@ +abs_top_builddir = @abs_top_builddir@ + +# Verify the examples in the buid tree. +check-local: + $(srcdir)/verify_all $(abs_top_srcdir)/.. $(abs_top_builddir) $(broker_args) $(exclude_examples_regexp) + diff --git a/cpp/examples/old_api/README.verify b/cpp/examples/old_api/README.verify new file mode 100644 index 0000000000..e1370764c9 --- /dev/null +++ b/cpp/examples/old_api/README.verify @@ -0,0 +1,42 @@ +# +# 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. +# += Qpid C++ Examples = + +For more information read examples/README. + +== The Verify All Script == + +The verify_all script will run each C++ example and compare its output +against what is expected. + +=== Arguments === + +The verify_all script expects the path to Qpid trunk as an argument. + +== 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/cpp/examples/old_api/direct/CMakeLists.txt b/cpp/examples/old_api/direct/CMakeLists.txt new file mode 100644 index 0000000000..2ec1b2b813 --- /dev/null +++ b/cpp/examples/old_api/direct/CMakeLists.txt @@ -0,0 +1,22 @@ +# +# 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. +# + +add_example(direct declare_queues) +add_example(direct direct_producer) +add_example(direct listener) diff --git a/cpp/examples/old_api/direct/Makefile.am b/cpp/examples/old_api/direct/Makefile.am new file mode 100644 index 0000000000..24f783fcc7 --- /dev/null +++ b/cpp/examples/old_api/direct/Makefile.am @@ -0,0 +1,47 @@ +# +# 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. +# +examplesdir=$(pkgdatadir)/examples/old_api/direct + +MAKELDFLAGS=$(CLIENTFLAGS) +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) \ + CMakeLists.txt \ + verify \ + verify.in \ + direct_declare_queues.vcproj \ + direct_direct_producer.vcproj \ + direct_listener.vcproj diff --git a/cpp/examples/old_api/direct/declare_queues.cpp b/cpp/examples/old_api/direct/declare_queues.cpp new file mode 100644 index 0000000000..9a51d1982b --- /dev/null +++ b/cpp/examples/old_api/direct/declare_queues.cpp @@ -0,0 +1,85 @@ +/* + * + * 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. + * + * declare_queues.cpp: (this program): + * + * Creates a queue named "message_queue" on a broker, binding the + * queue to the "amq.direct" exchange, using the routing key + * "routing_key". + * + * direct_producer.cpp + * + * Publishes to the "amq.direct" exchange, specifying the routing + * key "routing_key" + * + * listener.cpp + * + * Reads from the "message_queue" queue on the broker using a + * message listener. + * + */ + +#include +#include + + +using namespace qpid::client; +using namespace qpid::framing; + + +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/cpp/examples/old_api/direct/direct_declare_queues.vcproj b/cpp/examples/old_api/direct/direct_declare_queues.vcproj new file mode 100644 index 0000000000..083474b9ef --- /dev/null +++ b/cpp/examples/old_api/direct/direct_declare_queues.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/direct/direct_direct_producer.vcproj b/cpp/examples/old_api/direct/direct_direct_producer.vcproj new file mode 100644 index 0000000000..f091fbf291 --- /dev/null +++ b/cpp/examples/old_api/direct/direct_direct_producer.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/direct/direct_listener.vcproj b/cpp/examples/old_api/direct/direct_listener.vcproj new file mode 100644 index 0000000000..dce1d3ec28 --- /dev/null +++ b/cpp/examples/old_api/direct/direct_listener.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/direct/direct_producer.cpp b/cpp/examples/old_api/direct/direct_producer.cpp new file mode 100644 index 0000000000..ecc9675189 --- /dev/null +++ b/cpp/examples/old_api/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. + * + * create_queues.cpp: + * + * Creates a queue named "message_queue" on a broker, binding the + * queue to the "amq.direct" exchange, using the routing key + * "routing_key". + * + * direct_producer.cpp (this program): + * + * Publishes to the "amq.direct" exchange, specifying the routing + * key "routing_key" + * + * listener.cpp + * + * Reads from the "message_queue" queue on the broker using a + * message listener. + * + */ + + +#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; + int count = argc>3 ? atoi(argv[3]) : 10; + + Connection connection; + 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 message; + message.getDeliveryProperties().setRoutingKey("routing_key"); + + // Now send some messages ... + + for (int i=0; i +#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; + + 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/cpp/examples/old_api/direct/verify b/cpp/examples/old_api/direct/verify new file mode 100644 index 0000000000..f598bacc1f --- /dev/null +++ b/cpp/examples/old_api/direct/verify @@ -0,0 +1,23 @@ +# +# 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. +# + + +# 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/cpp/examples/old_api/direct/verify.in b/cpp/examples/old_api/direct/verify.in new file mode 100644 index 0000000000..d1e95f1151 --- /dev/null +++ b/cpp/examples/old_api/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/cpp/examples/old_api/failover/CMakeLists.txt b/cpp/examples/old_api/failover/CMakeLists.txt new file mode 100644 index 0000000000..05db8fad51 --- /dev/null +++ b/cpp/examples/old_api/failover/CMakeLists.txt @@ -0,0 +1,22 @@ +# +# 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. +# + +add_example(failover declare_queues) +add_example(failover resuming_receiver) +add_example(failover replaying_sender) diff --git a/cpp/examples/old_api/failover/Makefile.am b/cpp/examples/old_api/failover/Makefile.am new file mode 100644 index 0000000000..8b1da80f2c --- /dev/null +++ b/cpp/examples/old_api/failover/Makefile.am @@ -0,0 +1,47 @@ +# +# 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. +# +examplesdir=$(pkgdatadir)/examples/old_api/failover + +MAKELDFLAGS=$(CLIENTFLAGS) +include $(top_srcdir)/examples/makedist.mk + +noinst_PROGRAMS=declare_queues resuming_receiver replaying_sender + +declare_queues_SOURCES=declare_queues.cpp +declare_queues_LDADD=$(CLIENT_LIB) + +resuming_receiver_SOURCES=resuming_receiver.cpp +resuming_receiver_LDADD=$(CLIENT_LIB) + +replaying_sender_SOURCES=replaying_sender.cpp +replaying_sender_LDADD=$(CLIENT_LIB) + +examples_DATA= \ + declare_queues.cpp \ + resuming_receiver.cpp \ + replaying_sender.cpp \ + $(MAKEDIST) + +# FIXME aconway 2008-10-10: add verify scripts. + +EXTRA_DIST= \ + CMakeLists.txt \ + failover_declare_queues.vcproj \ + failover_replaying_sender.vcproj \ + failover_resuming_receiver.vcproj diff --git a/cpp/examples/old_api/failover/declare_queues.cpp b/cpp/examples/old_api/failover/declare_queues.cpp new file mode 100644 index 0000000000..a677870c53 --- /dev/null +++ b/cpp/examples/old_api/failover/declare_queues.cpp @@ -0,0 +1,61 @@ +/* + * + * 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 std; + +int main(int argc, char ** argv) +{ + ConnectionSettings settings; + if (argc > 1) settings.host = argv[1]; + if (argc > 2) settings.port = atoi(argv[2]); + + FailoverManager connection(settings); + try { + bool complete = false; + while (!complete) { + Session session = connection.connect().newSession(); + try { + session.queueDeclare(arg::queue="message_queue"); + complete = true; + } catch (const qpid::TransportFailure&) {} + } + connection.close(); + return 0; + } catch (const std::exception& error) { + std::cout << "Failed:" << error.what() << std::endl; + return 1; + } + +} + + + + + diff --git a/cpp/examples/old_api/failover/failover_declare_queues.vcproj b/cpp/examples/old_api/failover/failover_declare_queues.vcproj new file mode 100644 index 0000000000..c87c72affd --- /dev/null +++ b/cpp/examples/old_api/failover/failover_declare_queues.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/failover/failover_replaying_sender.vcproj b/cpp/examples/old_api/failover/failover_replaying_sender.vcproj new file mode 100644 index 0000000000..6d22fa6770 --- /dev/null +++ b/cpp/examples/old_api/failover/failover_replaying_sender.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/failover/failover_resuming_receiver.vcproj b/cpp/examples/old_api/failover/failover_resuming_receiver.vcproj new file mode 100644 index 0000000000..ba5061e248 --- /dev/null +++ b/cpp/examples/old_api/failover/failover_resuming_receiver.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/failover/replaying_sender.cpp b/cpp/examples/old_api/failover/replaying_sender.cpp new file mode 100644 index 0000000000..22a7e1ebd3 --- /dev/null +++ b/cpp/examples/old_api/failover/replaying_sender.cpp @@ -0,0 +1,97 @@ +/* + * + * 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; +using namespace qpid::client; +using namespace qpid::framing; + +using namespace std; + +class Sender : public FailoverManager::Command +{ + public: + Sender(const std::string& queue, uint count); + void execute(AsyncSession& session, bool isRetry); + uint getSent(); + private: + MessageReplayTracker sender; + const uint count; + uint sent; + Message message; + +}; + +Sender::Sender(const std::string& queue, uint count_) : sender(10), count(count_), sent(0) +{ + message.getDeliveryProperties().setRoutingKey(queue); +} + +void Sender::execute(AsyncSession& session, bool isRetry) +{ + if (isRetry) sender.replay(session); + else sender.init(session); + while (sent < count) { + stringstream message_data; + message_data << ++sent; + message.setData(message_data.str()); + message.getHeaders().setInt("sn", sent); + sender.send(message); + if (count > 1000 && !(sent % 1000)) { + std::cout << "sent " << sent << " of " << count << std::endl; + } + } + message.setData("That's all, folks!"); + sender.send(message); +} + +uint Sender::getSent() +{ + return sent; +} + +int main(int argc, char ** argv) +{ + ConnectionSettings settings; + if (argc > 1) settings.host = argv[1]; + if (argc > 2) settings.port = atoi(argv[2]); + + FailoverManager connection(settings); + Sender sender("message_queue", argc > 3 ? atoi(argv[3]) : 1000); + try { + connection.execute(sender); + std::cout << "Sent " << sender.getSent() << " messages." << std::endl; + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << "Failed: " << error.what() << std::endl; + } + return 1; +} diff --git a/cpp/examples/old_api/failover/resuming_receiver.cpp b/cpp/examples/old_api/failover/resuming_receiver.cpp new file mode 100644 index 0000000000..d1886ce861 --- /dev/null +++ b/cpp/examples/old_api/failover/resuming_receiver.cpp @@ -0,0 +1,127 @@ +/* + * + * 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 + + +using namespace qpid; +using namespace qpid::client; +using namespace qpid::framing; + +using namespace std; + + +class Listener : public MessageListener, + public FailoverManager::Command, + public FailoverManager::ReconnectionStrategy +{ + public: + Listener(); + void received(Message& message); + void execute(AsyncSession& session, bool isRetry); + void check(); + void editUrlList(std::vector& urls); + private: + Subscription subscription; + uint count; + uint skipped; + uint lastSn; + bool gaps; +}; + +Listener::Listener() : count(0), skipped(0), lastSn(0), gaps(false) {} + +void Listener::received(Message & message) +{ + if (message.getData() == "That's all, folks!") { + std::cout << "Shutting down listener for " << message.getDestination() + << std::endl; + + std::cout << "Listener received " << count << " messages (" << skipped << " skipped)" << std::endl; + subscription.cancel(); + } else { + uint sn = message.getHeaders().getAsInt("sn"); + if (lastSn < sn) { + if (sn - lastSn > 1) { + std::cout << "Error: gap in sequence between " << lastSn << " and " << sn << std::endl; + gaps = true; + } + lastSn = sn; + ++count; + } else { + ++skipped; + } + } +} + +void Listener::check() +{ + if (gaps) throw Exception("Detected gaps in sequence; messages appear to have been lost."); +} + +void Listener::execute(AsyncSession& session, bool isRetry) +{ + if (isRetry) { + std::cout << "Resuming from " << count << std::endl; + } + SubscriptionManager subs(session); + subscription = subs.subscribe(*this, "message_queue"); + subs.run(); +} + +void Listener::editUrlList(std::vector& urls) +{ + /** + * A more realistic algorithm would be to search through the list + * for prefered hosts and ensure they come first in the list. + */ + if (urls.size() > 1) std::rotate(urls.begin(), urls.begin() + 1, urls.end()); +} + +int main(int argc, char ** argv) +{ + ConnectionSettings settings; + if (argc > 1) settings.host = argv[1]; + if (argc > 2) settings.port = atoi(argv[2]); + + Listener listener; + FailoverManager connection(settings, &listener); + + try { + connection.execute(listener); + connection.close(); + listener.check(); + std::cout << "Completed without error." << std::endl; + return 0; + } catch(const std::exception& error) { + std::cout << "Failure: " << error.what() << std::endl; + } + return 1; +} + + + diff --git a/cpp/examples/old_api/fanout/CMakeLists.txt b/cpp/examples/old_api/fanout/CMakeLists.txt new file mode 100644 index 0000000000..3f89d67650 --- /dev/null +++ b/cpp/examples/old_api/fanout/CMakeLists.txt @@ -0,0 +1,21 @@ +# +# 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. +# + +add_example(fanout fanout_producer) +add_example(fanout listener) diff --git a/cpp/examples/old_api/fanout/Makefile.am b/cpp/examples/old_api/fanout/Makefile.am new file mode 100644 index 0000000000..3ab43b0279 --- /dev/null +++ b/cpp/examples/old_api/fanout/Makefile.am @@ -0,0 +1,42 @@ +# +# 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. +# +examplesdir=$(pkgdatadir)/examples/old_api/fanout + +MAKELDFLAGS=$(CLIENTFLAGS) +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) \ + CMakeLists.txt \ + verify \ + verify.in \ + fanout_fanout_producer.vcproj \ + fanout_listener.vcproj diff --git a/cpp/examples/old_api/fanout/fanout_fanout_producer.vcproj b/cpp/examples/old_api/fanout/fanout_fanout_producer.vcproj new file mode 100644 index 0000000000..daff5f3cf0 --- /dev/null +++ b/cpp/examples/old_api/fanout/fanout_fanout_producer.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/fanout/fanout_listener.vcproj b/cpp/examples/old_api/fanout/fanout_listener.vcproj new file mode 100644 index 0000000000..f0e91b7dc6 --- /dev/null +++ b/cpp/examples/old_api/fanout/fanout_listener.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/fanout/fanout_producer.cpp b/cpp/examples/old_api/fanout/fanout_producer.cpp new file mode 100644 index 0000000000..decd4d314d --- /dev/null +++ b/cpp/examples/old_api/fanout/fanout_producer.cpp @@ -0,0 +1,105 @@ +/* + * + * 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 two programs designed to be used + * together. + * + * fanout_producer.cpp (this program): + * + * Publishes messages to the "amq.fanout" exchange. + * + * listener.cpp + * + * Creates a private queue, binds it to the "amq.fanout" + * exchange, and reads messages from its queue as they + * arrive. Messages sent before the listener binds the queue are + * not received. + * + * Multiple listeners can run at the same time. + * + */ + + +#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; + 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/cpp/examples/old_api/fanout/listener.cpp b/cpp/examples/old_api/fanout/listener.cpp new file mode 100644 index 0000000000..cd3071c29a --- /dev/null +++ b/cpp/examples/old_api/fanout/listener.cpp @@ -0,0 +1,125 @@ +/* + * + * 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 is one of two programs designed to be used + * together. + * + * fanout_producer.cpp + * + * Publishes messages to the "amq.fanout" exchange. + * + * listener.cpp (this program) + * + * Creates a private queue, binds it to the "amq.fanout" + * exchange, and reads messages from its queue as they + * arrive. Messages sent before the listener binds the queue are + * not received. + * + * Multiple listeners can run at the same time. + * + */ + + +#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; + 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/cpp/examples/old_api/fanout/verify b/cpp/examples/old_api/fanout/verify new file mode 100644 index 0000000000..2eaadff56b --- /dev/null +++ b/cpp/examples/old_api/fanout/verify @@ -0,0 +1,25 @@ +# +# 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. +# + +# 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/cpp/examples/old_api/fanout/verify.in b/cpp/examples/old_api/fanout/verify.in new file mode 100644 index 0000000000..8f8612ce67 --- /dev/null +++ b/cpp/examples/old_api/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/cpp/examples/old_api/old-examples.sln b/cpp/examples/old_api/old-examples.sln new file mode 100644 index 0000000000..e6ec9a0d66 --- /dev/null +++ b/cpp/examples/old_api/old-examples.sln @@ -0,0 +1,123 @@ +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +# +# +# 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 +# +# +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "direct_declare_queues", "direct\direct_declare_queues.vcproj", "{18165D4D-FECA-1BAD-4346-8C4DF2536AA5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "direct_direct_producer", "direct\direct_direct_producer.vcproj", "{9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "direct_listener", "direct\direct_listener.vcproj", "{95CE1459-FECA-1BAD-4346-8C4DF2536AA5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "failover_declare_queues", "failover\failover_declare_queues.vcproj", "{7817898E-FECA-1BAD-8026-8D997AD361D0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "failover_replaying_sender", "failover\failover_replaying_sender.vcproj", "{085D6A66-FECA-1BAD-8026-8D997AD361D0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "failover_resuming_receiver", "failover\failover_resuming_receiver.vcproj", "{B0DAF702-FECA-1BAD-8026-8D997AD361D0}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fanout_fanout_producer", "fanout\fanout_fanout_producer.vcproj", "{972AB76B-FECA-1BAD-8826-8C64F27AA1C5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fanout_listener", "fanout\fanout_listener.vcproj", "{95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pub_sub_topic_listener", "pub-sub\pub-sub_topic_listener.vcproj", "{A415E66A-FECA-1BAD-A430-FD5330E23A2D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pub_sub_topic_publisher", "pub-sub\pub-sub_topic_publisher.vcproj", "{05158653-FECA-1BAD-A430-FD5330E23A2D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "request_response_client", "request-response\request-response_client.vcproj", "{2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "request_response_server", "request-response\request-response_server.vcproj", "{46817425-FECA-1BAD-BD3A-8A467D0C5CCC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tradedemo_declare_queues", "tradedemo\tradedemo_declare_queues.vcproj", "{9057502D-FECA-1BAD-23CE-CD4095BD3C8B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tradedemo_topic_listener", "tradedemo\tradedemo_topic_listener.vcproj", "{5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tradedemo_topic_publisher", "tradedemo\tradedemo_topic_publisher.vcproj", "{E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.ActiveCfg = Debug|Win32 + {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.Build.0 = Debug|Win32 + {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.ActiveCfg = Release|Win32 + {18165D4D-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.Build.0 = Release|Win32 + {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.ActiveCfg = Debug|Win32 + {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.Build.0 = Debug|Win32 + {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.ActiveCfg = Release|Win32 + {9701E0BD-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.Build.0 = Release|Win32 + {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.ActiveCfg = Debug|Win32 + {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Debug|Win32.Build.0 = Debug|Win32 + {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.ActiveCfg = Release|Win32 + {95CE1459-FECA-1BAD-4346-8C4DF2536AA5}.Release|Win32.Build.0 = Release|Win32 + {7817898E-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.ActiveCfg = Debug|Win32 + {7817898E-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.Build.0 = Debug|Win32 + {7817898E-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.ActiveCfg = Release|Win32 + {7817898E-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.Build.0 = Release|Win32 + {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.ActiveCfg = Debug|Win32 + {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.Build.0 = Debug|Win32 + {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.ActiveCfg = Release|Win32 + {085D6A66-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.Build.0 = Release|Win32 + {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.ActiveCfg = Debug|Win32 + {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Debug|Win32.Build.0 = Debug|Win32 + {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.ActiveCfg = Release|Win32 + {B0DAF702-FECA-1BAD-8026-8D997AD361D0}.Release|Win32.Build.0 = Release|Win32 + {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.ActiveCfg = Debug|Win32 + {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.Build.0 = Debug|Win32 + {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.ActiveCfg = Release|Win32 + {972AB76B-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.Build.0 = Release|Win32 + {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.ActiveCfg = Debug|Win32 + {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Debug|Win32.Build.0 = Debug|Win32 + {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.ActiveCfg = Release|Win32 + {95E7DF39-FECA-1BAD-8826-8C64F27AA1C5}.Release|Win32.Build.0 = Release|Win32 + {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.ActiveCfg = Debug|Win32 + {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.Build.0 = Debug|Win32 + {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.ActiveCfg = Release|Win32 + {A415E66A-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.Build.0 = Release|Win32 + {05158653-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.ActiveCfg = Debug|Win32 + {05158653-FECA-1BAD-A430-FD5330E23A2D}.Debug|Win32.Build.0 = Debug|Win32 + {05158653-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.ActiveCfg = Release|Win32 + {05158653-FECA-1BAD-A430-FD5330E23A2D}.Release|Win32.Build.0 = Release|Win32 + {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.ActiveCfg = Debug|Win32 + {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.Build.0 = Debug|Win32 + {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.ActiveCfg = Release|Win32 + {2691FE1E-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.Build.0 = Release|Win32 + {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.ActiveCfg = Debug|Win32 + {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Debug|Win32.Build.0 = Debug|Win32 + {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.ActiveCfg = Release|Win32 + {46817425-FECA-1BAD-BD3A-8A467D0C5CCC}.Release|Win32.Build.0 = Release|Win32 + {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.ActiveCfg = Debug|Win32 + {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.Build.0 = Debug|Win32 + {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.ActiveCfg = Release|Win32 + {9057502D-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.Build.0 = Release|Win32 + {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.ActiveCfg = Debug|Win32 + {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.Build.0 = Debug|Win32 + {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.ActiveCfg = Release|Win32 + {5A25F2CD-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.Build.0 = Release|Win32 + {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.ActiveCfg = Debug|Win32 + {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Debug|Win32.Build.0 = Debug|Win32 + {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.ActiveCfg = Release|Win32 + {E614CC2C-FECA-1BAD-23CE-CD4095BD3C8B}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/cpp/examples/old_api/pub-sub/CMakeLists.txt b/cpp/examples/old_api/pub-sub/CMakeLists.txt new file mode 100644 index 0000000000..961de06d5a --- /dev/null +++ b/cpp/examples/old_api/pub-sub/CMakeLists.txt @@ -0,0 +1,21 @@ +# +# 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. +# + +add_example(pub-sub topic_listener) +add_example(pub-sub topic_publisher) diff --git a/cpp/examples/old_api/pub-sub/Makefile.am b/cpp/examples/old_api/pub-sub/Makefile.am new file mode 100644 index 0000000000..8f42ee0211 --- /dev/null +++ b/cpp/examples/old_api/pub-sub/Makefile.am @@ -0,0 +1,43 @@ +# +# 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. +# +examplesdir=$(pkgdatadir)/examples/old_api/pub-sub + +MAKELDFLAGS=$(CLIENTFLAGS) +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) \ + CMakeLists.txt \ + verify \ + verify.in \ + pub-sub_topic_listener.vcproj \ + pub-sub_topic_publisher.vcproj diff --git a/cpp/examples/old_api/pub-sub/pub-sub_topic_listener.vcproj b/cpp/examples/old_api/pub-sub/pub-sub_topic_listener.vcproj new file mode 100644 index 0000000000..aa0b3bcaa3 --- /dev/null +++ b/cpp/examples/old_api/pub-sub/pub-sub_topic_listener.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/pub-sub/pub-sub_topic_publisher.vcproj b/cpp/examples/old_api/pub-sub/pub-sub_topic_publisher.vcproj new file mode 100644 index 0000000000..76e51df4df --- /dev/null +++ b/cpp/examples/old_api/pub-sub/pub-sub_topic_publisher.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/pub-sub/topic_listener.cpp b/cpp/examples/old_api/pub-sub/topic_listener.cpp new file mode 100644 index 0000000000..d38a806303 --- /dev/null +++ b/cpp/examples/old_api/pub-sub/topic_listener.cpp @@ -0,0 +1,173 @@ +/* + * + * 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 two programs designed to be used + * together. These programs implement a publish-subscribe example + * using the "amq.topic" exchange. + * + * topic_publisher.cpp + * + * Sends messages to the "amq.topic" exchange, using the + * multipart routing keys "usa.news", "usa.weather", + * "europe.news", and "europe.weather". + * + * topic_listener.cpp (this program) + * + * Creates private queues for "news", "weather", "usa", and + * "europe", binding them to the amq.topic exchange using + * bindings that match the corresponding parts of the multipart + * routing keys. + * + * Multiple listeners can be run at the same time. + * + */ + +#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 exchange, 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 exchange, 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=exchange, arg::queue=queue, arg::bindingKey=routing_key); + session.exchangeBind(arg::exchange=exchange, 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; + std::string exchange = argc>3 ? argv[3] : "amq.topic"; + 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", exchange, "usa.#"); + listener.prepareQueue("europe", exchange, "europe.#"); + listener.prepareQueue("news", exchange, "#.news"); + listener.prepareQueue("weather", exchange, "#.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/cpp/examples/old_api/pub-sub/topic_publisher.cpp b/cpp/examples/old_api/pub-sub/topic_publisher.cpp new file mode 100644 index 0000000000..aed5f8f033 --- /dev/null +++ b/cpp/examples/old_api/pub-sub/topic_publisher.cpp @@ -0,0 +1,129 @@ +/* + * + * 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 two programs designed to be used + * together. These programs implement a publish-subscribe example + * using the "amq.topic" exchange. + * + * topic_publisher.cpp (this program) + * + * Sends messages to the "amq.topic" exchange, using the + * multipart routing keys "usa.news", "usa.weather", + * "europe.news", and "europe.weather". + * + * topic_listener.cpp + * + * Creates private queues for "news", "weather", "usa", and + * "europe", binding them to the amq.topic exchange using + * bindings that match the corresponding parts of the multipart + * routing keys. + * + * Multiple listeners can be run at the same time. + * + */ + + +#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; + 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/cpp/examples/old_api/pub-sub/verify b/cpp/examples/old_api/pub-sub/verify new file mode 100644 index 0000000000..528d2f401e --- /dev/null +++ b/cpp/examples/old_api/pub-sub/verify @@ -0,0 +1,23 @@ +# +# 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. +# + +# 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/cpp/examples/old_api/pub-sub/verify.in b/cpp/examples/old_api/pub-sub/verify.in new file mode 100644 index 0000000000..6413c5c788 --- /dev/null +++ b/cpp/examples/old_api/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/cpp/examples/old_api/request-response/CMakeLists.txt b/cpp/examples/old_api/request-response/CMakeLists.txt new file mode 100644 index 0000000000..873a0cfa86 --- /dev/null +++ b/cpp/examples/old_api/request-response/CMakeLists.txt @@ -0,0 +1,21 @@ +# +# 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. +# + +add_example(request-response client) +add_example(request-response server) diff --git a/cpp/examples/old_api/request-response/Makefile.am b/cpp/examples/old_api/request-response/Makefile.am new file mode 100644 index 0000000000..f48762da51 --- /dev/null +++ b/cpp/examples/old_api/request-response/Makefile.am @@ -0,0 +1,43 @@ +# +# 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. +# +examplesdir=$(pkgdatadir)/examples/old_api/request-response + +MAKELDFLAGS=$(CLIENTFLAGS) +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) \ + CMakeLists.txt \ + verify \ + verify.in \ + request-response_client.vcproj \ + request-response_server.vcproj diff --git a/cpp/examples/old_api/request-response/client.cpp b/cpp/examples/old_api/request-response/client.cpp new file mode 100644 index 0000000000..679d1c5fc2 --- /dev/null +++ b/cpp/examples/old_api/request-response/client.cpp @@ -0,0 +1,163 @@ +/* + * + * 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) + * + * A client application that sends messages to the "amq.direct" + * exchange, using the routing key "request" to route messages to + * the server. + * + * Each instance of the client creates its own private response + * queue, binding it to the "amq.direct" exchange using it's + * session identifier as the routing key, and places its session + * identifier in the "reply-to" property of each message it sends. + * + * + * server.cpp + * + * A service that accepts messages from a request queue, converts + * their content to upper case, and sends the result to the + * original sender. + * + * This program creates a request queue, binds it to "amq.direct" + * using the routing key "request", then receives messages from + * the request queue. Each incoming message is converted to upper + * case, then sent to the "amq.direct" exchange using the + * request's reply-to property as the routing key for the + * response. + * + * + */ + +#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; + 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()); + } +} + + + +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 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. + + Message request; + 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]); + 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/cpp/examples/old_api/request-response/request-response_client.vcproj b/cpp/examples/old_api/request-response/request-response_client.vcproj new file mode 100644 index 0000000000..5f9eadde36 --- /dev/null +++ b/cpp/examples/old_api/request-response/request-response_client.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/request-response/request-response_server.vcproj b/cpp/examples/old_api/request-response/request-response_server.vcproj new file mode 100644 index 0000000000..54352b9f46 --- /dev/null +++ b/cpp/examples/old_api/request-response/request-response_server.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/request-response/server.cpp b/cpp/examples/old_api/request-response/server.cpp new file mode 100644 index 0000000000..65a4717b35 --- /dev/null +++ b/cpp/examples/old_api/request-response/server.cpp @@ -0,0 +1,161 @@ +/* + * + * 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 + * + * A client application that sends messages to the "amq.direct" + * exchange, using the routing key "request" to route messages to + * the server. + * + * Each instance of the client creates its own private response + * queue, binding it to the "amq.direct" exchange using it's + * session identifier as the routing key, and places its session + * identifier in the "reply-to" property of each message it sends. + * + * + * server.cpp (this program) + * + * A service that accepts messages from a request queue, converts + * their content to upper case, and sends the result to the + * original sender. + * + * This program creates a request queue, binds it to "amq.direct" + * using the routing key "request", then receives messages from + * the request queue. Each incoming message is converted to upper + * case, then sent to the "amq.direct" exchange using the + * request's reply-to property as the routing key for the + * response. + * + * + */ + + +#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; + + 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/cpp/examples/old_api/request-response/verify b/cpp/examples/old_api/request-response/verify new file mode 100644 index 0000000000..dee82413e7 --- /dev/null +++ b/cpp/examples/old_api/request-response/verify @@ -0,0 +1,24 @@ +# +# 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. +# + +# 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/cpp/examples/old_api/request-response/verify.in b/cpp/examples/old_api/request-response/verify.in new file mode 100644 index 0000000000..7925dc5671 --- /dev/null +++ b/cpp/examples/old_api/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/cpp/examples/old_api/tradedemo/CMakeLists.txt b/cpp/examples/old_api/tradedemo/CMakeLists.txt new file mode 100644 index 0000000000..e61fc1467d --- /dev/null +++ b/cpp/examples/old_api/tradedemo/CMakeLists.txt @@ -0,0 +1,22 @@ +# +# 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. +# + +add_example(tradedemo topic_listener) +add_example(tradedemo topic_publisher) +add_example(tradedemo declare_queues) diff --git a/cpp/examples/old_api/tradedemo/Makefile.am b/cpp/examples/old_api/tradedemo/Makefile.am new file mode 100644 index 0000000000..445b15b367 --- /dev/null +++ b/cpp/examples/old_api/tradedemo/Makefile.am @@ -0,0 +1,46 @@ +# +# 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. +# +examplesdir=$(pkgdatadir)/examples/old_api/tradedemo + +MAKELDFLAGS=$(CLIENTFLAGS) +include $(top_srcdir)/examples/makedist.mk + +noinst_PROGRAMS=topic_listener topic_publisher declare_queues + +topic_listener_SOURCES=topic_listener.cpp +topic_listener_LDADD=$(CLIENT_LIB) + +topic_publisher_SOURCES=topic_publisher.cpp +topic_publisher_LDADD=$(CLIENT_LIB) + +declare_queues_SOURCES=declare_queues.cpp +declare_queues_LDADD=$(CLIENT_LIB) + + +examples_DATA= \ + topic_listener.cpp \ + topic_publisher.cpp \ + declare_queues.cpp \ + $(MAKEDIST) + +EXTRA_DIST= \ + CMakeLists.txt \ + tradedemo_declare_queues.vcproj \ + tradedemo_topic_listener.vcproj \ + tradedemo_topic_publisher.vcproj diff --git a/cpp/examples/old_api/tradedemo/declare_queues.cpp b/cpp/examples/old_api/tradedemo/declare_queues.cpp new file mode 100644 index 0000000000..b1f2cc3510 --- /dev/null +++ b/cpp/examples/old_api/tradedemo/declare_queues.cpp @@ -0,0 +1,98 @@ +/* + * + * 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 implement a publish-subscribe example + * using the "amq.topic" exchange. In the example multiple listeners + * can subscribe to the same queues for TTL messages. + * The TTL messages are all ticker price data. Messages are + * browsed and therefore shared among the multiple listeners. + * Messages timeout using TTL so that they don't stay in the queue + * for too long and fill it up. + * Local exclusive LVQ are also declared for market data. + * + * declare_queues.cpp + * + * Declares several non-exclusive queues bound to the amq:topic exchange + * + * topic_publisher.cpp + * + * Sends messages to the "amq.topic" exchange, using the + * multipart routing keys for ticker price and market data + * Ticker messages are sent using a TTL value. + * + * topic_listener.cpp (this program) + * + * Subscribes to non-exclusive queues in NOT_ACQUIRE mode for + * ticker price data and declares two LVQs for market data. + * + * Multiple listeners can be run at the same time. + * + */ + +#include +#include + + +using namespace qpid::client; +using namespace qpid::framing; + + +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="TICKER.NYSE", arg::exclusive=false); + session.exchangeBind(arg::exchange="amq.topic", arg::queue="TICKER.NYSE", arg::bindingKey="TICKER.NYSE.#"); + std::cout << "Declared queue Ticker NYSE non-exclusive with amq:topic binding TICKER.NYSE.#" << std::endl; + session.queueDeclare(arg::queue="TICKER.NASDAQ", arg::exclusive=false); + session.exchangeBind(arg::exchange="amq.topic", arg::queue="TICKER.NASDAQ", arg::bindingKey="TICKER.NASDAQ.#"); + std::cout << "Declared queue Ticker NASDAQ non-exclusive with amq:topic binding TICKER.NASDAQ.#" << std::endl; + + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; + +} + + + diff --git a/cpp/examples/old_api/tradedemo/topic_listener.cpp b/cpp/examples/old_api/tradedemo/topic_listener.cpp new file mode 100644 index 0000000000..c488e7fb69 --- /dev/null +++ b/cpp/examples/old_api/tradedemo/topic_listener.cpp @@ -0,0 +1,183 @@ +/* + * + * 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 implement a publish-subscribe example + * using the "amq.topic" exchange. In the example multiple listeners + * can subscribe to the same queues for TTL messages. + * The TTL messages are all ticker price data. Messages are + * browsed and therefore shared among the multiple listeners. + * Messages timeout using TTL so that they don't stay in the queue + * for too long and fill it up. + * Local exclusive LVQ are also declared for market data. + * + * declare_queues.cpp + * + * Declares several non-exclusive queues bound to the amq:topic exchange + * + * topic_publisher.cpp + * + * Sends messages to the "amq.topic" exchange, using the + * multipart routing keys for ticker price and market data + * Ticker messages are sent using a TTL value. + * + * topic_listener.cpp (this program) + * + * Subscribes to non-exclusive queues in NOT_ACQUIRE mode for + * ticker price data and declares two LVQs for market data. + * + * Multiple listeners can be run at the same time. + * + */ + +#include +#include +#include +#include +#include +#include "qpid/client/QueueOptions.h" + +#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 subscribeTTLQueue(std::string queue); + virtual void subscribeLVQQueue(std::string queue); + 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::subscribeTTLQueue(std::string queue) { + + /* + * Subscribe to the queue using the subscription manager. + * The queues were declared elsewhere alog with their bindings. + */ + + std::cout << "Subscribing to queue " << queue << std::endl; + subscriptions.subscribe(*this, queue); + // Will not acquire messages but instead browse them. + subscriptions.setAcquireMode(message::ACQUIRE_MODE_NOT_ACQUIRED); +} + +void Listener::subscribeLVQQueue(std::string queue) { + + /* + * Declare and subscribe to the queue using the subscription manager. + */ + + QueueOptions qo; + qo.setOrdering(LVQ); + std::string binding = queue + ".#"; + queue += session.getId().getName(); + session.queueDeclare(arg::queue=queue, arg::exclusive=true, arg::arguments=qo); + session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey=binding); + std::cout << "Declared queue " << queue << " non-exclusive with amq:topic binding " << binding << std::endl; + std::cout << "Subscribing to queue " << queue << std::endl; + subscriptions.subscribe(*this, queue, SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE)); + +} + +void Listener::received(Message& message) { + // If you want to see the destination you can swap the following lines. + // std::cout << message.getDestination() << "\t" << message.getData() << std::endl; + std::cout << message.getData() << std::endl; + +} + +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.subscribeTTLQueue("TICKER.NASDAQ"); + listener.subscribeTTLQueue("TICKER.NYSE"); + + listener.subscribeLVQQueue("MRKT.NASDAQ"); + listener.subscribeLVQQueue("MRKT.NYSE"); + + std::cout << "Starting Listener -C to exit." << std::endl; + 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/cpp/examples/old_api/tradedemo/topic_publisher.cpp b/cpp/examples/old_api/tradedemo/topic_publisher.cpp new file mode 100644 index 0000000000..e22c185bc7 --- /dev/null +++ b/cpp/examples/old_api/tradedemo/topic_publisher.cpp @@ -0,0 +1,271 @@ +/* + * + * 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 implement a publish-subscribe example + * using the "amq.topic" exchange. In the example multiple listeners + * can subscribe to the same queues for TTL messages. + * The TTL messages are all ticker price data. Messages are + * browsed and therefore shared among the multiple listeners. + * Messages timeout using TTL so that they don't stay in the queue + * for too long and fill it up. + * Local exclusive LVQ are also declared for market data. + * + * declare_queues.cpp + * + * Declares several non-exclusive queues bound to the amq:topic exchange + * + * topic_publisher.cpp + * + * Sends messages to the "amq.topic" exchange, using the + * multipart routing keys for ticker price and market data + * Ticker messages are sent using a TTL value. + * + * topic_listener.cpp (this program) + * + * Subscribes to non-exclusive queues in NOT_ACQUIRE mode for + * ticker price data and declares two LVQs for market data. + * + * Multiple listeners can be run at the same time. + * + */ + + +#include +#include +#include +#include +#include "qpid/client/QueueOptions.h" + + +#include +#include +#include +#include +#include + +using namespace qpid::client; +using namespace qpid::framing; + +using std::stringstream; +using std::string; + +class Publisher { + private: + Session& session; + int ttl_time; + unsigned long seq; + + unsigned short high_[6]; + unsigned short low_[6]; + unsigned long shares_[6]; + unsigned long volume_[6]; + QueueOptions args; + + public: + Publisher( Session& session, + const int ttl_time, + const unsigned long shares[6]); + + virtual void publish_ticker(const std::string queue, unsigned short& curr_price); + virtual void publish_market(const std::string queue, unsigned short& curr_price, int i); + virtual ~Publisher() { }; +}; + +Publisher::Publisher(Session& session, int ttl_time, const unsigned long shares[6]) : + session(session), + ttl_time(ttl_time), + seq(0) +{ + for (unsigned short i=0; i < 6; i++) { + high_[i] = 0; + low_[i] = 9999; + volume_[i] = 0; + shares_[i] = shares[i]; + } +} + + +void Publisher::publish_ticker(const std::string symbol, unsigned short& curr_price) +{ + Message message; + + // Set the routing key once, we'll use the same routing key for all + // messages. + + std::string routing_key = "TICKER." + symbol; + std::cout << "Setting routing key:" << routing_key << std::endl; + message.getDeliveryProperties().setRoutingKey(routing_key); + + // Randomally generate some price flucuations + bool mvmnt; + unsigned short change = rand() % 3; + if (rand() % 2 == 0) + { + mvmnt = true; + curr_price += change; + } + else + { + mvmnt = false; + curr_price = (curr_price - change)>0 ? (curr_price - change) : 0; + } + + // Was there change in price or no change ? + std::string movement; + if (!change) + { + movement = "] [--]"; + } else + { + movement = (mvmnt ? "] [UP]" : "] [DOWN]"); + } + + stringstream ticker_data; + // Build up the ticker info + ticker_data << "[TICKER] " << "Symbol:" << symbol << " \tPrice[" << curr_price << "] \t[" + << change << movement; + + message.setData(ticker_data.str()); + // Set TTL value so that message will timeout after a period and be purged from queues + message.getDeliveryProperties().setTtl(ttl_time); + // Asynchronous transfer sends messages as quickly as + // possible without waiting for confirmation. + async(session).messageTransfer(arg::content=message, arg::destination="amq.topic"); + +} + +void Publisher::publish_market(const std::string symbol, unsigned short& curr_price, int i) +{ + Message message; + + // Set the routing key + std::string routing_key = "MRKT." + symbol; + std::cout << "Setting routing key:" << routing_key << std::endl; + message.getDeliveryProperties().setRoutingKey(routing_key); + + // Calculate the market data low/hi change, vol, market cap etc. + if (curr_price < low_[i] || low_[i] == 0) + { + low_[i] = curr_price; + } + else if (curr_price > high_[i] || high_[i] == 9999) + { + high_[i] = curr_price; + } + + volume_[i] += rand() % 1000; // increase the daily volume tracker + int mkt_cap = shares_[i] * curr_price; // calculate new market cap based on current price + + stringstream market_data; + // Build up the ticker info + market_data << "[MARKET] " << "Symbol:" << symbol << "\tVolume: " << volume_[i] + << "\tHi:" << high_[i] << "\tLo:" << low_[i] << "\tMktCap:" + << mkt_cap <<"M\tSEQ[" << seq << "]"; + + message.setData(market_data.str()); + + std::string key; + args.getLVQKey(key); + message.getHeaders().setString(key, symbol); + + // Asynchronous transfer sends messages as quickly as + // possible without waiting for confirmation. + async(session).messageTransfer(arg::content=message, arg::destination="amq.topic"); + seq++; // This sequence number is really just to demonstrate the LVQ nature of the queue. + // You will notice some messages don't show because they are overwritten by last value. + +} + + +int main(int argc, char** argv) { + unsigned int pub_cycles = argc>1 ? atoi(argv[1]) : 100; + unsigned int ttl_time = argc>2 ? atoi(argv[2]) : 4000; + const char* host = argc>3 ? argv[3] : "127.0.0.1"; + int port = argc>4 ? atoi(argv[4]) : 5672; + std::cout <<"Usage: topic_publisher " << std::endl; + std::cout <<"\tparameters are optional but must be in this order when used." << std::endl; + + // Set up the stocks symbols and their prices + std::string symbol[6]; + unsigned short price[6]; + symbol[0] = "NYSE.RHT"; // Red Hat + symbol[1] = "NYSE.IBM"; // IBM Corp. + symbol[2] = "NASDAQ.MSFT"; // Microsoft + symbol[3] = "NASDAQ.CSCO"; // Cisco Systems + symbol[4] = "NASDAQ.YHOO"; // Yahoo + symbol[5] = "NASDAQ.GOOG"; // Google + + // Rough starting values. + price[0] = rand() % 30 +1; + price[1] = rand() % 120 +1; + price[2] = rand() % 20 +1; + price[3] = rand() % 75 +1; + price[4] = rand() % 10 +1; + price[5] = rand() % 323 +1; + + // Shares oustanding in millions. + unsigned long shares[6] = {190,1340,8890, 5860, 1390, 314}; + + + Connection connection; + try { + connection.open(host, port); + Session session = connection.newSession(); + + Publisher theFeed(session,ttl_time, shares); + + //--------- Main body of program -------------------------------------------- + + // Print the opening values for each symbol + std::cout << std::endl << "Opening values:" << std::endl; + for (int i=0; i < 6; i++) + { + std::cout << symbol[i] << ":" << price[i] << std::endl; + } + + // For the duration of the publishing cycles publish + // ticker and market data for each symbol + for (unsigned int j=0; j + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/tradedemo/tradedemo_topic_listener.vcproj b/cpp/examples/old_api/tradedemo/tradedemo_topic_listener.vcproj new file mode 100644 index 0000000000..965be2e88b --- /dev/null +++ b/cpp/examples/old_api/tradedemo/tradedemo_topic_listener.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/tradedemo/tradedemo_topic_publisher.vcproj b/cpp/examples/old_api/tradedemo/tradedemo_topic_publisher.vcproj new file mode 100644 index 0000000000..77fd511e15 --- /dev/null +++ b/cpp/examples/old_api/tradedemo/tradedemo_topic_publisher.vcproj @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpp/examples/old_api/verify b/cpp/examples/old_api/verify new file mode 100755 index 0000000000..9a1ed078d6 --- /dev/null +++ b/cpp/examples/old_api/verify @@ -0,0 +1,121 @@ +#!/bin/sh + +# +# 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. +# + +export LC_ALL=C + +# Driver script to verify installed examples (also used for build tests.) +# +# Usage: verify example_dir [ example_dir ...] +# Where each example_dir must contain a verify sub-script to include. +# +# If $QPIDD is set, run a private QPIDD and use it. +# If $QPID_HOST or $QPID_PORT are set, use them to connect. +# + +QPID_DATA_DIR= +QPID_NO_MODULE_DIR=1 +export QPID_DATA_DIR QPID_NO_MODULE_DIR + +cleanup() { + test -n "$QPIDD" && $QPIDD -q # Private broker + kill %% > /dev/null 2>&1 # Leftover background jobs +} + +trap cleanup EXIT + +ARGS="${QPID_HOST:-localhost} $QPID_PORT" + +outfile() { + file=$1 + while [ -f $file.out ]; do file="${file}X"; done + echo $file.out + } + +fail() { test -n "$*" && echo $* 1>&2 ; FAIL=1; return 1; } + +client() { "$@" $ARGS > `outfile $*` || fail; } + +clients() { for cmd in "$@"; do client $cmd; done; } + +waitfor() { until grep -a -l "$2" $1 >/dev/null 2>&1 ; do sleep 1 ; done ; } + +background() { + pattern=$1; shift + out=`outfile $*` + eval "$* $ARGS > $out &" || { fail; return 1; } + waitfor $out "$pattern" +} + +name() { + for x in $*; do name="$name `basename $x`"; done + echo $name; +} + +outputs() { + wait 2> /dev/null # Wait for all backgroud processes to complete + rm -f $script.out + for f in "$@"; do + { echo "==== `name $f`"; eval "cat $f"; } >> $script.out || fail + done +} + +normalize() { echo `cd $1 && pwd`; } + +verify() { + FAIL= + arg=$1 + srcdir=$(normalize $2) + builddir=$(normalize $3) + if [ -d $arg ]; then dir=$(normalize $arg); script=verify; + else dir=$(normalize `dirname $arg`); script=`basename $arg`; fi + + # if the example is in the "cpp" area, make sure we run from the build directory, not the source dir. + rundir=${dir/$srcdir\/cpp/$builddir/} + cd $rundir || return 1 + rm -f *.out + { source $dir/$script && diff -ac $script.out $dir/$script.in ; } || fail + test -z "$FAIL" && rm -f *.out + return $FAIL +} + +HEX="[a-fA-F0-9]" +remove_uuid() { + sed "s/$HEX\{8\}-$HEX\{4\}-$HEX\{4\}-$HEX\{4\}-$HEX\{12\}//g" $* +} +remove_uuid64() { + sed 's/[-A-Za-z0-9_]\{22\}==//g' $* +} + +# Start private broker if QPIDD is set. +if [ -n "$QPIDD" ] ; then + export QPID_PORT=`$QPIDD -dp0` || { echo "Cannot start $QPIDD" ; exit 1; } + trap "$QPIDD -q" EXIT +fi + +topsrcdir=$1 +topbuilddir=$2 +shift 2 + +for example in "$@"; do + echo "== $example" + if ( verify $example $topsrcdir $topbuilddir; ) then echo "PASS"; else echo "FAIL"; RET=1; fi + done +exit $RET diff --git a/cpp/examples/old_api/verify_all b/cpp/examples/old_api/verify_all new file mode 100755 index 0000000000..fbe51377b6 --- /dev/null +++ b/cpp/examples/old_api/verify_all @@ -0,0 +1,46 @@ +#!/bin/sh + +# +# 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. +# + +# Verify all examples + +verify=`dirname $0`/verify +topsrcdir=$1 +topbuilddir=$2 +qpidd=$topbuilddir/src/qpidd +broker_args=$3 +exclude_regexp=$4 + +trap "$qpidd -q" exit +QPID_PORT=`$qpidd -dp0 $broker_args` || { echo "Can't run qpidd" ; exit 1; } +export QPID_PORT + +find="find $topsrcdir/cpp/examples/old_api" +find="$find -mindepth 2 -name verify" +all_examples=`$find` + +if test -z "$exclude_regexp"; then + run_examples=$all_examples +else + for f in $all_examples; do + { echo $f | grep $exclude_regexp > /dev/null ; } || run_examples="$run_examples $f" + done +fi +$verify $topsrcdir $topbuilddir $run_examples diff --git a/cpp/examples/old_api/xml-exchange/CMakeLists.txt b/cpp/examples/old_api/xml-exchange/CMakeLists.txt new file mode 100644 index 0000000000..3fea47a208 --- /dev/null +++ b/cpp/examples/old_api/xml-exchange/CMakeLists.txt @@ -0,0 +1,24 @@ +# +# 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. +# + +if (BUILD_XML) +add_example(xml-exchange declare_queues) +add_example(xml-exchange xml_producer) +add_example(xml-exchange listener) +endif (BUILD_XML) diff --git a/cpp/examples/old_api/xml-exchange/Makefile.am b/cpp/examples/old_api/xml-exchange/Makefile.am new file mode 100644 index 0000000000..3e1082cdb2 --- /dev/null +++ b/cpp/examples/old_api/xml-exchange/Makefile.am @@ -0,0 +1,49 @@ +# +# 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. +# +examplesdir=$(pkgdatadir)/examples/old_api/xml-exchange + +MAKELDFLAGS=$(CLIENTFLAGS) +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.txt \ + CMakeLists.txt + +examples_DATA= \ + $(EXTRA_DIST) \ + declare_queues.cpp \ + listener.cpp \ + xml_producer.cpp \ + $(MAKEDIST) + + + + + diff --git a/cpp/examples/old_api/xml-exchange/README.txt b/cpp/examples/old_api/xml-exchange/README.txt new file mode 100644 index 0000000000..85caebe352 --- /dev/null +++ b/cpp/examples/old_api/xml-exchange/README.txt @@ -0,0 +1,53 @@ +This example shows how to program a simple application +using the XML Exchange. + +[Note: The XML Exchange is not a standard AMQP exchange type. To run +this example you need to have a broker that has support for the xml +exchange. If you are compiling the broker from source please refer to +the INSTALL notes from qpid.] + +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/cpp/examples/old_api/xml-exchange/declare_queues.cpp b/cpp/examples/old_api/xml-exchange/declare_queues.cpp new file mode 100644 index 0000000000..ad08642019 --- /dev/null +++ b/cpp/examples/old_api/xml-exchange/declare_queues.cpp @@ -0,0 +1,98 @@ +/* + * + * 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 is one of three programs used to implement XML-based content + * routing in C++. + * + * declare_queues.cpp (this program) + * + * Creates a queue named "message_qaueue" on the broker, + * declares an XML Exchange, subscribes the queue to the XML + * Exchange using an XQuery in the binding, then exits. + * + * xml_producer.cpp + * + * Publishes messages to the XML Exchange. + * + * listener.cpp + * + * Reads messages from the "message_queue" queue. + */ + +#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="content_feed", arg::arguments=binding); + + //----------------------------------------------------------------------------- + + connection.close(); + return 0; + } catch(const std::exception& error) { + std::cout << error.what() << std::endl; + } + return 1; + +} + + + diff --git a/cpp/examples/old_api/xml-exchange/listener.cpp b/cpp/examples/old_api/xml-exchange/listener.cpp new file mode 100644 index 0000000000..11bcb9f669 --- /dev/null +++ b/cpp/examples/old_api/xml-exchange/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 is one of three programs used to implement XML-based content + * routing in C++. + * + * declare_queues.cpp + * + * Creates a queue named "message_qaueue" on the broker, + * declares an XML Exchange, subscribes the queue to the XML + * Exchange using an XQuery in the binding, then exits. + * + * xml_producer.cpp + * + * Publishes messages to the XML Exchange. + * + * listener.cpp (this program) + * + * Reads messages from the "message_queue" queue. + */ + + +#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().getAsString("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; + 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/cpp/examples/old_api/xml-exchange/xml_producer.cpp b/cpp/examples/old_api/xml-exchange/xml_producer.cpp new file mode 100644 index 0000000000..af1a7e60c7 --- /dev/null +++ b/cpp/examples/old_api/xml-exchange/xml_producer.cpp @@ -0,0 +1,113 @@ +/* + * + * 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. + * + */ + + +/** + * + * xml_producer.cpp + * + * This is one of three programs used to implement XML-based content + * routing in C++. + * + * declare_queues.cpp + * + * Creates a queue named "message_qaueue" on the broker, + * declares an XML Exchange, subscribes the queue to the XML + * Exchange using an XQuery in the binding, then exits. + * + * xml_producer.cpp (this program) + * + * Publishes messages to the XML Exchange. + * + * listener.cpp + * + * Reads messages from the "message_queue" queue. + */ + + +#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("content_feed"); + 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/cpp/examples/pub-sub/CMakeLists.txt b/cpp/examples/pub-sub/CMakeLists.txt deleted file mode 100644 index 961de06d5a..0000000000 --- a/cpp/examples/pub-sub/CMakeLists.txt +++ /dev/null @@ -1,21 +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. -# - -add_example(pub-sub topic_listener) -add_example(pub-sub topic_publisher) diff --git a/cpp/examples/pub-sub/Makefile.am b/cpp/examples/pub-sub/Makefile.am deleted file mode 100644 index 62658ebe94..0000000000 --- a/cpp/examples/pub-sub/Makefile.am +++ /dev/null @@ -1,43 +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. -# -examplesdir=$(pkgdatadir)/examples/pub-sub - -MAKELDFLAGS=$(CLIENTFLAGS) -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) \ - CMakeLists.txt \ - verify \ - verify.in \ - pub-sub_topic_listener.vcproj \ - pub-sub_topic_publisher.vcproj diff --git a/cpp/examples/pub-sub/pub-sub_topic_listener.vcproj b/cpp/examples/pub-sub/pub-sub_topic_listener.vcproj deleted file mode 100644 index aa0b3bcaa3..0000000000 --- a/cpp/examples/pub-sub/pub-sub_topic_listener.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/pub-sub/pub-sub_topic_publisher.vcproj b/cpp/examples/pub-sub/pub-sub_topic_publisher.vcproj deleted file mode 100644 index 76e51df4df..0000000000 --- a/cpp/examples/pub-sub/pub-sub_topic_publisher.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/pub-sub/topic_listener.cpp b/cpp/examples/pub-sub/topic_listener.cpp deleted file mode 100644 index d38a806303..0000000000 --- a/cpp/examples/pub-sub/topic_listener.cpp +++ /dev/null @@ -1,173 +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 two programs designed to be used - * together. These programs implement a publish-subscribe example - * using the "amq.topic" exchange. - * - * topic_publisher.cpp - * - * Sends messages to the "amq.topic" exchange, using the - * multipart routing keys "usa.news", "usa.weather", - * "europe.news", and "europe.weather". - * - * topic_listener.cpp (this program) - * - * Creates private queues for "news", "weather", "usa", and - * "europe", binding them to the amq.topic exchange using - * bindings that match the corresponding parts of the multipart - * routing keys. - * - * Multiple listeners can be run at the same time. - * - */ - -#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 exchange, 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 exchange, 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=exchange, arg::queue=queue, arg::bindingKey=routing_key); - session.exchangeBind(arg::exchange=exchange, 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; - std::string exchange = argc>3 ? argv[3] : "amq.topic"; - 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", exchange, "usa.#"); - listener.prepareQueue("europe", exchange, "europe.#"); - listener.prepareQueue("news", exchange, "#.news"); - listener.prepareQueue("weather", exchange, "#.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/cpp/examples/pub-sub/topic_publisher.cpp b/cpp/examples/pub-sub/topic_publisher.cpp deleted file mode 100644 index aed5f8f033..0000000000 --- a/cpp/examples/pub-sub/topic_publisher.cpp +++ /dev/null @@ -1,129 +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 two programs designed to be used - * together. These programs implement a publish-subscribe example - * using the "amq.topic" exchange. - * - * topic_publisher.cpp (this program) - * - * Sends messages to the "amq.topic" exchange, using the - * multipart routing keys "usa.news", "usa.weather", - * "europe.news", and "europe.weather". - * - * topic_listener.cpp - * - * Creates private queues for "news", "weather", "usa", and - * "europe", binding them to the amq.topic exchange using - * bindings that match the corresponding parts of the multipart - * routing keys. - * - * Multiple listeners can be run at the same time. - * - */ - - -#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; - 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/cpp/examples/pub-sub/verify b/cpp/examples/pub-sub/verify deleted file mode 100644 index 528d2f401e..0000000000 --- a/cpp/examples/pub-sub/verify +++ /dev/null @@ -1,23 +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. -# - -# 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/cpp/examples/pub-sub/verify.in b/cpp/examples/pub-sub/verify.in deleted file mode 100644 index 6413c5c788..0000000000 --- a/cpp/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/cpp/examples/qmf-console/ping.cpp b/cpp/examples/qmf-console/ping.cpp index fe537d48d2..e6d6d138d5 100644 --- a/cpp/examples/qmf-console/ping.cpp +++ b/cpp/examples/qmf-console/ping.cpp @@ -31,9 +31,7 @@ using namespace qpid::console; int main_int(int /*argc*/, char** /*argv*/) { // - // Declare connection settings for the messaging broker. The settings default to - // localhost:5672 with user guest (password guest). Refer to the header file - // for full details. + // Declare connection settings for the messaging broker. // qpid::client::ConnectionSettings connSettings; diff --git a/cpp/examples/qmf-console/printevents.cpp b/cpp/examples/qmf-console/printevents.cpp index 3a0a2ab68b..ac3e449a2c 100644 --- a/cpp/examples/qmf-console/printevents.cpp +++ b/cpp/examples/qmf-console/printevents.cpp @@ -64,9 +64,7 @@ struct Main { Listener listener; // - // Declare connection settings for the messaging broker. The settings default to - // localhost:5672 with user guest (password guest). Refer to the header file - // for full details. + // Declare connection settings for the messaging broker. // qpid::client::ConnectionSettings connSettings; diff --git a/cpp/examples/request-response/CMakeLists.txt b/cpp/examples/request-response/CMakeLists.txt deleted file mode 100644 index 873a0cfa86..0000000000 --- a/cpp/examples/request-response/CMakeLists.txt +++ /dev/null @@ -1,21 +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. -# - -add_example(request-response client) -add_example(request-response server) diff --git a/cpp/examples/request-response/Makefile.am b/cpp/examples/request-response/Makefile.am deleted file mode 100644 index 48b3d989f0..0000000000 --- a/cpp/examples/request-response/Makefile.am +++ /dev/null @@ -1,43 +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. -# -examplesdir=$(pkgdatadir)/examples/request-response - -MAKELDFLAGS=$(CLIENTFLAGS) -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) \ - CMakeLists.txt \ - verify \ - verify.in \ - request-response_client.vcproj \ - request-response_server.vcproj diff --git a/cpp/examples/request-response/client.cpp b/cpp/examples/request-response/client.cpp deleted file mode 100644 index 679d1c5fc2..0000000000 --- a/cpp/examples/request-response/client.cpp +++ /dev/null @@ -1,163 +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) - * - * A client application that sends messages to the "amq.direct" - * exchange, using the routing key "request" to route messages to - * the server. - * - * Each instance of the client creates its own private response - * queue, binding it to the "amq.direct" exchange using it's - * session identifier as the routing key, and places its session - * identifier in the "reply-to" property of each message it sends. - * - * - * server.cpp - * - * A service that accepts messages from a request queue, converts - * their content to upper case, and sends the result to the - * original sender. - * - * This program creates a request queue, binds it to "amq.direct" - * using the routing key "request", then receives messages from - * the request queue. Each incoming message is converted to upper - * case, then sent to the "amq.direct" exchange using the - * request's reply-to property as the routing key for the - * response. - * - * - */ - -#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; - 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()); - } -} - - - -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 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. - - Message request; - 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]); - 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/cpp/examples/request-response/request-response_client.vcproj b/cpp/examples/request-response/request-response_client.vcproj deleted file mode 100644 index 5f9eadde36..0000000000 --- a/cpp/examples/request-response/request-response_client.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/request-response/request-response_server.vcproj b/cpp/examples/request-response/request-response_server.vcproj deleted file mode 100644 index 54352b9f46..0000000000 --- a/cpp/examples/request-response/request-response_server.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/request-response/server.cpp b/cpp/examples/request-response/server.cpp deleted file mode 100644 index 65a4717b35..0000000000 --- a/cpp/examples/request-response/server.cpp +++ /dev/null @@ -1,161 +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 - * - * A client application that sends messages to the "amq.direct" - * exchange, using the routing key "request" to route messages to - * the server. - * - * Each instance of the client creates its own private response - * queue, binding it to the "amq.direct" exchange using it's - * session identifier as the routing key, and places its session - * identifier in the "reply-to" property of each message it sends. - * - * - * server.cpp (this program) - * - * A service that accepts messages from a request queue, converts - * their content to upper case, and sends the result to the - * original sender. - * - * This program creates a request queue, binds it to "amq.direct" - * using the routing key "request", then receives messages from - * the request queue. Each incoming message is converted to upper - * case, then sent to the "amq.direct" exchange using the - * request's reply-to property as the routing key for the - * response. - * - * - */ - - -#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; - - 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/cpp/examples/request-response/verify b/cpp/examples/request-response/verify deleted file mode 100644 index dee82413e7..0000000000 --- a/cpp/examples/request-response/verify +++ /dev/null @@ -1,24 +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. -# - -# 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/cpp/examples/request-response/verify.in b/cpp/examples/request-response/verify.in deleted file mode 100644 index 7925dc5671..0000000000 --- a/cpp/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/cpp/examples/tradedemo/CMakeLists.txt b/cpp/examples/tradedemo/CMakeLists.txt deleted file mode 100644 index e61fc1467d..0000000000 --- a/cpp/examples/tradedemo/CMakeLists.txt +++ /dev/null @@ -1,22 +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. -# - -add_example(tradedemo topic_listener) -add_example(tradedemo topic_publisher) -add_example(tradedemo declare_queues) diff --git a/cpp/examples/tradedemo/Makefile.am b/cpp/examples/tradedemo/Makefile.am deleted file mode 100644 index f4d8686d05..0000000000 --- a/cpp/examples/tradedemo/Makefile.am +++ /dev/null @@ -1,46 +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. -# -examplesdir=$(pkgdatadir)/examples/tradedemo - -MAKELDFLAGS=$(CLIENTFLAGS) -include $(top_srcdir)/examples/makedist.mk - -noinst_PROGRAMS=topic_listener topic_publisher declare_queues - -topic_listener_SOURCES=topic_listener.cpp -topic_listener_LDADD=$(CLIENT_LIB) - -topic_publisher_SOURCES=topic_publisher.cpp -topic_publisher_LDADD=$(CLIENT_LIB) - -declare_queues_SOURCES=declare_queues.cpp -declare_queues_LDADD=$(CLIENT_LIB) - - -examples_DATA= \ - topic_listener.cpp \ - topic_publisher.cpp \ - declare_queues.cpp \ - $(MAKEDIST) - -EXTRA_DIST= \ - CMakeLists.txt \ - tradedemo_declare_queues.vcproj \ - tradedemo_topic_listener.vcproj \ - tradedemo_topic_publisher.vcproj diff --git a/cpp/examples/tradedemo/declare_queues.cpp b/cpp/examples/tradedemo/declare_queues.cpp deleted file mode 100644 index b1f2cc3510..0000000000 --- a/cpp/examples/tradedemo/declare_queues.cpp +++ /dev/null @@ -1,98 +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 implement a publish-subscribe example - * using the "amq.topic" exchange. In the example multiple listeners - * can subscribe to the same queues for TTL messages. - * The TTL messages are all ticker price data. Messages are - * browsed and therefore shared among the multiple listeners. - * Messages timeout using TTL so that they don't stay in the queue - * for too long and fill it up. - * Local exclusive LVQ are also declared for market data. - * - * declare_queues.cpp - * - * Declares several non-exclusive queues bound to the amq:topic exchange - * - * topic_publisher.cpp - * - * Sends messages to the "amq.topic" exchange, using the - * multipart routing keys for ticker price and market data - * Ticker messages are sent using a TTL value. - * - * topic_listener.cpp (this program) - * - * Subscribes to non-exclusive queues in NOT_ACQUIRE mode for - * ticker price data and declares two LVQs for market data. - * - * Multiple listeners can be run at the same time. - * - */ - -#include -#include - - -using namespace qpid::client; -using namespace qpid::framing; - - -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="TICKER.NYSE", arg::exclusive=false); - session.exchangeBind(arg::exchange="amq.topic", arg::queue="TICKER.NYSE", arg::bindingKey="TICKER.NYSE.#"); - std::cout << "Declared queue Ticker NYSE non-exclusive with amq:topic binding TICKER.NYSE.#" << std::endl; - session.queueDeclare(arg::queue="TICKER.NASDAQ", arg::exclusive=false); - session.exchangeBind(arg::exchange="amq.topic", arg::queue="TICKER.NASDAQ", arg::bindingKey="TICKER.NASDAQ.#"); - std::cout << "Declared queue Ticker NASDAQ non-exclusive with amq:topic binding TICKER.NASDAQ.#" << std::endl; - - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; - -} - - - diff --git a/cpp/examples/tradedemo/topic_listener.cpp b/cpp/examples/tradedemo/topic_listener.cpp deleted file mode 100644 index c488e7fb69..0000000000 --- a/cpp/examples/tradedemo/topic_listener.cpp +++ /dev/null @@ -1,183 +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 implement a publish-subscribe example - * using the "amq.topic" exchange. In the example multiple listeners - * can subscribe to the same queues for TTL messages. - * The TTL messages are all ticker price data. Messages are - * browsed and therefore shared among the multiple listeners. - * Messages timeout using TTL so that they don't stay in the queue - * for too long and fill it up. - * Local exclusive LVQ are also declared for market data. - * - * declare_queues.cpp - * - * Declares several non-exclusive queues bound to the amq:topic exchange - * - * topic_publisher.cpp - * - * Sends messages to the "amq.topic" exchange, using the - * multipart routing keys for ticker price and market data - * Ticker messages are sent using a TTL value. - * - * topic_listener.cpp (this program) - * - * Subscribes to non-exclusive queues in NOT_ACQUIRE mode for - * ticker price data and declares two LVQs for market data. - * - * Multiple listeners can be run at the same time. - * - */ - -#include -#include -#include -#include -#include -#include "qpid/client/QueueOptions.h" - -#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 subscribeTTLQueue(std::string queue); - virtual void subscribeLVQQueue(std::string queue); - 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::subscribeTTLQueue(std::string queue) { - - /* - * Subscribe to the queue using the subscription manager. - * The queues were declared elsewhere alog with their bindings. - */ - - std::cout << "Subscribing to queue " << queue << std::endl; - subscriptions.subscribe(*this, queue); - // Will not acquire messages but instead browse them. - subscriptions.setAcquireMode(message::ACQUIRE_MODE_NOT_ACQUIRED); -} - -void Listener::subscribeLVQQueue(std::string queue) { - - /* - * Declare and subscribe to the queue using the subscription manager. - */ - - QueueOptions qo; - qo.setOrdering(LVQ); - std::string binding = queue + ".#"; - queue += session.getId().getName(); - session.queueDeclare(arg::queue=queue, arg::exclusive=true, arg::arguments=qo); - session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey=binding); - std::cout << "Declared queue " << queue << " non-exclusive with amq:topic binding " << binding << std::endl; - std::cout << "Subscribing to queue " << queue << std::endl; - subscriptions.subscribe(*this, queue, SubscriptionSettings(FlowControl::unlimited(), ACCEPT_MODE_NONE)); - -} - -void Listener::received(Message& message) { - // If you want to see the destination you can swap the following lines. - // std::cout << message.getDestination() << "\t" << message.getData() << std::endl; - std::cout << message.getData() << std::endl; - -} - -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.subscribeTTLQueue("TICKER.NASDAQ"); - listener.subscribeTTLQueue("TICKER.NYSE"); - - listener.subscribeLVQQueue("MRKT.NASDAQ"); - listener.subscribeLVQQueue("MRKT.NYSE"); - - std::cout << "Starting Listener -C to exit." << std::endl; - 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/cpp/examples/tradedemo/topic_publisher.cpp b/cpp/examples/tradedemo/topic_publisher.cpp deleted file mode 100644 index e22c185bc7..0000000000 --- a/cpp/examples/tradedemo/topic_publisher.cpp +++ /dev/null @@ -1,271 +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 implement a publish-subscribe example - * using the "amq.topic" exchange. In the example multiple listeners - * can subscribe to the same queues for TTL messages. - * The TTL messages are all ticker price data. Messages are - * browsed and therefore shared among the multiple listeners. - * Messages timeout using TTL so that they don't stay in the queue - * for too long and fill it up. - * Local exclusive LVQ are also declared for market data. - * - * declare_queues.cpp - * - * Declares several non-exclusive queues bound to the amq:topic exchange - * - * topic_publisher.cpp - * - * Sends messages to the "amq.topic" exchange, using the - * multipart routing keys for ticker price and market data - * Ticker messages are sent using a TTL value. - * - * topic_listener.cpp (this program) - * - * Subscribes to non-exclusive queues in NOT_ACQUIRE mode for - * ticker price data and declares two LVQs for market data. - * - * Multiple listeners can be run at the same time. - * - */ - - -#include -#include -#include -#include -#include "qpid/client/QueueOptions.h" - - -#include -#include -#include -#include -#include - -using namespace qpid::client; -using namespace qpid::framing; - -using std::stringstream; -using std::string; - -class Publisher { - private: - Session& session; - int ttl_time; - unsigned long seq; - - unsigned short high_[6]; - unsigned short low_[6]; - unsigned long shares_[6]; - unsigned long volume_[6]; - QueueOptions args; - - public: - Publisher( Session& session, - const int ttl_time, - const unsigned long shares[6]); - - virtual void publish_ticker(const std::string queue, unsigned short& curr_price); - virtual void publish_market(const std::string queue, unsigned short& curr_price, int i); - virtual ~Publisher() { }; -}; - -Publisher::Publisher(Session& session, int ttl_time, const unsigned long shares[6]) : - session(session), - ttl_time(ttl_time), - seq(0) -{ - for (unsigned short i=0; i < 6; i++) { - high_[i] = 0; - low_[i] = 9999; - volume_[i] = 0; - shares_[i] = shares[i]; - } -} - - -void Publisher::publish_ticker(const std::string symbol, unsigned short& curr_price) -{ - Message message; - - // Set the routing key once, we'll use the same routing key for all - // messages. - - std::string routing_key = "TICKER." + symbol; - std::cout << "Setting routing key:" << routing_key << std::endl; - message.getDeliveryProperties().setRoutingKey(routing_key); - - // Randomally generate some price flucuations - bool mvmnt; - unsigned short change = rand() % 3; - if (rand() % 2 == 0) - { - mvmnt = true; - curr_price += change; - } - else - { - mvmnt = false; - curr_price = (curr_price - change)>0 ? (curr_price - change) : 0; - } - - // Was there change in price or no change ? - std::string movement; - if (!change) - { - movement = "] [--]"; - } else - { - movement = (mvmnt ? "] [UP]" : "] [DOWN]"); - } - - stringstream ticker_data; - // Build up the ticker info - ticker_data << "[TICKER] " << "Symbol:" << symbol << " \tPrice[" << curr_price << "] \t[" - << change << movement; - - message.setData(ticker_data.str()); - // Set TTL value so that message will timeout after a period and be purged from queues - message.getDeliveryProperties().setTtl(ttl_time); - // Asynchronous transfer sends messages as quickly as - // possible without waiting for confirmation. - async(session).messageTransfer(arg::content=message, arg::destination="amq.topic"); - -} - -void Publisher::publish_market(const std::string symbol, unsigned short& curr_price, int i) -{ - Message message; - - // Set the routing key - std::string routing_key = "MRKT." + symbol; - std::cout << "Setting routing key:" << routing_key << std::endl; - message.getDeliveryProperties().setRoutingKey(routing_key); - - // Calculate the market data low/hi change, vol, market cap etc. - if (curr_price < low_[i] || low_[i] == 0) - { - low_[i] = curr_price; - } - else if (curr_price > high_[i] || high_[i] == 9999) - { - high_[i] = curr_price; - } - - volume_[i] += rand() % 1000; // increase the daily volume tracker - int mkt_cap = shares_[i] * curr_price; // calculate new market cap based on current price - - stringstream market_data; - // Build up the ticker info - market_data << "[MARKET] " << "Symbol:" << symbol << "\tVolume: " << volume_[i] - << "\tHi:" << high_[i] << "\tLo:" << low_[i] << "\tMktCap:" - << mkt_cap <<"M\tSEQ[" << seq << "]"; - - message.setData(market_data.str()); - - std::string key; - args.getLVQKey(key); - message.getHeaders().setString(key, symbol); - - // Asynchronous transfer sends messages as quickly as - // possible without waiting for confirmation. - async(session).messageTransfer(arg::content=message, arg::destination="amq.topic"); - seq++; // This sequence number is really just to demonstrate the LVQ nature of the queue. - // You will notice some messages don't show because they are overwritten by last value. - -} - - -int main(int argc, char** argv) { - unsigned int pub_cycles = argc>1 ? atoi(argv[1]) : 100; - unsigned int ttl_time = argc>2 ? atoi(argv[2]) : 4000; - const char* host = argc>3 ? argv[3] : "127.0.0.1"; - int port = argc>4 ? atoi(argv[4]) : 5672; - std::cout <<"Usage: topic_publisher " << std::endl; - std::cout <<"\tparameters are optional but must be in this order when used." << std::endl; - - // Set up the stocks symbols and their prices - std::string symbol[6]; - unsigned short price[6]; - symbol[0] = "NYSE.RHT"; // Red Hat - symbol[1] = "NYSE.IBM"; // IBM Corp. - symbol[2] = "NASDAQ.MSFT"; // Microsoft - symbol[3] = "NASDAQ.CSCO"; // Cisco Systems - symbol[4] = "NASDAQ.YHOO"; // Yahoo - symbol[5] = "NASDAQ.GOOG"; // Google - - // Rough starting values. - price[0] = rand() % 30 +1; - price[1] = rand() % 120 +1; - price[2] = rand() % 20 +1; - price[3] = rand() % 75 +1; - price[4] = rand() % 10 +1; - price[5] = rand() % 323 +1; - - // Shares oustanding in millions. - unsigned long shares[6] = {190,1340,8890, 5860, 1390, 314}; - - - Connection connection; - try { - connection.open(host, port); - Session session = connection.newSession(); - - Publisher theFeed(session,ttl_time, shares); - - //--------- Main body of program -------------------------------------------- - - // Print the opening values for each symbol - std::cout << std::endl << "Opening values:" << std::endl; - for (int i=0; i < 6; i++) - { - std::cout << symbol[i] << ":" << price[i] << std::endl; - } - - // For the duration of the publishing cycles publish - // ticker and market data for each symbol - for (unsigned int j=0; j - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/tradedemo/tradedemo_topic_listener.vcproj b/cpp/examples/tradedemo/tradedemo_topic_listener.vcproj deleted file mode 100644 index 965be2e88b..0000000000 --- a/cpp/examples/tradedemo/tradedemo_topic_listener.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/tradedemo/tradedemo_topic_publisher.vcproj b/cpp/examples/tradedemo/tradedemo_topic_publisher.vcproj deleted file mode 100644 index 77fd511e15..0000000000 --- a/cpp/examples/tradedemo/tradedemo_topic_publisher.vcproj +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cpp/examples/verify b/cpp/examples/verify deleted file mode 100755 index 9a1ed078d6..0000000000 --- a/cpp/examples/verify +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/sh - -# -# 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. -# - -export LC_ALL=C - -# Driver script to verify installed examples (also used for build tests.) -# -# Usage: verify example_dir [ example_dir ...] -# Where each example_dir must contain a verify sub-script to include. -# -# If $QPIDD is set, run a private QPIDD and use it. -# If $QPID_HOST or $QPID_PORT are set, use them to connect. -# - -QPID_DATA_DIR= -QPID_NO_MODULE_DIR=1 -export QPID_DATA_DIR QPID_NO_MODULE_DIR - -cleanup() { - test -n "$QPIDD" && $QPIDD -q # Private broker - kill %% > /dev/null 2>&1 # Leftover background jobs -} - -trap cleanup EXIT - -ARGS="${QPID_HOST:-localhost} $QPID_PORT" - -outfile() { - file=$1 - while [ -f $file.out ]; do file="${file}X"; done - echo $file.out - } - -fail() { test -n "$*" && echo $* 1>&2 ; FAIL=1; return 1; } - -client() { "$@" $ARGS > `outfile $*` || fail; } - -clients() { for cmd in "$@"; do client $cmd; done; } - -waitfor() { until grep -a -l "$2" $1 >/dev/null 2>&1 ; do sleep 1 ; done ; } - -background() { - pattern=$1; shift - out=`outfile $*` - eval "$* $ARGS > $out &" || { fail; return 1; } - waitfor $out "$pattern" -} - -name() { - for x in $*; do name="$name `basename $x`"; done - echo $name; -} - -outputs() { - wait 2> /dev/null # Wait for all backgroud processes to complete - rm -f $script.out - for f in "$@"; do - { echo "==== `name $f`"; eval "cat $f"; } >> $script.out || fail - done -} - -normalize() { echo `cd $1 && pwd`; } - -verify() { - FAIL= - arg=$1 - srcdir=$(normalize $2) - builddir=$(normalize $3) - if [ -d $arg ]; then dir=$(normalize $arg); script=verify; - else dir=$(normalize `dirname $arg`); script=`basename $arg`; fi - - # if the example is in the "cpp" area, make sure we run from the build directory, not the source dir. - rundir=${dir/$srcdir\/cpp/$builddir/} - cd $rundir || return 1 - rm -f *.out - { source $dir/$script && diff -ac $script.out $dir/$script.in ; } || fail - test -z "$FAIL" && rm -f *.out - return $FAIL -} - -HEX="[a-fA-F0-9]" -remove_uuid() { - sed "s/$HEX\{8\}-$HEX\{4\}-$HEX\{4\}-$HEX\{4\}-$HEX\{12\}//g" $* -} -remove_uuid64() { - sed 's/[-A-Za-z0-9_]\{22\}==//g' $* -} - -# Start private broker if QPIDD is set. -if [ -n "$QPIDD" ] ; then - export QPID_PORT=`$QPIDD -dp0` || { echo "Cannot start $QPIDD" ; exit 1; } - trap "$QPIDD -q" EXIT -fi - -topsrcdir=$1 -topbuilddir=$2 -shift 2 - -for example in "$@"; do - echo "== $example" - if ( verify $example $topsrcdir $topbuilddir; ) then echo "PASS"; else echo "FAIL"; RET=1; fi - done -exit $RET diff --git a/cpp/examples/verify_all b/cpp/examples/verify_all deleted file mode 100755 index cb4c5283fa..0000000000 --- a/cpp/examples/verify_all +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh - -# -# 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. -# - -# Verify all examples - -verify=`dirname $0`/verify -topsrcdir=$1 -topbuilddir=$2 -qpidd=$topbuilddir/src/qpidd -broker_args=$3 -exclude_regexp=$4 - -trap "$qpidd -q" exit -QPID_PORT=`$qpidd -dp0 $broker_args` || { echo "Can't run qpidd" ; exit 1; } -export QPID_PORT - -find="find $topsrcdir/cpp/examples" -find="$find -mindepth 2 -name verify" -all_examples=`$find` - -if test -z "$exclude_regexp"; then - run_examples=$all_examples -else - for f in $all_examples; do - { echo $f | grep $exclude_regexp > /dev/null ; } || run_examples="$run_examples $f" - done -fi -$verify $topsrcdir $topbuilddir $run_examples diff --git a/cpp/examples/xml-exchange/CMakeLists.txt b/cpp/examples/xml-exchange/CMakeLists.txt deleted file mode 100644 index 3fea47a208..0000000000 --- a/cpp/examples/xml-exchange/CMakeLists.txt +++ /dev/null @@ -1,24 +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. -# - -if (BUILD_XML) -add_example(xml-exchange declare_queues) -add_example(xml-exchange xml_producer) -add_example(xml-exchange listener) -endif (BUILD_XML) diff --git a/cpp/examples/xml-exchange/Makefile.am b/cpp/examples/xml-exchange/Makefile.am deleted file mode 100644 index 9001e3fa61..0000000000 --- a/cpp/examples/xml-exchange/Makefile.am +++ /dev/null @@ -1,49 +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. -# -examplesdir=$(pkgdatadir)/examples/xml-exchange - -MAKELDFLAGS=$(CLIENTFLAGS) -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.txt \ - CMakeLists.txt - -examples_DATA= \ - $(EXTRA_DIST) \ - declare_queues.cpp \ - listener.cpp \ - xml_producer.cpp \ - $(MAKEDIST) - - - - - diff --git a/cpp/examples/xml-exchange/README.txt b/cpp/examples/xml-exchange/README.txt deleted file mode 100644 index 85caebe352..0000000000 --- a/cpp/examples/xml-exchange/README.txt +++ /dev/null @@ -1,53 +0,0 @@ -This example shows how to program a simple application -using the XML Exchange. - -[Note: The XML Exchange is not a standard AMQP exchange type. To run -this example you need to have a broker that has support for the xml -exchange. If you are compiling the broker from source please refer to -the INSTALL notes from qpid.] - -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/cpp/examples/xml-exchange/declare_queues.cpp b/cpp/examples/xml-exchange/declare_queues.cpp deleted file mode 100644 index ad08642019..0000000000 --- a/cpp/examples/xml-exchange/declare_queues.cpp +++ /dev/null @@ -1,98 +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 is one of three programs used to implement XML-based content - * routing in C++. - * - * declare_queues.cpp (this program) - * - * Creates a queue named "message_qaueue" on the broker, - * declares an XML Exchange, subscribes the queue to the XML - * Exchange using an XQuery in the binding, then exits. - * - * xml_producer.cpp - * - * Publishes messages to the XML Exchange. - * - * listener.cpp - * - * Reads messages from the "message_queue" queue. - */ - -#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="content_feed", arg::arguments=binding); - - //----------------------------------------------------------------------------- - - connection.close(); - return 0; - } catch(const std::exception& error) { - std::cout << error.what() << std::endl; - } - return 1; - -} - - - diff --git a/cpp/examples/xml-exchange/listener.cpp b/cpp/examples/xml-exchange/listener.cpp deleted file mode 100644 index 11bcb9f669..0000000000 --- a/cpp/examples/xml-exchange/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 is one of three programs used to implement XML-based content - * routing in C++. - * - * declare_queues.cpp - * - * Creates a queue named "message_qaueue" on the broker, - * declares an XML Exchange, subscribes the queue to the XML - * Exchange using an XQuery in the binding, then exits. - * - * xml_producer.cpp - * - * Publishes messages to the XML Exchange. - * - * listener.cpp (this program) - * - * Reads messages from the "message_queue" queue. - */ - - -#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().getAsString("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; - 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/cpp/examples/xml-exchange/xml_producer.cpp b/cpp/examples/xml-exchange/xml_producer.cpp deleted file mode 100644 index af1a7e60c7..0000000000 --- a/cpp/examples/xml-exchange/xml_producer.cpp +++ /dev/null @@ -1,113 +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. - * - */ - - -/** - * - * xml_producer.cpp - * - * This is one of three programs used to implement XML-based content - * routing in C++. - * - * declare_queues.cpp - * - * Creates a queue named "message_qaueue" on the broker, - * declares an XML Exchange, subscribes the queue to the XML - * Exchange using an XQuery in the binding, then exits. - * - * xml_producer.cpp (this program) - * - * Publishes messages to the XML Exchange. - * - * listener.cpp - * - * Reads messages from the "message_queue" queue. - */ - - -#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("content_feed"); - 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