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/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 + 10 files changed, 1592 insertions(+) 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 (limited to 'cpp/examples/old_api/direct') 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 -- cgit v1.2.1