Skip to content
Advertisement

JMS client to ActiveMQ at server on Red Hat JBoss EAP 7.3 in Java

I am writing a Java client to connect to my JBoss EAP 7.3 server running ActiveMQ, and I am getting various connection responses as I alter the parameters. Please help me correct the parameters/code. I get:

09:46:57.227 [main] INFO org.xnio.nio - XNIO NIO Implementation Version 3.4.6.Final
09:46:57.606 [Remoting "config-based-naming-client-endpoint" I/O-1] DEBUG org.xnio.nio - Started channel thread 'Remoting "config-based-naming-client-endpoint" I/O-1', selector sun.nio.ch.WindowsSelectorImpl@17ab1d7e                                 ...
jboss.naming.client.connect.options. has the following options {}
09:46:57.763 [main] DEBUG org.jboss.naming.remote.client.HaRemoteNamingStore - Failed to connect to server http-remoting://127.0.0.1:8080
java.lang.RuntimeException: java.io.IOException: For now upgrade responses must have a content length of zero.
    at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:95)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:198)
...    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:146)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at com.goprecise.ams.demo.SendJmsToProcess.main(SendJmsToProcess.java:46)
Caused by: java.io.IOException: For now upgrade responses must have a content length of zero.
...     at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
    at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89)
    at org.xnio.nio.WorkerThread.run(WorkerThread.java:571)
...     at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:335)
    at org.jboss.naming.remote.client.EndpointCache$EndpointWrapper.connect(EndpointCache.java:122)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:197)
    ... 8 common frames omitted
javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [http-remoting://127.0.0.1:8080 (java.io.IOException: For now upgrade responses must have a content length of zero.)]
    at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:244)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:149)

This is the Java client code in a try catch block attempting to connect:

            Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
            env.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");  
            env.put(Context.SECURITY_PRINCIPAL,adminUser);
            env.put(Context.SECURITY_CREDENTIALS, adminPassword);
            Context  namingContext = new InitialContext(env);

            String CONNECTION_FACTORY = "java:jboss/exported/jms/RemoteConnectionFactory"; 
                        ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY);
            System.out.println("Got ConnectionFactory");

            Destination destination = (Destination) namingContext.lookup(QUEUE);  // Sure QUEUE is correct
            System.out.println("Got JMS Endpoint " + QUEUE);

            JMSContext context = connectionFactory.createContext(adminUser, adminPassword);
            context.createProducer().send(destination, xmlContent);
            System.out.println("Got JMS destination");

And these are my JNDI tree values in the EAP management console for java:jboss/exported >> JMS >>

URI                    java:jboss/exported/jms/RemoteConnectionFactory
Class Name             org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory
Value                  ActiveMQConnectionFactory [serverLocator=ServerLocatorImpl 
                       [initialConnectors=[TransportConfiguration(name=http-connector, 
                       factory=org-apache-activemq-artemis-core-remoting-impl-netty-
                       NettyConnectorFactory) ?httpUpgradeEndpoint=http-                    
                       acceptor&activemqServerName=default&httpUpgradeEnabled=true&port=
                       8080&host=kubernetes-docker-internal], discoveryGroupConfiguration=null], 
                       clientID=null, consumerWindowSize = 1048576, dupsOKBatchSize=1048576, 
                       transactionBatchSize=1048576, readOnly=falseEnableSharedClientID=true]

Advertisement

Answer

It looks to me like you’re using the wrong InitialContextFactory implementation. Try using org.wildfly.naming.client.WildFlyInitialContextFactory instead of org.jboss.naming.remote.client.InitialContextFactory.

You can find a full JMS client example for JBoss EAP 7.3 here.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement