本文介绍了Camel-rabbitmq 组件无法通过 SSL 进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用camel-rabbitmq 组件通过SSL 与rabbitMQ 通信.

I am using camel-rabbitmq component to communicate rabbitMQ via SSL.

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

As per rabbitMQ component document to enable SSL only sslProtocal parameter is enough. By default JVM SSLcontext will be loaded and validate server certificate based on /lib/security/cacerts file (or) JVM arguments.

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

Detailed info present in this link :- https://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores

我在 JVM 参数中提供了密钥存储文件,从蓝图文件下面开始,但出现以下错误;

I supplied key store files in JVM arguments , started below blueprint file and I got below error;

BluePrint.xml

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".Trust manager 受 SSLContext 限制,所以我们不能在 Trust manager 下绑定 SSLcontext.在camel-rabbitmq 组件中,没有SSLContext"参数来保存它.

There is one more parameter to configure "TrustManger" . Trust manager is bounded by SSLContext, so we cant bound SSLcontext under Trust manger. In camel-rabbitmq component there is no "SSLContext" parameter to hold it.

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

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

Please let me know how to fix this connectivity issue.

推荐答案

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

If you refer above "blueprint.xml" file I am using new version of rabbitmq syntax; I need to create connection factory bean and load necessary parameters .

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

This connection factory class by default will be auto detected by camel-rabbitMQ component.

参考以下代码:-

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

这里是抓点;

新语法不允许将 sslProtocol 设置为TRUE/TLS/SSLv3",而只是忽略查询命令.

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 模式下进行通信.

To communicate RMQ through SSL we need to create SSLContext since sslProtocol is not being assigned properly the entire logic skipped and force connection to communicate in PLAN TCP mode.

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

To solve this issue ; We need to revert to old Syntax like below;

更新的蓝图文件:-

<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>

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

Add below truststore parameters. Refer this below document for more information .

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

我能够通过 SSL 与上述更改通信 RMQ.

I am able to communicate RMQ through SSL with above changes.

这篇关于Camel-rabbitmq 组件无法通过 SSL 进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 13:27