使用 IBM 的 SDK 从独立客户端访问 WildFly 的 ActiveMQ
Accessing WildFly's ActiveMQ from standalone client with IBM's SDK
如标题所示,我正在尝试从独立客户端连接到 WildFly 10 上的 ActiveMQ 运行ning。如果我使用 Oracle 的 SDK,在不更改代码或配置的情况下,我能够连接,但是如果我切换到 IBM 的 SDK,它会失败并出现以下异常:
javax.jms.JMSException: Failed to create session factory
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:727)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:233)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:229)
at pt.sibs.epms.JmsClient.main(JmsClient.java:50)
Caused by: ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]
at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:777)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:724)
... 3 more
我的问题是:这是不可能的,我在浪费时间,还是只是一些额外的调整?
注意:不幸的是,我必须使用 IBM 的 SDK,因为客户端将 运行 在 AIX 机器上。
编辑 #1
在进行了一些字节码操作之后,我能够确定分歧点。
Oracle 的 SDK 事件流:
method start() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
context javax.net.ssl.SSLContext@58c1c010
this.channelClazzclass io.netty.channel.socket.nio.NioSocketChannel
isStarted() true
------------------------------------------------------------------------------------------------------------
method doConnect() from io/netty/bootstrap/Bootstrap
channel.isOpen() true
regFuture.isDone() true
------------------------------------------------------------------------------------------------------------
method createConnection() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
future class io.netty.channel.DefaultChannelPromise
channel class io.netty.channel.socket.nio.NioSocketChannel
channel.isOpen() true
------------------------------------------------------------------------------------------------------------
method openTransportConnection() from org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl
connector.isStarted() true
------------------------------------------------------------------------------------------------------------
一切正常。
IBM 的 SDK 事件流:
method start() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
context javax.net.ssl.SSLContext@71b0b083
this.channelClazzclass io.netty.channel.socket.nio.NioSocketChannel
isStarted() true
------------------------------------------------------------------------------------------------------------
method doConnect() from io/netty/bootstrap/Bootstrap
channel.isOpen() true
regFuture.isDone() false
------------------------------------------------------------------------------------------------------------
method doClose() from io/netty/channel/socket/nio/NioSocketChannel
------------------------------------------------------------------------------------------------------------
method createConnection() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
future class io.netty.channel.DefaultChannelPromise
channel class io.netty.channel.socket.nio.NioSocketChannel
channel.isOpen() false
mar 10, 2017 7:59:35 AM org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector createConnection
ERROR: AMQ214016: Failed to create netty connection
java.nio.channels.ClosedChannelException
------------------------------------------------------------------------------------------------------------
method openTransportConnection()from org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl
connector.isStarted() false
------------------------------------------------------------------------------------------------------------
如您所见,createConnection()
失败,因为通道未打开并且来自 NioSocketChannel
的 doClose()
被显式调用。
我已将 doClose()
更改为抛出并捕获异常,这样我就可以看到它何时被调用:
java.lang.Exception: CLOSE INVOKED
at io.netty.channel.socket.nio.NioSocketChannel.doClose(NioSocketChannel.java:238)
at io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:611)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:590)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:534)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.closeOnRead(AbstractNioByteChannel.java:71)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:158)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:785)
关闭操作正常发生,不是任何异常事件引起的。
这是一个错误吗?
经过几天的排查,我终于找到了问题所在。我注意到,虽然客户端使用的是 Java 8,但 TLSv1 用于握手(没有抛出异常)。我尝试通过多种方式强制使用 TLSv1.2,但只有当我发现一个记录不完整的 属性 时,我才能够解决问题:
-Dcom.ibm.jsse2.overrideDefaultTLS=true
需要在客户端设置属性
如标题所示,我正在尝试从独立客户端连接到 WildFly 10 上的 ActiveMQ 运行ning。如果我使用 Oracle 的 SDK,在不更改代码或配置的情况下,我能够连接,但是如果我切换到 IBM 的 SDK,它会失败并出现以下异常:
javax.jms.JMSException: Failed to create session factory
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:727)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:233)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:229)
at pt.sibs.epms.JmsClient.main(JmsClient.java:50)
Caused by: ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]
at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:777)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:724)
... 3 more
我的问题是:这是不可能的,我在浪费时间,还是只是一些额外的调整?
注意:不幸的是,我必须使用 IBM 的 SDK,因为客户端将 运行 在 AIX 机器上。
编辑 #1
在进行了一些字节码操作之后,我能够确定分歧点。
Oracle 的 SDK 事件流:
method start() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
context javax.net.ssl.SSLContext@58c1c010
this.channelClazzclass io.netty.channel.socket.nio.NioSocketChannel
isStarted() true
------------------------------------------------------------------------------------------------------------
method doConnect() from io/netty/bootstrap/Bootstrap
channel.isOpen() true
regFuture.isDone() true
------------------------------------------------------------------------------------------------------------
method createConnection() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
future class io.netty.channel.DefaultChannelPromise
channel class io.netty.channel.socket.nio.NioSocketChannel
channel.isOpen() true
------------------------------------------------------------------------------------------------------------
method openTransportConnection() from org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl
connector.isStarted() true
------------------------------------------------------------------------------------------------------------
一切正常。
IBM 的 SDK 事件流:
method start() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
context javax.net.ssl.SSLContext@71b0b083
this.channelClazzclass io.netty.channel.socket.nio.NioSocketChannel
isStarted() true
------------------------------------------------------------------------------------------------------------
method doConnect() from io/netty/bootstrap/Bootstrap
channel.isOpen() true
regFuture.isDone() false
------------------------------------------------------------------------------------------------------------
method doClose() from io/netty/channel/socket/nio/NioSocketChannel
------------------------------------------------------------------------------------------------------------
method createConnection() from org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnector
future class io.netty.channel.DefaultChannelPromise
channel class io.netty.channel.socket.nio.NioSocketChannel
channel.isOpen() false
mar 10, 2017 7:59:35 AM org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector createConnection
ERROR: AMQ214016: Failed to create netty connection
java.nio.channels.ClosedChannelException
------------------------------------------------------------------------------------------------------------
method openTransportConnection()from org/apache/activemq/artemis/core/client/impl/ClientSessionFactoryImpl
connector.isStarted() false
------------------------------------------------------------------------------------------------------------
如您所见,createConnection()
失败,因为通道未打开并且来自 NioSocketChannel
的 doClose()
被显式调用。
我已将 doClose()
更改为抛出并捕获异常,这样我就可以看到它何时被调用:
java.lang.Exception: CLOSE INVOKED
at io.netty.channel.socket.nio.NioSocketChannel.doClose(NioSocketChannel.java:238)
at io.netty.channel.AbstractChannel$AbstractUnsafe.doClose0(AbstractChannel.java:611)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:590)
at io.netty.channel.AbstractChannel$AbstractUnsafe.close(AbstractChannel.java:534)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.closeOnRead(AbstractNioByteChannel.java:71)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:158)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:785)
关闭操作正常发生,不是任何异常事件引起的。 这是一个错误吗?
经过几天的排查,我终于找到了问题所在。我注意到,虽然客户端使用的是 Java 8,但 TLSv1 用于握手(没有抛出异常)。我尝试通过多种方式强制使用 TLSv1.2,但只有当我发现一个记录不完整的 属性 时,我才能够解决问题:
-Dcom.ibm.jsse2.overrideDefaultTLS=true
需要在客户端设置属性