summaryrefslogtreecommitdiff
path: root/RC9/qpid/cpp/examples/fanout
diff options
context:
space:
mode:
Diffstat (limited to 'RC9/qpid/cpp/examples/fanout')
-rw-r--r--RC9/qpid/cpp/examples/fanout/Makefile.am47
-rw-r--r--RC9/qpid/cpp/examples/fanout/fanout_producer.cpp106
-rw-r--r--RC9/qpid/cpp/examples/fanout/listener.cpp126
-rw-r--r--RC9/qpid/cpp/examples/fanout/verify25
-rw-r--r--RC9/qpid/cpp/examples/fanout/verify.in43
-rw-r--r--RC9/qpid/cpp/examples/fanout/verify_cpp_python7
-rw-r--r--RC9/qpid/cpp/examples/fanout/verify_cpp_python.in27
-rw-r--r--RC9/qpid/cpp/examples/fanout/verify_python_cpp7
-rw-r--r--RC9/qpid/cpp/examples/fanout/verify_python_cpp.in29
9 files changed, 417 insertions, 0 deletions
diff --git a/RC9/qpid/cpp/examples/fanout/Makefile.am b/RC9/qpid/cpp/examples/fanout/Makefile.am
new file mode 100644
index 0000000000..6cbf2c93ad
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/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/fanout
+
+include $(top_srcdir)/examples/makedist.mk
+
+noinst_PROGRAMS=fanout_producer listener
+fanout_producer_SOURCES=fanout_producer.cpp
+fanout_producer_LDADD=$(CLIENT_LIB)
+
+listener_SOURCES=listener.cpp
+listener_LDADD=$(CLIENT_LIB)
+
+examples_DATA= \
+ fanout_producer.cpp \
+ listener.cpp \
+ $(MAKEDIST)
+
+EXTRA_DIST= \
+ $(examples_DATA) \
+ verify \
+ verify.in \
+ verify_cpp_python \
+ verify_cpp_python.in \
+ verify_python_cpp \
+ verify_python_cpp.in
+
+
+
+
+
diff --git a/RC9/qpid/cpp/examples/fanout/fanout_producer.cpp b/RC9/qpid/cpp/examples/fanout/fanout_producer.cpp
new file mode 100644
index 0000000000..fb16f7e8b1
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/fanout_producer.cpp
@@ -0,0 +1,106 @@
+/*
+ *
+ * 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 <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/AsyncSession.h>
+#include <qpid/client/Message.h>
+
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+#include <sstream>
+
+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/RC9/qpid/cpp/examples/fanout/listener.cpp b/RC9/qpid/cpp/examples/fanout/listener.cpp
new file mode 100644
index 0000000000..b6050ef728
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/listener.cpp
@@ -0,0 +1,126 @@
+/*
+ *
+ * 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 <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/Message.h>
+#include <qpid/client/MessageListener.h>
+#include <qpid/client/SubscriptionManager.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+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/RC9/qpid/cpp/examples/fanout/verify b/RC9/qpid/cpp/examples/fanout/verify
new file mode 100644
index 0000000000..2eaadff56b
--- /dev/null
+++ b/RC9/qpid/cpp/examples/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/RC9/qpid/cpp/examples/fanout/verify.in b/RC9/qpid/cpp/examples/fanout/verify.in
new file mode 100644
index 0000000000..8f8612ce67
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/verify.in
@@ -0,0 +1,43 @@
+==== fanout_producer.out
+==== listener.out | remove_uuid
+Listening
+Message: Message 0
+Message: Message 1
+Message: Message 2
+Message: Message 3
+Message: Message 4
+Message: Message 5
+Message: Message 6
+Message: Message 7
+Message: Message 8
+Message: Message 9
+Message: That's all, folks!
+Shutting down listener for
+==== listenerX.out | remove_uuid
+Listening
+Message: Message 0
+Message: Message 1
+Message: Message 2
+Message: Message 3
+Message: Message 4
+Message: Message 5
+Message: Message 6
+Message: Message 7
+Message: Message 8
+Message: Message 9
+Message: That's all, folks!
+Shutting down listener for
+==== listenerXX.out | remove_uuid
+Listening
+Message: Message 0
+Message: Message 1
+Message: Message 2
+Message: Message 3
+Message: Message 4
+Message: Message 5
+Message: Message 6
+Message: Message 7
+Message: Message 8
+Message: Message 9
+Message: That's all, folks!
+Shutting down listener for
diff --git a/RC9/qpid/cpp/examples/fanout/verify_cpp_python b/RC9/qpid/cpp/examples/fanout/verify_cpp_python
new file mode 100644
index 0000000000..6a1ba7ad7d
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/verify_cpp_python
@@ -0,0 +1,7 @@
+# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify
+py=$PYTHON_EXAMPLES/fanout
+background "Subscribed" $py/fanout_consumer.py
+background "Subscribed" $py/fanout_consumer.py
+clients ./fanout_producer
+outputs ./fanout_producer.out "$py/fanout_consumer.py.out | remove_uuid" "$py/fanout_consumer.pyX.out | remove_uuid"
+
diff --git a/RC9/qpid/cpp/examples/fanout/verify_cpp_python.in b/RC9/qpid/cpp/examples/fanout/verify_cpp_python.in
new file mode 100644
index 0000000000..21bafe06de
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/verify_cpp_python.in
@@ -0,0 +1,27 @@
+==== fanout_producer.out
+==== fanout_consumer.py.out | remove_uuid
+Subscribed to queue
+Message 0
+Message 1
+Message 2
+Message 3
+Message 4
+Message 5
+Message 6
+Message 7
+Message 8
+Message 9
+That's all, folks!
+==== fanout_consumer.pyX.out | remove_uuid
+Subscribed to queue
+Message 0
+Message 1
+Message 2
+Message 3
+Message 4
+Message 5
+Message 6
+Message 7
+Message 8
+Message 9
+That's all, folks!
diff --git a/RC9/qpid/cpp/examples/fanout/verify_python_cpp b/RC9/qpid/cpp/examples/fanout/verify_python_cpp
new file mode 100644
index 0000000000..d9b3361523
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/verify_python_cpp
@@ -0,0 +1,7 @@
+# See https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/bin/verify
+py=$PYTHON_EXAMPLES/fanout
+background "Listening" ./listener
+background "Listening" ./listener
+clients $py/fanout_producer.py
+outputs $py/fanout_producer.py.out "./listener.out | remove_uuid" "./listenerX.out | remove_uuid"
+
diff --git a/RC9/qpid/cpp/examples/fanout/verify_python_cpp.in b/RC9/qpid/cpp/examples/fanout/verify_python_cpp.in
new file mode 100644
index 0000000000..8f9e959053
--- /dev/null
+++ b/RC9/qpid/cpp/examples/fanout/verify_python_cpp.in
@@ -0,0 +1,29 @@
+==== fanout_producer.py.out
+==== listener.out | remove_uuid
+Listening
+Message: message 0
+Message: message 1
+Message: message 2
+Message: message 3
+Message: message 4
+Message: message 5
+Message: message 6
+Message: message 7
+Message: message 8
+Message: message 9
+Message: That's all, folks!
+Shutting down listener for
+==== listenerX.out | remove_uuid
+Listening
+Message: message 0
+Message: message 1
+Message: message 2
+Message: message 3
+Message: message 4
+Message: message 5
+Message: message 6
+Message: message 7
+Message: message 8
+Message: message 9
+Message: That's all, folks!
+Shutting down listener for