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.
stomp
it seems, unless implementing a message receiver client (a watcher then) and the auto acknowledgement off on the server. Or maybe there is an alternative library in Python/NodeJS. For sure AWS SDK do not implement aQueueBrowser
. – Taima