You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jo...@apache.org on 2010/04/15 22:04:00 UTC

svn commit: r934573 - in /qpid/trunk/qpid/cpp/examples/messaging: Makefile.am hello_world.cpp

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


Re: [c++]: hello_world.cpp

Posted by Jonathan Robie <jo...@redhat.com>.
Thanks, Cliff!

Jonathan

On 04/16/2010 10:27 AM, Cliff Jansen wrote:
> I volunteer for the WCF version.  I'll get to it as soon as I get
> QPID-2501 out of the way. I also plan to do some work on the WCF
> documentation side as soon as I can as well.
>
> I am going to be on vacation next week so I will try to squeeze in what I can.
>
> Cliff
>
> On Fri, Apr 16, 2010 at 6:27 AM, Jonathan Robie
> <jo...@redhat.com>  wrote:
>    
>> Thanks, Gordon - this is definitely an improvement. I applied the patch,
>>   committed it, and used this in the tutorial. I also created a Python
>> example and check it in.
>>
>> I'll also do this for Java (pestering Rajith as needed).
>>
>> Anyone want to do a "Hello World" program for WCF? I'm not really set up in
>> that environment.
>>
>> Jonathan
>>
>> ---------------------------------------------------------------------
>> Apache Qpid - AMQP Messaging Implementation
>> Project:      http://qpid.apache.org
>> Use/Interact: mailto:dev-subscribe@qpid.apache.org
>>
>>
>>      
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:dev-subscribe@qpid.apache.org
>
>
>    


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


Re: [c++]: hello_world.cpp

Posted by Cliff Jansen <cl...@gmail.com>.
I volunteer for the WCF version.  I'll get to it as soon as I get
QPID-2501 out of the way. I also plan to do some work on the WCF
documentation side as soon as I can as well.

I am going to be on vacation next week so I will try to squeeze in what I can.

Cliff

On Fri, Apr 16, 2010 at 6:27 AM, Jonathan Robie
<jo...@redhat.com> wrote:
> Thanks, Gordon - this is definitely an improvement. I applied the patch,
>  committed it, and used this in the tutorial. I also created a Python
> example and check it in.
>
> I'll also do this for Java (pestering Rajith as needed).
>
> Anyone want to do a "Hello World" program for WCF? I'm not really set up in
> that environment.
>
> Jonathan
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:dev-subscribe@qpid.apache.org
>
>

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


Re: [c++]: hello_world.cpp

Posted by Jonathan Robie <jo...@redhat.com>.
Thanks, Gordon - this is definitely an improvement. I applied the 
patch,  committed it, and used this in the tutorial. I also created a 
Python example and check it in.

I'll also do this for Java (pestering Rajith as needed).

Anyone want to do a "Hello World" program for WCF? I'm not really set up 
in that environment.

Jonathan

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


[c++]: hello_world.cpp

Posted by Gordon Sim <gs...@redhat.com>.
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.