正如标题所示,我正在尝试从独立客户端连接到在 WildFly 10 上运行的 ActiveMQ。如果我使用 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机器上运行。
进行一些字节码操作后,我能够识别出分歧点。
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()
失败,因为通道未打开并且来自 doClose()
的 NioSocketChannel
被显式调用。
我已将 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$2.run(SingleThreadEventExecutor.java:112)
at java.lang.Thread.run(Thread.java:785)
关闭操作是正常发生的,不是由任何异常事件引起的。 这是一个错误吗?
经过几天的排查,我终于找到了问题所在。我注意到,虽然客户端使用 Java 8,但握手时使用了 TLSv1(没有抛出异常)。我尝试通过多种方式强制使用 TLSv1.2,但只有当我发现一个文档记录不充分的属性时,我才能够解决问题:
-Dcom.ibm.jsse2.overrideDefaultTLS=true
该属性需要在客户端设置。