java中red hat jboss eap 7.3服务器上的jms客户端到activemq

wz1wpwve  于 2021-07-11  发布在  Java
关注(0)|答案(1)|浏览(513)

我正在编写一个java客户机来连接到运行activemq的jbosseap7.3服务器,并且在修改参数时得到各种连接响应。请帮我更正参数/代码。我得到:

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)

这是尝试连接的try-catch块中的java客户端代码:

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");

这些是我在eap管理控制台中的jndi树值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]
iqih9akk

iqih9akk1#

我看你用错了 InitialContextFactory 实施。尝试使用 org.wildfly.naming.client.WildFlyInitialContextFactory 而不是 org.jboss.naming.remote.client.InitialContextFactory .
您可以在这里找到JBossEAP7.3的完整jms客户机示例。

相关问题