qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonat...@apache.org
Subject svn commit: r934573 - in /qpid/trunk/qpid/cpp/examples/messaging: Makefile.am hello_world.cpp
Date Thu, 15 Apr 2010 20:04:00 GMT
Author: jonathan
Date: Thu Apr 15 20:04:00 2010
New Revision: 934573

URL: http://svn.apache.org/viewvc?rev=934573&view=rev
Log:
Added hello_world.cpp example for tutorial.

Added:
    qpid/trunk/qpid/cpp/examples/messaging/hello_world.cpp
Modified:
    qpid/trunk/qpid/cpp/examples/messaging/Makefile.am

Modified: qpid/trunk/qpid/cpp/examples/messaging/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/Makefile.am?rev=934573&r1=934572&r2=934573&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/Makefile.am Thu Apr 15 20:04:00 2010
@@ -21,7 +21,10 @@ examplesdir=$(pkgdatadir)/examples/messa
 MAKELDFLAGS=$(CLIENTFLAGS)
 include $(top_srcdir)/examples/makedist.mk
 
-noinst_PROGRAMS=drain spout queue_sender queue_receiver topic_sender topic_receiver client
server map_sender map_receiver
+noinst_PROGRAMS=drain spout queue_sender queue_receiver topic_sender topic_receiver client
server map_sender map_receiver hello_world
+
+hello_world_SOURCES=hello_world.cpp
+hello_world_LDADD=$(CLIENT_LIB)
 
 drain_SOURCES=drain.cpp
 drain_LDADD=$(CLIENT_LIB)
@@ -55,6 +58,7 @@ map_receiver_LDADD=$(CLIENT_LIB)
 
 EXTRA_DIST=                  \
 	CMakeLists.txt \
+	messaging_hello_world.vcproj \
 	messaging_client.vcproj \
 	messaging_drain.vcproj \
 	messaging_map_receiver.vcproj \

Added: qpid/trunk/qpid/cpp/examples/messaging/hello_world.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/hello_world.cpp?rev=934573&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/hello_world.cpp (added)
+++ qpid/trunk/qpid/cpp/examples/messaging/hello_world.cpp Thu Apr 15 20:04:00 2010
@@ -0,0 +1,49 @@
+#include <qpid/messaging/Connection.h>
+#include <qpid/messaging/Message.h>
+#include <qpid/messaging/Receiver.h>
+#include <qpid/messaging/Sender.h>
+#include <qpid/messaging/Session.h>
+
+#include <iostream>
+#include <sstream>
+
+using namespace qpid::messaging;
+
+int main() {
+
+  Connection connection("localhost:5672");
+  try {
+    connection.open();
+    Session session = connection.createSession();
+
+    std::string queueName = "message_queue";
+
+    Sender sender = session.createSender(queueName);
+    
+    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()));
+    }
+    sender.close();
+	
+    Receiver receiver = session.createReceiver(queueName);
+
+    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:commits-subscribe@qpid.apache.org


Mime
View raw message