Jonathan,

I notice you have added a hello world example, which I think is good. However I'd prefer a little more brevity; the aim is to get across the core objects and methods involved as simply as possible. My suggested changes are shown in the attached patch and include:

* only send a single message; I don't think the loops add any useful information) * remove the sender.close() and receiver.close(); connection.close() is sufficient and helps keep the program short * create sender and receiver before sending which allows using an exchange as well as a queue * use amq.topic as the default address (but allow a different one to be passed in); this means you can run the example without any setup of a queue

--Gordon.
Index: examples/messaging/hello_world.cpp
===================================================================
--- examples/messaging/hello_world.cpp	(revision 934593)
+++ examples/messaging/hello_world.cpp	(working copy)
@@ -5,45 +5,31 @@
 #include <qpid/messaging/Session.h>
 
 #include <iostream>
-#include <sstream>
 
 using namespace qpid::messaging;
 
-int main() {
+int main(int argc, char** argv) {
+    std::string broker = argc > 1 ? argv[1] : "localhost:5672";
+    std::string address = argc > 2 ? argv[2] : "amq.topic";
+    Connection connection(broker);
+    try {
+        connection.open();
+        Session session = connection.createSession();
 
-  Connection connection("localhost:5672");
-  try {
-    connection.open();
-    Session session = connection.createSession();
+        Receiver receiver = session.createReceiver(address);
+        Sender sender = session.createSender(address);
 
-    std::string address = "message_queue";
+        sender.send(Message("Hello world!"));
 
-    Sender sender = session.createSender(address);
-    
-    for (int i=0; i<5; i++) {
-      std::stringstream content;
-      content << "Message " << i;
-      std::cout << "Sending " << content.str() << std::endl;
-      sender.send(Message(content.str()));
+        Message message = receiver.fetch(Duration::SECOND * 1);
+        std::cout << message.getContent() << std::endl;
+        session.acknowledge();
+        
+        connection.close();
+        return 0;
+    } catch(const std::exception& error) {
+        std::cerr << error.what() << std::endl;
+        connection.close();
+        return 1;   
     }
-    sender.close();
-	
-    Receiver receiver = session.createReceiver(address);
-
-    Message message;
-    Duration timeout(1000); /* in milliseconds */
-    while (receiver.fetch(message, timeout)) {
-      std::cout << "Received " << message.getContent() << std::endl;
-      session.acknowledge();
-    }
-
-    receiver.close();
-
-    connection.close();
-    return 0;
-  } catch(const std::exception& error) {
-    std::cerr << error.what() << std::endl;
-    connection.close();
-    return 1;   
-  }
 }

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscr...@qpid.apache.org

Reply via email to