问题
I am using camel-rabbitmq component to communicate rabbitMQ via SSL.
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.
Detailed info present in this link :- https://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores
I supplied key store files in JVM arguments , started below blueprint file and I got below error;
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&routingKey=rmqRoutekey&sslProtocol=TLSv1.2"/>
<to uri="log:msgdestroy"/>
</route>
</camelContext>
</blueprint>
Error log :-
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
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.
回答1:
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 .
This connection factory class by default will be auto detected by camel-rabbitMQ component.
Refer below code :-
https://github.com/apache/camel/blob/master/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQComponent.java#L171
Here is the catch point;
The new syntax is not allowing sslProtocol to set as "TRUE/TLS/SSLv3" simply ignoring query commands.
https://github.com/apache/camel/blob/master/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQConnectionFactorySupport.java#L40
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;
Updated blueprint file:-
<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&password=admin&amq;queue=queue&routingKey=rmqRoutekey&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
I am able to communicate RMQ through SSL with above changes.
来源:https://stackoverflow.com/questions/50546431/camel-rabbitmq-component-unable-to-communicate-via-ssl