I'm writing a simple Java JMS QueueBrowser client to AmazonMQ, that runs ActiveMQ with stomp
protocol over ssh
(hence he transport is stomp+ssl
:
// java
import java.util.Enumeration;
// jms
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.ConnectionFactory;
import javax.jms.Connection;
// activemq
import org.apache.activemq.ActiveMQConnectionFactory;
public class QueueBrowserExample {
public static void main(String[] args) throws Exception {
System.out.println("init");
try {
final String PORT = "61616";
final String PROTOCOL = "stomp+ssl";
final String HOST = "xxx.mq.us-east-1.amazonaws.com";
final String connectionString = PROTOCOL + "://" + HOST + ":" + PORT;
System.out.println("attempt to connect to " + connectionString);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionString);
Connection connection = connectionFactory.createConnection("admin", "admin");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("Test");
QueueBrowser queueBrowser = session.createBrowser(queue);
Enumeration msgs = queueBrowser.getEnumeration();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I'm getting then a javax.jms.JMSException
execepion due to the Transport used (stomp+ssl
I assume)
javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=b-02b566af-1f0d-4d48-ad24-229a813a53fb-1.mq.us-east-1.amazonaws.com}
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:319)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:332)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:253)
at QueueBrowserExample.main(QueueBrowserExample.java:37)
Caused by: java.lang.IllegalArgumentException: Invalid connect parameters: {wireFormat.host=b-02b566af-1f0d-4d48-ad24-229a813a53fb-1.mq.us-east-1.amazonaws.com}
at org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.java:122)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:64)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:317)
... 3 more
The ActiveMQ back-end is using STOMP, and I do not have any access to it. Hence I have to figure how to "manage" the queue (watching messages only, not processing), and I came to QueueBrowser and JMS.
JMS over STOMP is not supported.
Keep in mind that JMS is just an API. The underlying wire protocol is different between most brokers. In ActiveMQ "Classic" (which is what Amazon MQ uses) you can use JMS via the OpenWire protocol or via AMQP (which requires using Qpid JMS library). There is no support for JMS over STOMP.
In this case, you're using the OpenWire JMS client since you're using org.apache.activemq.ActiveMQConnectionFactory
. It doesn't matter what you specify in the connection string, the client will use the OpenWire protocol.
STOMP just doesn't support much of the functionality exposed by JMS. Queue browsers in particular are not supported by STOMP.