2

I want to use ActiveMQ as a message broker communicating between a C++ component and a Java component in two process. Eg. C++ component is the publisher and the Java component is the subscriber(there maybe multiple subscribers). I look at ActiveMQ website and it mentions the tool OpenWire and ActiveMQ-CPP. However, all the examples on the websites are using the same language for both producer and consumer.

My questions are:

1.Can ActiveMQ work for producer/consumer in different languages?

2.In different processes? How?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Lily
  • 5,872
  • 19
  • 56
  • 75

2 Answers2

2

OpenWire is a protocol and hence can theoretically be implemented anywhere, but that doesn't mean full implementations exist for every language. The fine print of the C++ client says:

"As of version 2.0, ActiveMQ-CPP supports the OpenWire v2 protocol, with a few exceptions. ObjectMessage - We cannot reconstruct the object(s) contained in an ObjectMessage in C++, so if your application is subscribed to a queue or topic that has an ObjectMessage sent to it, you will receive the message but will not be able to extract an Object from it."

So if you want to send data across processes, you write your C++ and Java components to use the API (making sure not to use ObjectMessage types if you're using ActiveMQ-CPP). Then run the ActiveMQ server... tell your programs to connect to it, and it should work.

But if you're really just trying to do interprocess communication when you control both clients, this could be a bit heavy-handed. You might be interested in the responses to What is the best approach for IPC between Java and C++? and Good alternative to shared memory IPC for Java/C++ apps on Linux

Community
  • 1
  • 1
  • why ActiveMQ is heavy-handed? – Lily Jan 22 '10 at 20:39
  • My understanding is that you have to run an ActiveMQ process, so you've now got a total of three processes running (along with all the worry that comes with running and configuring the brokering server). If you use shared memory then your processes can talk directly, and if you use sockets you get the ability to run your programs on different machines if you wish. Each level of abstraction gives you something, and you may-or-may-not need that something for your application. – HostileFork says dont trust SE Jan 22 '10 at 20:59
  • thanks for your reply. I do want to run different modules on different machines. Actually, in my case, it's a publisher/subscriber pattern (multiple publisher/multiple subscriber) I am not sure which one is better: socket vs. ActiveMQ? – Lily Jan 24 '10 at 00:53
  • I've not used ActiveMQ...but that wasn't necessary to answer your original question. With "what's better" issues I'm out of my depth. :) But if you control the C++ and the Java code then there doesn't seem to be a strong reason why they wouldn't just speak the same format over something like Google Protocol Buffers and you wouldn't need a "message broker". But maybe ActiveMQ is great for publish/subscriber features regardless. Perhaps ask a new question "Which is better for publish/subscribe network services, ActiveMQ or Bonjour or..." and someone who knows more than I do can answer it. – HostileFork says dont trust SE Jan 25 '10 at 04:22
0

Directly from ActiveMQ's front page :

Supports a variety of Cross Language Clients and Protocols from Java, C, C++, C#, Ruby, Perl, Python, PHP

* OpenWire for high performance clients in Java, C, C++, C#
* Stomp support so that clients can be written easily in C, Ruby, Perl,
  Python, PHP, ActionScript/Flash, Smalltalk to talk to ActiveMQ as well 
  as any other popular Message Broker

We have tested it with PHP (using Stomp) and Java (using OpenWire).

Regarding processes : the various producers and consumers can of course be in totally different processes, communicating over e.g TCP or SSL.