Java ActiveMQ + STOMP + SSH: illegal reflective access operation to method sun.security.ssl.SSLSocketImpl.setHost
Asked Answered
T

1

1

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.

Taima answered 9/2, 2022 at 13:24 Comment(0)
S
2

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.

Santonin answered 9/2, 2022 at 14:19 Comment(4)
Thanks a lot, I missed that. So there is any alternative when using 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 a QueueBrowser.Taima
Thanks I did know about JMS OpenWire, I supposed that it was cross-protocol sort of. STOMP is the server protocol, cannot change that. Thanks.Taima
Ye the ActiveMQ backend 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 QueueBroker and JMS. Thank you.Taima
Add on. The problem here with STOMP seems to be related to activemq.apache.org/how-do-i-unack-the-message-with-stompTaima

© 2022 - 2024 — McMap. All rights reserved.