I’m switching gears in this post to discuss my experience with installing and integrating Apache ActiveMQ’s C++ client library with Objective-C. ActiveMQ is an open-source message broker, for Windows and UNIX, from the Apache Software Foundation.
- Intro to ActiveMQ
- Installing ActiveMQ C++ Client Libraries
- Integrating ActiveMQ C++ with Objective-C
In previous posts, I cover iPhone development topics for a prototype I’m working on. Yet, my iPhone app is only one client in a larger software as a service (SaaS) prototype. The plan is to have the SaaS system support clients across other popular mobile platforms and desktop operating systems such as Mac OS X and Windows.
In this heterogeneous computing environment, some of my components need to reliably send and receive messages. So, adding a message broker to the mix makes sense. However, for a prototype, buying a commercial product such as IBM’s WebSphere MQ is out-of-the-question. Consequently, I chose Apache ActiveMQ.
Apache ActiveMQ is an open source message broker which fully implements the Java Message Service 1.1 (JMS). It provides “Enterprise Features” like clustering, multiple message stores, and availability to use any database as a JMS persistence provider besides VM, cache, and journal persistency.
Apart from Java, ActiveMQ can be also used from .NET, C/C++ or Delphi or from scripting languages like Perl, Python, PHP and Ruby via various “Cross Language Clients” together with connecting to many protocols and platforms.
Apache ActiveMQ. (2009, November 26). In Wikipedia, The Free Encyclopedia. Retrieved 23:00, November 26, 2009, from http://en.wikipedia.org/w/index.php?title=Apache_ActiveMQ&oldid=328100430
Installing ActiveMQ is easy. Writing Java clients is straightforward. However, I have a native Mac OS X client (written in Objective-C) that needs to process messages. Fortunately, ActiveMQ has a C++ client library or CMS, which stands for C++ Messaging Service; and since Xcode supports Objective C++ (mixing Objective-C and C++) I have a solution for integrating my client with ActiveMQ.
Installing CMS on a UNIX-based system is not as easy as installing the ActiveMQ server. There are some hoops to jump through.
- Download CMS here.
- Follow the README instructions and note that the package is dependent on number of tools and libraries:
- autoconf version >= 2.61
- automake version >= 1.10
- libtool version >= 1.5.24
- APR version >= 1.3
- APR-Util version >= 1.3
- CPPUnit version >= 1.10.2*
- libuuid version >= ?*
On Mac OS X 10.6.x, I already had autoconf, automake, and libtool. But, I had to install the latter four packages before installing CMS. Each installation follows the same set of standard command lines, check the requisite README for variations:
- make [test or check]
- make install
After installing everything, the CMS libraries will be in usr/local/lib and ready to use in Xcode.
Moving to client development, I had the simple CMS consumer example running straightaway. However, once I began to mix in my Objective-C code, my build was wrought with pre-complier errors of the form: expected ‘;’, ‘,’ or ‘)’ before ‘>’ token.
Answers to this issue on the web were illusive. But, I knew the root cause was the inclusion of <Foundation/Foundation.h> with my C++. Fiddling with build settings was futile. My workaround, remove all references to Foundation.h and explicitly add only the headers the implementation needs. For example: <Foundation/NSString.h>, <Foundation/NSDate.h>, <Foundation/NSDateFormatter.h>… Works like a charm, but tedious. I wish Xcode had a command analogous to Organize Imports in Eclipse.
In any case, my ActiveMQ Objective C++ client is now working nicely. I hope this info helps some other Xcoder out there.