Vincent Vincent - 1 year ago 99
Java Question

How to connect an ActiveMQ producer to an OpenMQ JMS broker

I'm trying to send text messages from a swing heavy client (using Apache ActiveMQ library) to an instance of glassfish server which seems to use OpenMQ as the default JMS provider.

Below the very source basic code I'm using for my client :

try {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("jms/SaisieQueueFactory");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("jms/SaisieQueue");
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("Score + 1");
} catch(Exception ex) {

  • I found the broker port in the system properties from the administration console of Glassfish server (JMS_PROVIDER_PORT)

  • The queue connection factory and the queue have been created when I deployed my MessageDrivenBean

  • For now the client and the glassfish instance are running on the same computer but I would like to have them working on two different machines (that's why I'm not using vm:// as the transport protocol)

I got these exceptions :

javax.jms.JMSException: Cannot send, channel has already failed: tcp://
at org.apache.activemq.util.JMSExceptionSupport.create(
at org.apache.activemq.ActiveMQConnection.syncSendPacket(
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(
at org.apache.activemq.ActiveMQConnection.start(
at testdate.TestDate.main(
Caused by: org.apache.activemq.transport.InactivityIOException: Cannot send, channel has already failed: tcp://
at org.apache.activemq.transport.AbstractInactivityMonitor.doOnewaySend(
at org.apache.activemq.transport.AbstractInactivityMonitor.oneway(
at org.apache.activemq.transport.TransportFilter.oneway(
at org.apache.activemq.transport.WireFormatNegotiator.oneway(
at org.apache.activemq.transport.MutexTransport.oneway(
at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(
at org.apache.activemq.transport.ResponseCorrelator.request(
at org.apache.activemq.ActiveMQConnection.syncSendPacket(
... 3 more

  • I considered the solution of changing the JMS provider of my Glassfish instance to ActiveMQ but if it is possible I would like to keep OpenMQ

PS: I'm a beginner with JMS and the Java EE framework

Answer Source

The JMS API definies a java interface and an architecture for messaging, it does not define any specific wire protocol, it could be a carrier pigeon, in memory or any of the common formats (STOMP, OpenWire, AMQP, MQTT).

Why can't you use Open MQ libraries instead in your client? This is the way JMS is designed. You should only have to switch from the .jar files and change the ConnectionFactory.

I don't see any reason to switch to ActiveMQ just for the sake of using the ActiveMQ JMS client, since it should be pretty much the same thing as the Open MQ client. There are other reasons to switch though, such as different server side features and what not, but you did not mention that.

That said, there is bridge component that is able to expose any JMS server over the STOMP protocol (which ActiveMQ supports).

It's called Stomp Connect and there are some rather old instructions at the OpenMQ page how to use it.

From there, you should be able to connect with ActiveMQConnection factory specifying STOMP. But I have not really tried this combination myself.