qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r593402 - in /incubator/qpid/trunk/qpid/cpp: examples/ examples/direct/ examples/fanout/ examples/pub-sub/ examples/request-response/ src/qpid/client/
Date Fri, 09 Nov 2007 02:38:35 GMT
Author: aconway
Date: Thu Nov  8 18:38:33 2007
New Revision: 593402

URL: http://svn.apache.org/viewvc?rev=593402&view=rev
Log:

QPID-676: Jonathan Robie's C++ examples.
Made the following alterations for recent C++ API changes:
 - use arg:: namespace for Session keyword arguments.
 - removed trailing _ on session method names.

cpp/examples/Makefile.am calls make in each example directory with
flags to build examples from headers/libraries SVN checkout.

Examples themselves have a plain Makefile (not automake) which will
work as is if qpid is installed in standard places.

Added:
    incubator/qpid/trunk/qpid/cpp/examples/direct/
    incubator/qpid/trunk/qpid/cpp/examples/direct/Makefile   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/direct/direct_config_queues.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_config_queues.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_publisher.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/direct/direct_publisher.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/direct/listener.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/fanout/   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/fanout/Makefile   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_config_queues.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_consumer.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_publisher.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/fanout/listener.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/pub-sub/   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/pub-sub/Makefile   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_config_queues.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_listener.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_publisher.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/request-response/   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/request-response/Makefile   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/request-response/client.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/examples/request-response/server.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h   (with props)
Removed:
    incubator/qpid/trunk/qpid/cpp/examples/topic_listener.cpp
    incubator/qpid/trunk/qpid/cpp/examples/topic_publisher.cpp

Added: incubator/qpid/trunk/qpid/cpp/examples/direct/Makefile
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/direct/Makefile?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/direct/Makefile (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/direct/Makefile Thu Nov  8 18:38:33 2007
@@ -0,0 +1,20 @@
+CXX=g++
+CXXFLAGS= 
+
+PROGRAMS=direct_config_queues listener direct_publisher direct_persistent_publisher
+all: $(PROGRAMS)
+
+direct_config_queues: direct_config_queues.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+listener: listener.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+direct_publisher: direct_publisher.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+direct_persistent_publisher: direct_persistent_publisher.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+clean:
+	rm -f $(PROGRAMS) 

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_config_queues.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/direct/direct_config_queues.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/direct/direct_config_queues.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/direct/direct_config_queues.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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_config_queues.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.
+ *  
+ *  direct_config_queues.cpp (this program):
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *  direct_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *  direct_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+using std::string;
+
+
+int main() {
+    Connection connection;
+    Message msg;
+    try {
+      connection.open("127.0.0.1", 5672);
+      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.queueBind(arg::queue="message_queue", arg::routingKey="routing_key");
+
+
+  //-----------------------------------------------------------------------------
+
+      connection.close();
+      return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+   
+}
+
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_config_queues.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_config_queues.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_config_queues.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_config_queues.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_config_queues.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_config_queues.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,101 @@
+/*
+ *
+ * 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_config_durable_queues.cpp
+ *
+ *  This program is one of a set of programs designed to be used
+ *  together. These programs do not specify the exchange type - the
+ *  default exchange type is the direct exchange.
+ *
+ *    direct_config_queues.cpp:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ * 
+ *  direct_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *  direct_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ *  direct_persistent_publisher.cpp:
+ *
+ *      Publishes a combination of persistent and transient messages
+ *      to a broker, specifying a routing key. The persistent messages
+ *      survive server restart, the transient ones do not (unless the
+ *      queues are configured as durable queues).
+ *
+ *  direct_config_durable_queues.cpp (this program):
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue. Uses persistent queues, so all
+ *      messages on the queue survive server restart.
+ *
+ *
+ */
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+using std::string;
+
+
+int main() {
+    Connection connection;
+    Message msg;
+    try {
+      connection.open("127.0.0.1", 5672);
+      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.queueBind(arg::queue="message_queue", arg::routingKey="routing_key");
+
+
+  //-----------------------------------------------------------------------------
+
+      connection.close();
+      return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+   
+}
+
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_config_queues.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_config_queues.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_publisher.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_publisher.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_publisher.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_publisher.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,111 @@
+/*
+ *
+ * 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_publisher.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.
+ *  
+ *    direct_config_queues.cpp:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    direct_publisher.cpp (this program):
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    direct_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.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() {
+    Connection connection;
+    Message message;
+    try {
+        connection.open("127.0.0.1", 5672 );
+        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.getDeliveryProperties().setRoutingKey("routing_key"); 
+
+	// Now send some messages ...
+
+	for (int i=0; i<10; i++) {
+	  stringstream message_data;
+	  message_data << "Message " << i;
+	  message.setData(message_data.str());
+
+	  // Make odd-numbered messages persistent
+
+	  if (i % 1)
+	    message.getDeliveryProperties().setDeliveryMode(PERSISTENT);
+	  else
+	    message.getDeliveryProperties().setDeliveryMode(TRANSIENT);
+
+          session.messageTransfer(arg::content=message);
+	}
+	
+	// And send a final message to indicate termination.
+
+	message.setData("That's all, folks!");
+        session.messageTransfer(arg::content=message); 
+
+  //-----------------------------------------------------------------------------
+
+        connection.close();
+        return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_publisher.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_persistent_publisher.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_publisher.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/direct/direct_publisher.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/direct/direct_publisher.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/direct/direct_publisher.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,104 @@
+/*
+ *
+ * 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_publisher.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.
+ *  
+ *    direct_config_queues.cpp:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    direct_publisher.cpp (this program):
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    direct_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.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() {
+    Connection connection;
+    Message message;
+    try {
+        connection.open("127.0.0.1", 5672 );
+        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.getDeliveryProperties().setRoutingKey("routing_key"); 
+
+	// Now send some messages ...
+
+	for (int i=0; i<10; i++) {
+	  stringstream message_data;
+	  message_data << "Message " << i;
+
+	  message.setData(message_data.str());
+          session.messageTransfer(arg::content=message);
+	}
+	
+	// And send a final message to indicate termination.
+
+	message.setData("That's all, folks!");
+        session.messageTransfer(arg::content=message); 
+
+  //-----------------------------------------------------------------------------
+
+        connection.close();
+        return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_publisher.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/direct_publisher.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/direct/listener.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/direct/listener.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/direct/listener.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/direct/listener.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,134 @@
+/*
+ *
+ * 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_listener.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.
+ *  
+ *    direct_config_queues.cpp:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    direct_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    direct_listener.cpp (this program):
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+#include <qpid/client/Dispatcher.h>
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/Message.h>
+#include <qpid/client/MessageListener.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+      
+class Listener : public MessageListener{
+private:
+  std::string destination_name;
+  Dispatcher dispatcher;
+public:
+  Listener(Session& session, string destination_name): 
+    destination_name(destination_name),
+    dispatcher(session)
+  {};
+
+  virtual void listen();
+  virtual void received(Message& message);
+  ~Listener() { };
+};
+
+
+void Listener::listen() {
+  std::cout << "Activating listener for: " <<destination_name << std::endl;
+  dispatcher.listen(destination_name, this);
+
+  // ### The following line gives up control - it should be possible
+  // ### to listen without giving up control!
+
+  dispatcher.run();
+}
+
+
+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 " <<destination_name << std::endl;
+      dispatcher.stop();
+  }
+}
+
+
+
+int main() {
+    Connection connection;
+    Message msg;
+    try {
+      connection.open("127.0.0.1", 5672);
+      Session session =  connection.newSession();
+
+  //--------- Main body of program --------------------------------------------
+
+
+      //  Subscribe to the queue, route it to a client destination for
+      //  the  listener. (The destination  name merely  identifies the
+      //  destination in the listener, you can use any name as long as
+      //  you use the same name for the listener).
+
+      session.messageSubscribe(arg::queue="message_queue", arg::destination="listener_destination");
+
+      //  Allocate some credit ### This really should not be needed for simple examples ! ####
+
+      session.messageFlow(arg::destination="listener_destination", arg::unit=0, arg::value=1);//messages ### Define a constant?
+      session.messageFlow(arg::destination="listener_destination", arg::unit=1, arg::value=0xFFFFFFFF);//bytes ###### Define a constant?
+
+      //  Tell the listener to listen to the destination we just
+      //  created above.
+
+      Listener listener(session, "listener_destination");
+      listener.listen();
+
+  //-----------------------------------------------------------------------------
+
+      connection.close();
+      return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;   
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/listener.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/direct/listener.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov  8 18:38:33 2007
@@ -0,0 +1,3 @@
+fanout_config_queues
+fanout_publisher
+listener

Added: incubator/qpid/trunk/qpid/cpp/examples/fanout/Makefile
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/fanout/Makefile?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/fanout/Makefile (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/fanout/Makefile Thu Nov  8 18:38:33 2007
@@ -0,0 +1,17 @@
+CXX=g++
+CXXFLAGS= 
+
+PROGRAMS=fanout_config_queues listener fanout_publisher
+all: $(PROGRAMS)
+
+fanout_config_queues: fanout_config_queues.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+listener: listener.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+fanout_publisher: fanout_publisher.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+clean:
+	rm -f $(PROGRAMS) 

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_config_queues.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_config_queues.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_config_queues.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_config_queues.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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_config_queues.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.
+ *  
+ *  direct_config_queues.cpp (this program):
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *  direct_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *  direct_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+using std::string;
+
+
+int main() {
+    Connection connection;
+    Message msg;
+    try {
+      connection.open("127.0.0.1", 5672);
+      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.queueBind(arg::queue="message_queue", arg::exchange="amq.fanout");
+
+
+  //-----------------------------------------------------------------------------
+
+      connection.close();
+      return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+   
+}
+
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_config_queues.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_config_queues.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_consumer.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_consumer.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_consumer.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_consumer.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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_listener.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.
+ *  
+ *    direct_config_queues.cpp:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    direct_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    direct_consumer.cpp (this program):
+ *
+ *      Reads from a queue on the broker using session.get().
+ *
+ *      This is less efficient that direct_listener.cpp, but simpler,
+ *      and can be a better approach when synchronizing messages from
+ *      multiple queues.
+ *
+ */
+
+#include <qpid/client/Dispatcher.h>
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/ClientMessage.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+      
+int main() {
+    Connection connection;
+    Message msg;
+    try {
+      connection.open("127.0.0.1", 5672);
+      Session session =  connection.newSession();
+
+  //--------- Main body of program --------------------------------------------
+
+      Listener listener(session, "destination");
+      ### session.get();
+
+  //-----------------------------------------------------------------------------
+
+      connection.close();
+      return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;   
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_consumer.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_consumer.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_publisher.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_publisher.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_publisher.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_publisher.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,102 @@
+/*
+ *
+ * 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_publisher.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.
+ *  
+ *    direct_config_queues.cpp:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    direct_publisher.cpp (this program):
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    direct_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.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() {
+    Connection connection;
+    Message message;
+    try {
+        connection.open("127.0.0.1", 5672 );
+        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());
+          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;
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_publisher.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/fanout_publisher.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/fanout/listener.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/fanout/listener.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/fanout/listener.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/fanout/listener.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,134 @@
+/*
+ *
+ * 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_listener.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.
+ *  
+ *    direct_config_queues.cpp:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    direct_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    direct_listener.cpp (this program):
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+#include <qpid/client/Dispatcher.h>
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/Message.h>
+#include <qpid/client/MessageListener.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+      
+class Listener : public MessageListener{
+private:
+  std::string destination_name;
+  Dispatcher dispatcher;
+public:
+  Listener(Session& session, string destination_name): 
+    destination_name(destination_name),
+    dispatcher(session)
+  {};
+
+  virtual void listen();
+  virtual void received(Message& message);
+  ~Listener() { };
+};
+
+
+void Listener::listen() {
+  std::cout << "Activating listener for: " <<destination_name << std::endl;
+  dispatcher.listen(destination_name, this);
+
+  // ### The following line gives up control - it should be possible
+  // ### to listen without giving up control!
+
+  dispatcher.run();
+}
+
+
+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 " <<destination_name << std::endl;
+      dispatcher.stop();
+  }
+}
+
+
+
+int main() {
+    Connection connection;
+    Message msg;
+    try {
+      connection.open("127.0.0.1", 5672);
+      Session session =  connection.newSession();
+
+  //--------- Main body of program --------------------------------------------
+
+
+      //  Subscribe to the queue, route it to a client destination for
+      //  the  listener. (The destination  name merely  identifies the
+      //  destination in the listener, you can use any name as long as
+      //  you use the same name for the listener).
+
+      session.messageSubscribe(arg::queue="message_queue", arg::destination="listener_destination");
+
+      //  Allocate some credit ### This really should not be needed for simple examples ! ####
+
+      session.messageFlow(arg::destination="listener_destination", arg::unit=0, arg::value=1);//messages ### Define a constant?
+      session.messageFlow(arg::destination="listener_destination", arg::unit=1, arg::value=0xFFFFFFFF);//bytes ###### Define a constant?
+
+      //  Tell the listener to listen to the destination we just
+      //  created above.
+
+      Listener listener(session, "listener_destination");
+      listener.listen();
+
+  //-----------------------------------------------------------------------------
+
+      connection.close();
+      return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;   
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/listener.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/fanout/listener.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov  8 18:38:33 2007
@@ -0,0 +1,3 @@
+topic_config_queues
+topic_listener
+topic_publisher

Added: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/Makefile
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/pub-sub/Makefile?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/pub-sub/Makefile (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/pub-sub/Makefile Thu Nov  8 18:38:33 2007
@@ -0,0 +1,17 @@
+CXX=g++ 
+CXXFLAGS= 
+
+PROGRAMS=topic_config_queues topic_listener topic_publisher
+all: $(PROGRAMS)
+
+topic_config_queues: topic_config_queues.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+topic_listener: topic_listener.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+topic_publisher: topic_publisher.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+clean:
+	rm -f $(PROGRAMS) 

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_config_queues.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_config_queues.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_config_queues.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_config_queues.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,128 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ *  topic_config_queues.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):
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *  topic_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *  topic_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+using std::string;
+
+
+int main() {
+    Connection connection;
+    Message msg;
+    try {
+      connection.open("127.0.0.1", 5672);
+      Session session =  connection.newSession();
+
+
+  //--------- Main body of program --------------------------------------------
+
+
+      /*  A consumer application reads from the queue, and needs no
+       *  knowledge of the exchanges used to route messages to the
+       *  queue, or of the routing keys.
+       *
+       *  A publisher application writes to the exchange, providing a
+       *  routing key, It needs no knowledge of the queues or bindings
+       *  used to route messages to consumers.
+       */
+
+
+       /* Create queues on the broker. */
+
+      session.queueDeclare(arg::queue="news_queue");
+      session.queueDeclare(arg::queue="weather_queue");
+      session.queueDeclare(arg::queue="usa_queue");
+      session.queueDeclare(arg::queue="europe_queue");
+
+      /* Bind these queues using routing keys, so messages will be
+	 delivered to the right queues. */
+
+      session.queueBind(arg::exchange="amq.topic", arg::queue="news_queue", arg::routingKey="#.news");
+      session.queueBind(arg::exchange="amq.topic", arg::queue="weather_queue", arg::routingKey="#.weather");
+      session.queueBind(arg::exchange="amq.topic", arg::queue="usa_queue", arg::routingKey="usa.#");
+      session.queueBind(arg::exchange="amq.topic", arg::queue="europe_queue", arg::routingKey="europe.#");
+
+
+      /*
+       *  We use a separate 'control' routing key for control
+       *  messages. All such messages are routed to each queue.  In
+       *  this demo, we use a message with the content "That's all,
+       *  Folks!" to signal that no more messages will be sent, and
+       *  users of the queue can stop listening for messages.
+       *
+       *  Because wildcard matching can result in more than one match for
+       *  a given message, it can place more messages on the queues than
+       *  were originally received.
+       *
+       *  We do not use wildcard matching for control messages. We
+       *  want to make sure that each such message is received once
+       *  and only once.
+       */
+
+
+      session.queueBind(arg::exchange="amq.topic", arg::queue="news_queue", arg::routingKey="control");
+      session.queueBind(arg::exchange="amq.topic", arg::queue="weather_queue", arg::routingKey="control");
+      session.queueBind(arg::exchange="amq.topic", arg::queue="usa_queue", arg::routingKey="control");
+      session.queueBind(arg::exchange="amq.topic", arg::queue="europe_queue", arg::routingKey="control");
+
+
+  //-----------------------------------------------------------------------------
+
+      connection.close();
+      return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+   
+}
+
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_config_queues.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_config_queues.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_listener.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_listener.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_listener.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_listener.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,169 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/**
+ *  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:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    topic_publisher.cpp:
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    topic_listener.cpp (this program):
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/Message.h>
+#include <qpid/client/MessageListener.h>
+#include <qpid/client/Queue.h>
+#include <qpid/client/SubscriptionManager.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+#include <set>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+
+class Listener : public MessageListener {
+  private:
+    Session& session;
+    SubscriptionManager subscriptions;
+  public:
+    Listener(Session& session);
+    virtual void prepareQueue(std::string queue, std::string routing_key);
+    virtual void received(Message& message);
+    virtual void listen();
+    ~Listener() { };
+};
+
+
+/*
+ *  Listener::Listener
+ *
+ *  Subscribe to the queue, route it to a client destination for the
+ *  listener. (The destination name merely identifies the destination
+ *  in the listener, you can use any name as long as you use the same
+ *  name for the listener).
+ */
+
+Listener::Listener(Session& session) : 
+        session(session),
+        subscriptions(session)
+{
+}
+
+
+void Listener::prepareQueue(std::string queue, std::string routing_key) {
+
+    /* Create a unique queue name for this consumer by concatenating
+     * the queue name parameter with the Session ID.
+     */
+
+    queue += session.getId().str();
+    std::cout << "Declaring queue: " << queue <<  std::endl;
+   
+    /* Declare an exclusive queue on the broker
+     */
+
+    session.queueDeclare(arg::queue=queue, arg::exclusive=true);
+
+    /* Route messages to the new queue if they match the routing key.
+     *
+     * Also route any messages to with the "control" routing key to
+     * this queue so we know when it's time to stop. A publisher sends
+     * a message with the content "That's all, Folks!", using the
+     * "control" routing key, when it is finished.
+     */
+
+    session.queueBind(arg::exchange="amq.topic", arg::queue=queue, arg::routingKey=routing_key);
+    session.queueBind(arg::exchange="amq.topic", arg::queue=queue, arg::routingKey="control");
+
+    /*
+     * subscribe to the queue using the subscription manager.
+     */
+
+    std::cout << "Subscribing to queue " << queue << std::endl;
+    subscriptions.subscribe(*this, queue);
+}
+
+void Listener::received(Message& message) {
+    std::cout << "Message: " << message.getData() << " from " << message.getDestination() << std::endl;
+
+    if (message.getData() == "That's all, folks!") {
+        std::cout << "Shutting down listener for " << message.getDestination() << std::endl;
+        subscriptions.cancel(message.getDestination());
+    }
+}
+
+void Listener::listen() {
+  subscriptions.run();
+}
+
+int main() {
+    Connection connection;
+    try {
+        connection.open("127.0.0.1", 5672);
+        Session session =  connection.newSession();
+
+        //--------- Main body of program --------------------------------------------
+
+	// Create a listener for the session
+
+        Listener listener(session);
+
+        // 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");
+
+	std::cout << "Listening for messages ..." << std::endl;
+
+        // Give up control and receive messages
+        listener.listen();
+
+
+        //-----------------------------------------------------------------------------
+
+        connection.close();
+        return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;   
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_listener.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_listener.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_publisher.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_publisher.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_publisher.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_publisher.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,123 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+
+/**
+ *  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:
+ *
+ *      Creates a queue on a broker, binding a routing key to route
+ *      messages to that queue.
+ *
+ *    topic_publisher.cpp (this program):
+ *
+ *      Publishes to a broker, specifying a routing key.
+ *
+ *    topic_listener.cpp
+ *
+ *      Reads from a queue on the broker using a message listener.
+ *
+ */
+
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Session.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;
+
+void publish_messages(Session& session, string routing_key)
+{
+  Message message;
+
+  // Set the routing key once, we'll use the same routing key for all
+  // messages.
+
+  message.getDeliveryProperties().setRoutingKey(routing_key); 
+  for (int i=0; i<5; i++) {
+    stringstream message_data;
+    message_data << "Message " << i;
+
+    message.setData(message_data.str());
+    session.messageTransfer(arg::content=message, arg::destination="amq.topic");
+  }
+
+}
+
+/*
+ * no_more_messages()
+ * 
+ * Send a message to indicate that no more messages are coming.
+ * Use the 'control' routing key (see comments in topic_config_queues.cpp).
+ *
+ */
+
+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="amq.topic"); 
+}
+
+int main() {
+    Connection connection;
+    Message message;
+    try {
+        connection.open("127.0.0.1", 5672 );
+        Session session =  connection.newSession();
+
+  //--------- Main body of program --------------------------------------------
+
+	publish_messages(session, "usa.news");
+	publish_messages(session, "usa.weather");
+	publish_messages(session, "europe.news");
+	publish_messages(session, "europe.weather");
+
+	no_more_messages(session);
+
+  //-----------------------------------------------------------------------------
+
+        connection.close();
+        return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_publisher.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/pub-sub/topic_publisher.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/qpid/trunk/qpid/cpp/examples/request-response/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov  8 18:38:33 2007
@@ -0,0 +1,2 @@
+client
+server

Added: incubator/qpid/trunk/qpid/cpp/examples/request-response/Makefile
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/request-response/Makefile?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/request-response/Makefile (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/request-response/Makefile Thu Nov  8 18:38:33 2007
@@ -0,0 +1,15 @@
+CXX=g++
+CXXFLAGS= 
+
+PROGRAMS=client server
+all: $(PROGRAMS)
+
+client: client.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+server: server.cpp
+	$(CXX) $(CXXFLAGS) -lqpidclient -o $@ $^
+
+
+clean:
+	rm -f $(PROGRAMS) 

Propchange: incubator/qpid/trunk/qpid/cpp/examples/request-response/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/cpp/examples/request-response/client.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/request-response/client.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/request-response/client.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/request-response/client.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,178 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+
+/**
+ *  client.cpp
+ *
+ *  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.
+ *
+ *    service.cpp
+ *
+ *      Accept requests, reverse the letters in each message, and
+ *      return it as a response.
+ *
+ */
+
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Dispatcher.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/Message.h>
+#include <qpid/client/MessageListener.h>
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+
+#include <sstream>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+
+class Listener : public MessageListener{
+private:
+  Session session;
+  std::string destination_name;
+  Dispatcher dispatcher;
+  int counter;
+public:
+  Listener(Session& session, string destination_name): 
+    destination_name(destination_name),
+    dispatcher(session),
+    session(session),
+    counter(0)
+  {};
+
+  virtual void listen();
+  virtual void wait();
+  virtual void received(Message& message);
+  ~Listener() { };
+};
+
+
+void Listener::listen() {
+  std::cout << "Activating response queue listener for: " <<destination_name << std::endl;
+
+  session.messageSubscribe(arg::queue=destination_name, arg::destination=destination_name);
+
+    // Allocate credit. Sigh. This really should not be required #####
+  session.messageFlow(arg::destination=destination_name, arg::unit=0, arg::value=1);//messages ### Define a constant?
+  session.messageFlow(arg::destination=destination_name, arg::unit=1, arg::value=0xFFFFFFFF);//bytes ###### Define a constant?
+
+
+  dispatcher.listen(destination_name, this);
+}
+
+
+void Listener::wait() {
+  std::cout << "Waiting for all responses to arrive ..." << std::endl;
+  dispatcher.run();
+}
+
+
+void Listener::received(Message& message) {
+  std::cout << "Response: " << message.getData() << std::endl;
+
+  ++ counter;
+  if (counter > 3) {
+      std::cout << "Shutting down listener for " << destination_name << std::endl;
+      dispatcher.stop();
+  }
+}
+
+
+using std::stringstream;
+using std::string;
+
+int main() {
+    Connection connection;
+    Message request;
+    try {
+        connection.open("127.0.0.1", 5672 );
+        Session session =  connection.newSession();
+
+  //--------- Main body of program --------------------------------------------
+
+	// Create a response queue so the server can send us responses
+	// to our requests. Use the client's session ID as the name
+	// of the response queue.
+
+	stringstream response_queue;
+	response_queue << "client " << session.getId();
+
+        // Use the name of the response queue as the routing key
+
+	session.queueDeclare(arg::queue=response_queue.str());  // ### Nice if I could just use strstream for this
+        session.queueBind(arg::queue=response_queue.str(), arg::routingKey=response_queue.str());
+
+	// Create a listener for the response queue and start listening.
+
+	Listener listener(session, response_queue.str());
+	listener.listen();
+
+
+	// The routing key for the request queue is simply
+	// "request_queue", and all clients use the same routing key.
+	//
+	// Each client sends the name of their own response queue so
+	// the service knows where to route messages.
+
+	request.getDeliveryProperties().setRoutingKey("request_queue");
+	request.getHeaders().setString("reply-to", response_queue.str());
+
+	// Now send some requests ...
+
+	string s[] = {
+		"Twas brillig, and the slithy toves",
+		"Did gire and gymble in the wabe.",
+		"All mimsy were the borogroves,",
+		"And the mome raths outgrabe."
+        };
+
+
+	for (int i=0; i<4; i++) {
+	  request.setData(s[i]);
+          session.messageTransfer(arg::content=request);
+	  std::cout << "Request: " << s[i] << std::endl;
+	}
+
+	// And wait for any outstanding responses to arrive
+
+	listener.wait();
+	
+
+  //-----------------------------------------------------------------------------
+
+        connection.close();
+        return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/request-response/client.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/request-response/client.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/examples/request-response/server.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/request-response/server.cpp?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/request-response/server.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/examples/request-response/server.cpp Thu Nov  8 18:38:33 2007
@@ -0,0 +1,153 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+
+/**
+ *  server.cpp
+ *
+ *  This program is one of two programs that illustrate the
+ *  request/response pattern.
+ *  
+ *    client.cpp 
+ *
+ *      Make requests of a service, print the response.
+ *
+ *    server.cpp (this program)
+ *
+ *      Accept requests, reverse the letters in each message, and
+ *      return it as a response.
+ *
+ */
+
+
+#include <qpid/client/Connection.h>
+#include <qpid/client/Dispatcher.h>
+#include <qpid/client/Session.h>
+#include <qpid/client/Message.h>
+#include <qpid/client/MessageListener.h>
+
+
+#include <unistd.h>
+#include <cstdlib>
+#include <iostream>
+#include <algorithm>
+
+#include <sstream>
+#include <string>
+
+using namespace qpid::client;
+using namespace qpid::framing;
+using std::stringstream;
+using std::string;
+
+class Listener : public MessageListener{
+private:
+  std::string destination_name;
+  Dispatcher dispatcher;
+  Session session;
+public:
+  Listener(Session& session, string destination_name): 
+    destination_name(destination_name),
+    dispatcher(session),
+    session(session)
+  {};
+
+  virtual void listen();
+  virtual void received(Message& message);
+  virtual void wait();
+  ~Listener() { };
+};
+
+
+void Listener::listen() {
+  std::cout << "Activating request queue listener for: " <<destination_name << std::endl;
+
+  session.messageSubscribe(arg::queue=destination_name, arg::destination=destination_name);
+
+  // ##### Should not be needed. Sigh.
+  session.messageFlow(arg::destination=destination_name, arg::unit=0, arg::value=1);//messages ### Define a constant?
+  session.messageFlow(arg::destination=destination_name, arg::unit=1, arg::value=0xFFFFFFFF);//bytes ###### Define a constant?
+
+  dispatcher.listen(destination_name, this);
+}
+
+
+void Listener::wait() {
+  std::cout << "Waiting for requests" << std::endl;
+  dispatcher.run();
+}
+
+
+void Listener::received(Message& request) {
+
+  Message response;
+  string routingKey = request.getHeaders().getString("reply-to");
+
+  std::cout << "Request:: " << request.getData() << "  (" <<routingKey << ")" << std::endl;
+
+  // Transform message content to upper case
+  std::string s = request.getData();
+  std::transform (s.begin(), s.end(), s.begin(), toupper);
+  response.setData(s);
+
+  // Send it back to the user
+  response.getDeliveryProperties().setRoutingKey(routingKey);
+  session.messageTransfer(arg::content=response);
+}
+
+
+int main() {
+  Connection connection;
+    Message message;
+    try {
+        connection.open("127.0.0.1", 5672 );
+        Session session =  connection.newSession();
+
+  //--------- Main body of program --------------------------------------------
+
+	// Create a request queue for clients to use when making
+	// requests.
+
+	string request_queue = "request_queue";
+
+        // Use the name of the request queue as the routing key
+
+	session.queueDeclare(arg::queue=request_queue);
+        session.queueBind(arg::queue=request_queue, arg::routingKey=request_queue);
+
+	// Create a listener for the request queue and start listening.
+
+	Listener listener(session, request_queue);
+	listener.listen();
+	listener.wait();
+
+
+  //-----------------------------------------------------------------------------
+
+        connection.close();
+        return 0;
+    } catch(const std::exception& error) {
+        std::cout << error.what() << std::endl;
+    }
+    return 1;
+}
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/examples/request-response/server.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/examples/request-response/server.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h?rev=593402&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h Thu Nov  8 18:38:33 2007
@@ -0,0 +1,33 @@
+#ifndef QPID_CLIENT_SESSION_H
+#define QPID_CLIENT_SESSION_H
+
+/*
+ *
+ * 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.
+ *
+ */
+#include "qpid/client/Session_0_10.h"
+
+namespace qpid {
+namespace client {
+
+typedef Session_0_10 Session;
+
+}} // namespace qpid::client
+
+#endif  /*!QPID_CLIENT_SESSION_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Session.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message