Wednesday, July 12, 2023

RabbitMQ: Application terminated: factory failed to instantiate due to: Unsupported or unrecognized SSL message.

 

>PROBLEM


Attempt to access the RabbitMQ service, throws the follwing:


Application terminated: factory failed to instantiate due to: Unsupported or unrecognized SSL message.

javax.net.ssl.SSLException: java.net.SocketException: Connection reset

at sun.security.ssl.Alert.createSSLException(Alert.java:127)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:370)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:313)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:308)

at sun.security.ssl.SSLTransport.decode(SSLTransport.java:141)

at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1290)

...

Suppressed: java.net.SocketException: Connection reset by peer: socket write error

at java.net.SocketOutputStream.socketWrite0(Native Method)

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)

...

Caused by: java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:210)

at java.net.SocketInputStream.read(SocketInputStream.java:141)

at sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:475)

...

javax.net.ssl.SSLException: java.net.SocketException: Connection reset

at sun.security.ssl.Alert.createSSLException(Alert.java:127)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:370)

at sun.security.ssl.TransportContext.fatal(TransportContext.java:313)

...

Caused by: java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:210)

at java.net.SocketInputStream.read(SocketInputStream.java:141)

at sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:475)


>SOLUTION


Enable or disable the SSL protocol.

An example of the properties file (application.yml):


  rabbit-host: mydomain.com 

  rabbit-port: 5672

  rabbit-ssl: false

  rabbit-user: john doe

  rabbit-pass: secret



Java code snippet to check the "rabbit-ssl" property:


if (PropertiesYml.BROKER_SSL) {

try {

factory.useSslProtocol();

this.connection = factory.newConnection();

} catch (KeyManagementException | NoSuchAlgorithmException | IOException | TimeoutException e) {

logger.error(String.format("Application terminated: factory failed to instantiate due to: %s.", e.getMessage()));

}

} else {

try {

this.connection = factory.newConnection();

} catch (IOException | TimeoutException e) {

logger.error(String.format("Application terminated: factory failed to instantiate due to: %s.", e.getMessage()));

}

}


>ENV

RabbitMQ v3.7.8
Erlang v21.2.6
Java 17

RabbitMQ: Caused by: com.rabbitmq.client.ShutdownSignalException: connection error, java.io.IOException, Caused by: java.io.EOFException


>PROBLEM


Attempt to connect to RabbitMQ returns the following:


java.io.IOException

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129)

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125)

at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:396)

...

Caused by: com.rabbitmq.client.ShutdownSignalException: connection error

...

Caused by: java.io.EOFException

at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)

...

Caused by: com.rabbitmq.client.ShutdownSignalException: connection error

...

Caused by: java.io.EOFException

at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)

...

java.io.IOException

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:129)

at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:125)

at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:396)

...

Caused by: com.rabbitmq.client.ShutdownSignalException: connection error

Caused by: java.io.EOFException

at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:290)

...



>SOLUTION


Check the following:

1.Usually, the console management uses 15672 port.

2. Usually, the HTTP request via app (web service/microserve) uses 5672

3. Make sure to enable these ports when working with container (docker).

4. Avoid using /api  on a RESTful web service because "/api" is already used by the native rabbitmq's ws,



An example of the properties file (application.yml):

  rabbit-host: mydomain.com 

  rabbit-port: 5672

  rabbit-ssl: false

  rabbit-user: john doe

  rabbit-pass: secret


>ENV

RabbitMQ v3.7.8
Erlang v21.2.6
Java 17

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...