Steve HustonRiverace Corporation
Steve's Networked Programming Newsletter
Making Nets Work
September 2009

The past couple of newsletter issues were focused on ACE, so it's time for a little Apache Qpid "How-To" this month. I start with the basics. So it doesn't take months to get you up to a real messaging program, I'll probably continue the series on my blog, so keep an eye out there.

I also tried out a new way of delivering ACE training this month. More details included below and, since this worked out pretty well, it'll continue.

As always, be sure to forward this note to other people you work with to be sure they know what's happening in the world of networked application development.

In This Issue
How to Send a Message Using Apache Qpid C++
ACE Training Live On the Web
Did Your Last Project Run Late? Want to Prevent That?
How to Send a Message Using Apache Qpid C++
I've mentioned Apache Qpid a number of times in this newsletter over the past year or so. In case you're not yet familiar with Apache Qpid, it's a message queuing system which implements the Advanced Message Queuing Protocol (AMQP). Because it's open source and freely available for multiple platforms, it's an attractive choice when you need reliable, persistent message queuing.

Apache Qpid offers client APIs in a number of languages, but I work more with the C++ version, so will use that language for this example.

To lay a little groundwork, the players in AMQP that we're concerned with are:
  • Client: an entity that sends and receives messages. The example in this article is a client program.
  • Exchange: destination for messages that a client sends; there are a number of different exchange types which provide various message distribution mechanisms such as direct, fan-out, and publish-subscribe (pub-sub).
  • Queue: holds messages that a client will receive
  • Broker: the traffic cop; manages exchanges, queues, and the routing between them
  • Connection: a data connection to the broker
  • Session: an abstraction for managing a set of message transfers; Sessions operate over Connections.
Our example will send a message to a direct exchange. The message will have a routing key that will help the broker route the message from the exchange to any queues that are interested in this message. A subsequent example will show how to receive such a message.

Ok, let's get into it... first, the header files we need:

#include <qpid/client/Connection.h>
#include <qpid/client/Session.h>
#include <qpid/client/Message.h>

In order to anything, we need a connection to the broker and a session to use. We'll assume there's a broker on the local system and that it's listening on TCP port 5672 (the default for Qpid).

qpid::client::Connection connection;
try {
  connection.open("localhost", 5672);
  qpid::client::Session session = connection.newSession();
  qpid::client::Message message("Hello, world!", "my_key");
  session.messageTransfer(arg::content=message, arg::destination="amq.direct");
  connection.close();
  return 0;
} catch(const std::exception& error) {
   std::cout << error.what() << std::endl;
  return 1;
}

That's it. Of course, there are many fancy options for when needed, but this program sends a message and will work on all Qpid platforms. If you're interested in checking out the API details behind this, the API reference is at http://qpid.apache.org/docs/api/cpp/html/index.html.

Keep an eye on my blog for more how-to article on Qpid (and ACE). Is there something particular you want to see an example of? Let me know!
ACE Training Live On the Web
I tried something new in September - delivering an ACE training session live via webinar. The first session was "How to Get the Most From the ACE Reactor". The Reactor framework is a popular item in ACE, and the people who attended got good results, so I'll do more of these. Since the class covered Reactor topics that are not in the ACE books (such as event handler reference counting), the class had instruction that's not easy to get.

Feedback from the ACE users list was generally that threading and ACE_Task are topics people really want to hear more about, so that's probably the direction the next session will go in.

Interested? To ensure you hear about future sessions, please be sure you're registered to receive notices about "Special Offers and Events" and/or "News About Riverace's Services" in your profile. To see, or change, your profile, click on "Update Profile/Email Address" at the bottom of this message.
Do You Need Help Designing Your Next System?
Nobody has to tell you that designing a well-formed, efficient, maintainable networked application is hard. You've had to deal with it. The problem is that networking functionality is usually in a supporting role to your system's main purposes, and your skills and experience are much better used to focus on specific business and technology issues. It may make more sense to bring in seasoned expertise to help design a solid networking base in your next system.

I've helped many companies get great networked applications built - I may be able to help you as well. Let's talk and see if I can help take care of the networking, and let you focus on applying your expertise and experience to the business features that'll really help your system stand out.

Call me at 508-541-9180 or email me at [email protected].
If you have any ideas for areas of networked programming you'd like to hear about in future issues, please email me with your suggestions. In the meantime, keep those nets working!
 
Sincerely,
 

Steve Huston
Riverace Corporation