diff options
author | Carl C. Trieloff <cctrieloff@apache.org> | 2008-11-10 17:05:41 +0000 |
---|---|---|
committer | Carl C. Trieloff <cctrieloff@apache.org> | 2008-11-10 17:05:41 +0000 |
commit | f6f56f56ebb092d8808119a66ced9fcd0399b238 (patch) | |
tree | 3c38eba69b014d53a62f20f92722bed6c1b547d0 | |
parent | c238bdf224cb3ba37c5fb2de06da7f41e98545a2 (diff) | |
download | qpid-python-f6f56f56ebb092d8808119a66ced9fcd0399b238.tar.gz |
QPID-1445 patch from Jonathan
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@712699 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | cpp/examples/direct/declare_queues.cpp | 23 | ||||
-rw-r--r-- | cpp/examples/direct/direct_producer.cpp | 24 | ||||
-rw-r--r-- | cpp/examples/direct/listener.cpp | 23 | ||||
-rw-r--r-- | cpp/examples/fanout/fanout_producer.cpp | 25 | ||||
-rw-r--r-- | cpp/examples/fanout/listener.cpp | 26 | ||||
-rw-r--r-- | cpp/examples/pub-sub/topic_listener.cpp | 23 | ||||
-rw-r--r-- | cpp/examples/pub-sub/topic_publisher.cpp | 44 | ||||
-rw-r--r-- | cpp/examples/request-response/client.cpp | 28 | ||||
-rw-r--r-- | cpp/examples/request-response/server.cpp | 28 | ||||
-rw-r--r-- | cpp/examples/xml-exchange/declare_queues.cpp | 25 | ||||
-rw-r--r-- | cpp/examples/xml-exchange/listener.cpp | 23 | ||||
-rw-r--r-- | cpp/examples/xml-exchange/xml_producer.cpp | 25 |
12 files changed, 230 insertions, 87 deletions
diff --git a/cpp/examples/direct/declare_queues.cpp b/cpp/examples/direct/declare_queues.cpp index 3289efb872..07e34007a4 100644 --- a/cpp/examples/direct/declare_queues.cpp +++ b/cpp/examples/direct/declare_queues.cpp @@ -19,24 +19,28 @@ * */ + /** * declare_queues.cpp * * This program is one of three programs designed to be used - * together. These programs use the "amq.direct" exchange. + * together. * - * direct_config_queues.cpp (this program): + * declare_queues.cpp: (this program): * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. + * 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: + * direct_producer.cpp * - * Publishes to a broker, specifying a routing key. + * Publishes to the "amq.direct" exchange, specifying the routing + * key "routing_key" * - * listener.cpp + * listener.cpp * - * Reads from a queue on the broker using a message listener. + * Reads from the "message_queue" queue on the broker using a + * message listener. * */ @@ -56,7 +60,6 @@ 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; - string exchange(argc>3 ? argv[3] : "amq.direct"); Connection connection; try { @@ -70,7 +73,7 @@ int main(int argc, char** argv) { // routing key is "routing_key" to this newly created queue. session.queueDeclare(arg::queue="message_queue"); - session.exchangeBind(arg::exchange=exchange, arg::queue="message_queue", arg::bindingKey="routing_key"); + session.exchangeBind(arg::exchange="amq.direct", arg::queue="message_queue", arg::bindingKey="routing_key"); //----------------------------------------------------------------------------- diff --git a/cpp/examples/direct/direct_producer.cpp b/cpp/examples/direct/direct_producer.cpp index 9ea3c812a6..8719fa263f 100644 --- a/cpp/examples/direct/direct_producer.cpp +++ b/cpp/examples/direct/direct_producer.cpp @@ -19,26 +19,27 @@ * */ - /** * direct_producer.cpp: * * This program is one of three programs designed to be used - * together. These programs do not specify the exchange type - the - * default exchange type is the direct exchange. + * together. * * create_queues.cpp: * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. + * 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 a broker, specifying a routing key. + * Publishes to the "amq.direct" exchange, specifying the routing + * key "routing_key" * * listener.cpp * - * Reads from a queue on the broker using a message listener. + * Reads from the "message_queue" queue on the broker using a + * message listener. * */ @@ -65,7 +66,7 @@ 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; - string exchange(argc>4 ? argv[4] : "amq.direct"); + Connection connection; Message message; try { @@ -88,16 +89,13 @@ int main(int argc, char** argv) { 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=exchange); - session.messageTransfer(arg::content=message, arg::destination=exchange); + session.messageTransfer(arg::content=message, arg::destination="amq.direct"); } // And send a final message to indicate termination. message.setData("That's all, folks!"); - session.messageTransfer(arg::content=message, arg::destination=exchange); + session.messageTransfer(arg::content=message, arg::destination="amq.direct"); //----------------------------------------------------------------------------- diff --git a/cpp/examples/direct/listener.cpp b/cpp/examples/direct/listener.cpp index d199b5c0bb..5fe7138f1e 100644 --- a/cpp/examples/direct/listener.cpp +++ b/cpp/examples/direct/listener.cpp @@ -20,10 +20,29 @@ */ /** - * listener.cpp: This program reads messages from a queue on - * the broker using a message listener. + * listener.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 + * + * Publishes to the "amq.direct" exchange, specifying the routing + * key "routing_key" + * + * listener.cpp (this program): + * + * Reads from the "message_queue" queue on the broker using a + * message listener. */ + #include <qpid/client/Connection.h> #include <qpid/client/Session.h> #include <qpid/client/Message.h> diff --git a/cpp/examples/fanout/fanout_producer.cpp b/cpp/examples/fanout/fanout_producer.cpp index bb253d7027..18338717b9 100644 --- a/cpp/examples/fanout/fanout_producer.cpp +++ b/cpp/examples/fanout/fanout_producer.cpp @@ -23,22 +23,21 @@ /** * fanout_producer.cpp: * - * This program is one of three programs designed to be used - * together. These programs do not specify the exchange type - the - * default exchange type is the direct exchange. - * - * declare_queues.cpp: - * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. + * This program is one of two programs designed to be used + * together. * * fanout_producer.cpp (this program): * - * Publishes to a broker, specifying a routing key. + * Publishes messages to the "amq.fanout" exchange. * * listener.cpp * - * Reads from a queue on the broker using a message listener. + * 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. * */ @@ -64,7 +63,7 @@ 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; - string exchange = argc>3 ? argv[3] : "amq.fanout"; + Connection connection; Message message; try { @@ -87,13 +86,13 @@ int main(int argc, char** argv) { 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=exchange); + 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=exchange); + session.messageTransfer(arg::content=message, arg::destination="amq.fanout"); //----------------------------------------------------------------------------- diff --git a/cpp/examples/fanout/listener.cpp b/cpp/examples/fanout/listener.cpp index 2938125f4b..dd9bf3c7ba 100644 --- a/cpp/examples/fanout/listener.cpp +++ b/cpp/examples/fanout/listener.cpp @@ -19,11 +19,29 @@ * */ + /** - * listener.cpp: This program reads messages fro a queue on - * the broker using a message listener. + * 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> @@ -60,7 +78,7 @@ void Listener::received(Message& message) { 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; - string exchange = argc>3 ? argv[3] : "amq.fanout"; + Connection connection; Message msg; try { @@ -83,7 +101,7 @@ int main(int argc, char** argv) { session.queueDeclare(arg::queue=myQueue, arg::exclusive=true, arg::autoDelete=true); - session.exchangeBind(arg::exchange=exchange, arg::queue=myQueue, arg::bindingKey="my-key"); + 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); diff --git a/cpp/examples/pub-sub/topic_listener.cpp b/cpp/examples/pub-sub/topic_listener.cpp index af70cc2672..14c5777bfc 100644 --- a/cpp/examples/pub-sub/topic_listener.cpp +++ b/cpp/examples/pub-sub/topic_listener.cpp @@ -22,21 +22,24 @@ /** * topic_listener.cpp: * - * This program is one of three programs designed to be used - * together. These programs use the topic exchange. - * - * topic_config_queues.cpp: + * This program is one of two programs designed to be used + * together. These programs implement a publish-subscribe example + * using the "amq.topic" exchange. * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. + * topic_publisher.cpp * - * topic_publisher.cpp: + * Sends messages to the "amq.topic" exchange, using the + * multipart routing keys "usa.news", "usa.weather", + * "europe.news", and "europe.weather". * - * Publishes to a broker, specifying a routing key. + * topic_listener.cpp (this program) * - * 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. * - * Reads from a queue on the broker using a message listener. + * Multiple listeners can be run at the same time. * */ diff --git a/cpp/examples/pub-sub/topic_publisher.cpp b/cpp/examples/pub-sub/topic_publisher.cpp index d11e807259..8186c5d5bb 100644 --- a/cpp/examples/pub-sub/topic_publisher.cpp +++ b/cpp/examples/pub-sub/topic_publisher.cpp @@ -19,25 +19,27 @@ * */ - /** * topic_publisher.cpp: * - * This program is one of three programs designed to be used - * together. These programs use the topic exchange. - * - * topic_config_queues.cpp: + * This program is one of two programs designed to be used + * together. These programs implement a publish-subscribe example + * using the "amq.topic" exchange. * - * Creates a queue on a broker, binding a routing key to route - * messages to that queue. + * topic_publisher.cpp (this program) * - * 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". * - * Publishes to a broker, specifying a routing key. + * topic_listener.cpp * - * 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. * - * Reads from a queue on the broker using a message listener. + * Multiple listeners can be run at the same time. * */ @@ -60,7 +62,7 @@ using namespace qpid::framing; using std::stringstream; using std::string; -void publish_messages(Session& session, string exchange, string routing_key) +void publish_messages(Session& session, string routing_key) { Message message; @@ -75,7 +77,7 @@ void publish_messages(Session& session, string exchange, string routing_key) 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=exchange); + async(session).messageTransfer(arg::content=message, arg::destination="amq.topic"); } } @@ -88,19 +90,19 @@ void publish_messages(Session& session, string exchange, string routing_key) * */ -void no_more_messages(Session& session, string exchange) +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=exchange); + 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; - std::string exchange = argc>3 ? argv[3] : "amq.topic"; + Connection connection; Message message; try { @@ -109,12 +111,12 @@ int main(int argc, char** argv) { //--------- Main body of program -------------------------------------------- - publish_messages(session, exchange, "usa.news"); - publish_messages(session, exchange, "usa.weather"); - publish_messages(session, exchange, "europe.news"); - publish_messages(session, exchange, "europe.weather"); + publish_messages(session, "usa.news"); + publish_messages(session, "usa.weather"); + publish_messages(session, "europe.news"); + publish_messages(session, "europe.weather"); - no_more_messages(session, exchange); + no_more_messages(session); //----------------------------------------------------------------------------- diff --git a/cpp/examples/request-response/client.cpp b/cpp/examples/request-response/client.cpp index 0ee0e78c92..aace2109fa 100644 --- a/cpp/examples/request-response/client.cpp +++ b/cpp/examples/request-response/client.cpp @@ -26,14 +26,32 @@ * This program is one of two programs that illustrate the * request/response pattern. * - * client.cpp (this program) * - * Make requests of a service, print the response. + * 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. * - * service.cpp + * 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. * - * Accept requests, reverse the letters in each message, and - * return it as a response. * */ diff --git a/cpp/examples/request-response/server.cpp b/cpp/examples/request-response/server.cpp index df189cfdd8..fb3b78d47b 100644 --- a/cpp/examples/request-response/server.cpp +++ b/cpp/examples/request-response/server.cpp @@ -26,14 +26,32 @@ * This program is one of two programs that illustrate the * request/response pattern. * - * client.cpp * - * Make requests of a service, print the response. + * client.cpp + * + * A client application that sends messages to the "amq.direct" + * exchange, using the routing key "request" to route messages to + * the server. * - * server.cpp (this program) + * 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. * - * Accept requests, reverse the letters in each message, and - * return it as a response. * */ diff --git a/cpp/examples/xml-exchange/declare_queues.cpp b/cpp/examples/xml-exchange/declare_queues.cpp index 1307c473c5..d3a0f539b6 100644 --- a/cpp/examples/xml-exchange/declare_queues.cpp +++ b/cpp/examples/xml-exchange/declare_queues.cpp @@ -19,6 +19,29 @@ * */ + +/** + * + * 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 <qpid/client/Connection.h> #include <qpid/client/Session.h> @@ -59,7 +82,7 @@ int main(int argc, char** argv) { FieldTable binding; binding.setString("xquery", "declare variable $control external;" "./message/id mod 2 = 1 or $control = 'end'"); - session.exchangeBind(arg::exchange="xml", arg::queue="message_queue", arg::bindingKey="query_name", arg::arguments=binding); + session.exchangeBind(arg::exchange="xml", arg::queue="message_queue", arg::bindingKey="content_feed", arg::arguments=binding); //----------------------------------------------------------------------------- diff --git a/cpp/examples/xml-exchange/listener.cpp b/cpp/examples/xml-exchange/listener.cpp index 94cd1670e5..2c9a1e7a55 100644 --- a/cpp/examples/xml-exchange/listener.cpp +++ b/cpp/examples/xml-exchange/listener.cpp @@ -19,11 +19,30 @@ * */ + /** - * listener.cpp: This program reads messages fro a queue on - * the broker using a message listener. + * + * 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 <qpid/client/Connection.h> #include <qpid/client/Session.h> #include <qpid/client/Message.h> diff --git a/cpp/examples/xml-exchange/xml_producer.cpp b/cpp/examples/xml-exchange/xml_producer.cpp index 19889e4891..5cb75d0087 100644 --- a/cpp/examples/xml-exchange/xml_producer.cpp +++ b/cpp/examples/xml-exchange/xml_producer.cpp @@ -20,6 +20,29 @@ */ +/** + * + * 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 <qpid/client/Connection.h> #include <qpid/client/Session.h> #include <qpid/client/AsyncSession.h> @@ -55,7 +78,7 @@ int main(int argc, char** argv) { // In the XML exchange, the routing key and the name of // the query match. - message.getDeliveryProperties().setRoutingKey("query_name"); + message.getDeliveryProperties().setRoutingKey("content_feed"); message.getHeaders().setString("control","continue"); // Now send some messages ... |