Camel-rabbitmq组件无法通过SSL进行通信

时间:2018-05-26 19:43:15

标签: rabbitmq apache-camel

我使用camel-rabbitmq组件通过SSL与rabbitMQ进行通信。

根据rabbitMQ组件文档仅启用SSL sslProtocal 参数就足够了。默认情况下,将加载JVM SSLcontext,并根据 / lib / security / cacerts 文件(或)JVM参数验证服务器证书。

此链接中的详细信息: - https://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores

我在JVM参数中提供了密钥库文件,从蓝图文件下面开始,我得到了以下错误;

BluePrint.xml

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="customConnectionFactory" class="com.rabbitmq.client.ConnectionFactory">
  <property name="host" value="127.0.0.1"/>
  <property name="port" value="5671"/>
  <property name="username" value="admin"/>
  <property name="password" value="admin"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
  <route>
    <from uri="rabbitmq://rmqEx?queue=queue&amp;routingKey=rmqRoutekey&amp;sslProtocol=TLSv1.2"/>
    <to uri="log:msgdestroy"/>
  </route>
</camelContext>
</blueprint>

错误日志: -

2018-05-27T00:38:11,569 | INFO  | Camel (camel-1) thread #1 - RabbitMQConsumer | RabbitConsumer                   | 58 - org.apache.camel.camel-rabbitmq - 2.21.0 | Attempting to open a new rabbitMQ channel
2018-05-27T00:38:11,583 | INFO  | Camel (camel-1) thread #1 - RabbitMQConsumer | RabbitMQConsumer                 | 56 - org.apache.camel.camel-core - 2.21.0 | Connection failed, will retry in 5000ms
java.io.IOException: null
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:126) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:122) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:362) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:64) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:99) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:948) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:865) [53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1049) [53:com.rabbitmq.client:5.1.2]
at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.connect(RabbitMQEndpoint.java:228) [58:org.apache.camel.camel-rabbitmq:2.21.0]
at org.apache.camel.component.rabbitmq.RabbitMQConsumer.openConnection(RabbitMQConsumer.java:64) [58:org.apache.camel.camel-rabbitmq:2.21.0]
at org.apache.camel.component.rabbitmq.RabbitMQConsumer.getConnection(RabbitMQConsumer.java:75) [58:org.apache.camel.camel-rabbitmq:2.21.0]
at org.apache.camel.component.rabbitmq.RabbitConsumer.reconnect(RabbitConsumer.java:307) [58:org.apache.camel.camel-rabbitmq:2.21.0]
at org.apache.camel.component.rabbitmq.RabbitMQConsumer$StartConsumerCallable.call(RabbitMQConsumer.java:216) [58:org.apache.camel.camel-rabbitmq:2.21.0]
at org.apache.camel.component.rabbitmq.RabbitMQConsumer$StartConsumerCallable.call(RabbitMQConsumer.java:196) [58:org.apache.camel.camel-rabbitmq:2.21.0]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:66) ~[53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:494) ~[53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:306) ~[53:com.rabbitmq.client:5.1.2]
... 16 more
Caused by: java.io.EOFException
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290) ~[?:?]
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[53:com.rabbitmq.client:5.1.2]
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:580) ~[53:com.rabbitmq.client:5.1.2]
... 1 more

还有一个参数可用于配置“TrustManger”。信任管理器受SSLContext约束,因此我们无法在Trust manger下绑定SSLcontext。在camel-rabbitmq组件中,没有“SSLContext”参数来保存它。

http://camel.apache.org/camel-configuration-utilities.html

请告诉我如何解决此连接问题。

1 个答案:

答案 0 :(得分:0)

如果你在上面提到&#34; blueprint.xml &#34;文件我正在使用新版本的rabbitmq语法;我需要创建连接工厂bean并加载必要的参数。

默认情况下,此连接工厂类将由camel-rabbitMQ组件自动检测。

参考下面的代码: -

https://github.com/apache/camel/blob/master/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java#L171

这是关键点;

新语法不允许sslProtocol设置为&#34; TRUE / TLS / SSLv3&#34;只是忽略查询命令。

https://github.com/apache/camel/blob/master/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQConnectionFactorySupport.java#L40

要通过SSL传递RMQ,我们需要创建SSLContext,因为没有正确分配sslProtocol整个跳过的逻辑并强制连接以PLAN TCP模式进行通信。

解决这个问题;我们需要恢复到如下所示的旧语法;

更新了蓝图文件: -

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
  <route>
    <from uri="rabbitmq://127.0.0.1:5671/rmqEx?username=admin&amp;password=admin&amq;queue=queue&amp;routingKey=rmqRoutekey&amp;sslProtocol=true"/>
    <to uri="log:msgdestroy"/>
  </route>
</camelContext>
</blueprint>

添加以下信任库参数。有关详细信息,请参阅以下文档。

https://docs.oracle.com/cd/E19830-01/819-4712/ablqw/index.html

我可以通过SSL与上述更改进行RMQ通信。