diff options
author | Ted Ross <tross@apache.org> | 2008-10-24 00:45:11 +0000 |
---|---|---|
committer | Ted Ross <tross@apache.org> | 2008-10-24 00:45:11 +0000 |
commit | 55c976dbede7ada5dbcc581945f7d5b1a038344c (patch) | |
tree | ade284127ba75103b85d5b431bed78c500896af8 /cpp/examples/pub-sub | |
parent | bd0c16218e3ccc75ce997ba9f0806c27e6468085 (diff) | |
download | qpid-python-55c976dbede7ada5dbcc581945f7d5b1a038344c.tar.gz |
QPID-1348 - Dynamic binding for federation. Parameterized exchange names for CPP examples
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@707515 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/examples/pub-sub')
-rw-r--r-- | cpp/examples/pub-sub/topic_listener.cpp | 19 | ||||
-rw-r--r-- | cpp/examples/pub-sub/topic_publisher.cpp | 19 |
2 files changed, 20 insertions, 18 deletions
diff --git a/cpp/examples/pub-sub/topic_listener.cpp b/cpp/examples/pub-sub/topic_listener.cpp index 9996abab19..af70cc2672 100644 --- a/cpp/examples/pub-sub/topic_listener.cpp +++ b/cpp/examples/pub-sub/topic_listener.cpp @@ -61,7 +61,7 @@ class Listener : public MessageListener { SubscriptionManager subscriptions; public: Listener(Session& session); - virtual void prepareQueue(std::string queue, std::string routing_key); + virtual void prepareQueue(std::string queue, std::string exchange, std::string routing_key); virtual void received(Message& message); virtual void listen(); ~Listener() { }; @@ -84,7 +84,7 @@ Listener::Listener(Session& session) : } -void Listener::prepareQueue(std::string queue, std::string routing_key) { +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. @@ -106,8 +106,8 @@ void Listener::prepareQueue(std::string queue, std::string routing_key) { * "control" routing key, when it is finished. */ - session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey=routing_key); - session.exchangeBind(arg::exchange="amq.topic", arg::queue=queue, arg::bindingKey="control"); + 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. @@ -134,6 +134,7 @@ void Listener::listen() { 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); @@ -147,12 +148,12 @@ int main(int argc, char** argv) { // Subscribe to messages on the queues we are interested in - listener.prepareQueue("usa", "usa.#"); - listener.prepareQueue("europe", "europe.#"); - listener.prepareQueue("news", "#.news"); - listener.prepareQueue("weather", "#.weather"); + 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; + std::cout << "Listening for messages ..." << std::endl; // Give up control and receive messages listener.listen(); diff --git a/cpp/examples/pub-sub/topic_publisher.cpp b/cpp/examples/pub-sub/topic_publisher.cpp index ab485fec8f..d11e807259 100644 --- a/cpp/examples/pub-sub/topic_publisher.cpp +++ b/cpp/examples/pub-sub/topic_publisher.cpp @@ -60,7 +60,7 @@ using namespace qpid::framing; using std::stringstream; using std::string; -void publish_messages(Session& session, string routing_key) +void publish_messages(Session& session, string exchange, string routing_key) { Message message; @@ -75,7 +75,7 @@ void publish_messages(Session& session, 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="amq.topic"); + async(session).messageTransfer(arg::content=message, arg::destination=exchange); } } @@ -88,18 +88,19 @@ void publish_messages(Session& session, string routing_key) * */ -void no_more_messages(Session& session) +void no_more_messages(Session& session, string exchange) { Message message; message.getDeliveryProperties().setRoutingKey("control"); message.setData("That's all, folks!"); - session.messageTransfer(arg::content=message, arg::destination="amq.topic"); + session.messageTransfer(arg::content=message, arg::destination=exchange); } 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 { @@ -108,12 +109,12 @@ int main(int argc, char** argv) { //--------- Main body of program -------------------------------------------- - publish_messages(session, "usa.news"); - publish_messages(session, "usa.weather"); - publish_messages(session, "europe.news"); - publish_messages(session, "europe.weather"); + publish_messages(session, exchange, "usa.news"); + publish_messages(session, exchange, "usa.weather"); + publish_messages(session, exchange, "europe.news"); + publish_messages(session, exchange, "europe.weather"); - no_more_messages(session); + no_more_messages(session, exchange); //----------------------------------------------------------------------------- |