summaryrefslogtreecommitdiff
path: root/qpid/cpp/examples/pub-sub/topic_publisher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/examples/pub-sub/topic_publisher.cpp')
-rw-r--r--qpid/cpp/examples/pub-sub/topic_publisher.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/qpid/cpp/examples/pub-sub/topic_publisher.cpp b/qpid/cpp/examples/pub-sub/topic_publisher.cpp
index d11e807259..8186c5d5bb 100644
--- a/qpid/cpp/examples/pub-sub/topic_publisher.cpp
+++ b/qpid/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);
//-----------------------------------------------------------------------------