Connection to RabbitMQ using Java fails due to missing protocol.
When using Java to connect to a RabbitMQ service on a remote node using the rabbit java client, there are connection errors as below:
1) Modify the Java code by adding the lines shown below, by adding the protocol using the factory methods. Specify the other parameters username, password,port ect. in addition to this.
String protocol = "TLSv1";
ConnectionFactory factory = new ConnectionFactory();
factory.useSslProtocol(this.protocol);
and specify the protocol to be used to connect to rabbitMQ.
2) Also specify the protocol in the rabbitMQ configuration file /etc/rabbitmq/rabbitmq.config.
[
{kernel, [
]},
{ssl, [{versions, ['TLSv1']}]},
{rabbit, [
{ssl_listeners, [5671]},
{ssl_options, [{cacertfile,"/etc/rabbitmq/ssl/cacert.pem"},
{certfile,"/etc/rabbitmq/ssl/cert.pem"},
{keyfile,"/etc/rabbitmq/ssl/key.pem"},
{verify,verify_none},
{fail_if_no_peer_cert,false}
,{versions,['TLSv1']}
.....
..........
.........
]}
]
Using step 1 and 2 above helps in resolving connection errors when connecting to RabbitMQ using Java.
When using Java to connect to a RabbitMQ service on a remote node using the rabbit java client, there are connection errors as below:
I have installed Rabbitmq server on Debian or Rhel machine. I want to connect this
machine and publish message on it.o
factory = new ConnectionFactory();
logger.info("successfully opening a Connection to an AMQP broker..");
factory.setUsername("guest");
logger.info("Set the user name...");
factory.setPassword("guest");
logger.info("Set the password...");
factory.setVirtualHost("/");
logger.info("Set the virtual host...");
factory.setHost("192.168.x.x"); //my server IP Address
logger.info("The default host to use for connections..");
factory.setPort(5672);
logger.info("Set the target port..");
connection = factory.newConnection();
when i tried i got the following error:
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at
com.rabbitmq.client.ConnectionFactory.createFrameHandler(ConnectionFactory.java:342)
at
com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:380)
at
com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:403)
at RabbitMQProducer12.producer(RabbitMQProducer12.java:43)
at RabbitMQProducer12.main(RabbitMQProducer12.java:78)
To resolve the above issue:1) Modify the Java code by adding the lines shown below, by adding the protocol using the factory methods. Specify the other parameters username, password,port ect. in addition to this.
String protocol = "TLSv1";
ConnectionFactory factory = new ConnectionFactory();
factory.useSslProtocol(this.protocol);
and specify the protocol to be used to connect to rabbitMQ.
2) Also specify the protocol in the rabbitMQ configuration file /etc/rabbitmq/rabbitmq.config.
[
{kernel, [
]},
{ssl, [{versions, ['TLSv1']}]},
{rabbit, [
{ssl_listeners, [5671]},
{ssl_options, [{cacertfile,"/etc/rabbitmq/ssl/cacert.pem"},
{certfile,"/etc/rabbitmq/ssl/cert.pem"},
{keyfile,"/etc/rabbitmq/ssl/key.pem"},
{verify,verify_none},
{fail_if_no_peer_cert,false}
,{versions,['TLSv1']}
.....
..........
.........
]}
]
Using step 1 and 2 above helps in resolving connection errors when connecting to RabbitMQ using Java.
No comments:
Post a Comment