使用IBM的SDK从独立客户端访问WildFly的ActiveMQ

时间:2017-03-09 09:22:49

标签: jms activemq wildfly-10

正如标题所示,我试图从独立客户端连接到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机器上运行。

编辑#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()失败,因为频道未打开,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)

关闭操作正常发生,不是由任何异常事件引起的。 这是一个错误吗?

1 个答案:

答案 0 :(得分:1)

经过几天的调查,我终于找到了问题所在。我注意到,虽然客户端使用的是Java 8,但TLSv1正被用于握手(没有异常被抛出)。我试图以多种方式强制使用TLSv1.2,但只有当我找到一个记录不完整的属性时我才能解决问题:

\w+            # at least one word character
\s*            # Zero or more spaces
(?:\[\d+\]){2} # [0][1] or any other two-dimensional array
\s*=\s*        # spaces = and spaces
\K             # "forget" everything
\{([\d.]*)\}   # match and capture {number}

需要在客户端设置属性。