talking stomp to apache camel with c

Tue, Jul 28, 2009

I’ve got an Apache Camel instance running with stomp listening for interesting things to happen and it works just fine from Ruby. But I need to read from a queue using C++ on Windows for GADfly. So I needed to build a C++ client in Visual Studio. To do that you need the following:

  • Apache apr
  • Apache apr-iconv
  • Apache apr-util
  • activemq-cpp-library
You first need to setup the apr libraries for compilation. There are some instructions on this page but the source links for win32 are mostly broken so you have to go into the other files area to find them. Once you get them, you have to rename the directories thus:
  • APR_SRC_HOME/apr
  • APR_SRC_HOME/apr-iconv
  • APR_SRC_HOME/apr-util
otherwise nothing will work.

Open APR_SRC_HOME/apr/apr.dsw, ignore any warnings about project stuff and build the entire solution.

Open APR_SRC_HOME/apr-iconv/apriconv.sln and build that

Open APR_SRC_HOME/apr-util/aprutil.sln. This might give you a load of messages. Just ignore them. Then remove all projects from the solution that are to do with database support. It’s much easier without them as they need extra dependencies which you don’t need for messaging. Once you’ve removed them build the entire solution.

If you have the above source layout in the correctly named directories each apr project will find what it needs from the other ones.

Now, download ActiveMQ CMS and unpack to CMS_SOURCE_HOME.

Open the file CMS_SOURCE_HOME/vs2005-build/vs2005-activemq-cpp.sln

Under Configuration Properties -> C++ -> General -> Additional Include Directories, add links to the apr and apr-util include directories:

  • APR_SRC_HOME/apr/include
  • APR_SRC_HOME/apr-util/include
Under Configuration Properties -> Librarian -> General -> Additional Library Directories, add links to the apr debug directories:
  • APR_SRC_HOME/apr/Debug
  • APR_SRC_HOME/apr-util/Debug
and under Additional Dependencies add:
  • libapr-1.lib
  • libaprutil-1.lib
Now build the solution.

The next step is to actually use the C++ CMS library. A quick way to test is to grab the CMS example code, which doesn’t work with the latest release of CMS but we’ll fix that.

Create a new project in STOMP_TEST_HOME, Win32 console application and copy/paste the example code into it.

Under Configuration Properties -> C++ -> General -> Additional Include Directories, add links to the apr and cms include directories:

  • APR_SRC_HOME/apr/include
  • CMS_SOURCE_HOME/src/main
Under Configuration Properties -> Linker -> General -> Additional Library Directories, add links to the CMS debug directory:
  • CMS_SOURCE_HOME/vs2005-build/Debug
Under Configuration Properties -> Linker -> Input -> Additional Dependencies, add links to the libraries:
  • libactivemq-cppd.lib
  • Ws2_32.lib
Add this to the list of includes:
#include <activemq/library/ActiveMQCPP.h>
and add these lines to the main() code:
using namespace activemq::library;
ActiveMQCPP::initializeLibrary();
or you’ll just get this error when you run:

no matching factory registered for format := tcp

Build the project, then copy these files to the Debug directory (this is a quick way of getting the dependencies onto the path):

  • APR_SRC_HOME/apr/Debug/libapr-1.dll
  • APR_SRC_HOME/apr-iconv/Debug/libapriconv-1.dll
  • APR_SRC_HOME/apr-util/Debug/libaprutil-1.dll
Once you’ve set up your camel instance you can run the example, pointing at that instance.

comments powered by Disqus