RabbitMQ连接重置异常

问题描述 投票:0回答:1

我对此问题有同样的问题:RabbitMQ Connection reset。我的代码在kotlin中,来自https://www.rabbitmq.com/ssl.html#java-client-connecting

        val connectionFactory = ConnectionFactory()
        connectionFactory.host = "localhost"
        connectionFactory.port = 5671
        connectionFactory.useSslProtocol()

        val connection = connectionFactory.newConnection()
        val channel = connection.createChannel();

        channel.queueDeclare("rabbitmq-java-test", false, true, true, null);
        channel.basicPublish("", "rabbitmq-java-test", null, "Hello, World!".toByteArray())

        val response = channel.basicGet("rabbitmq-java-test", false)
        if (response == null) {
            println("No message retrieved")
        } else {
            val body = response.body
            println(String(body))
        }

        channel.close()
        connection.close()

我以这种方式配置了RabbitMQ:

[
    {rabbit, [
        {loopback_users, []},
        {ssl_listeners, [5671]},
        {ssl_options, [{cacertfile, "path\to\rabbitCA.pem"},
                       {certfile, "path\to\localhost-crt.pem"},
                       {keyfile, "path\to\localhost-key.pem"},
                       {verify, verify_peer},
                       {fail_if_no_peer_cert, false}]},
        {log, [{file, [{level, debug}]}
      ]
    }
].

我测试了这个:https://www.rabbitmq.com/troubleshooting-ssl.html#sclient-connection并在cmd中获得结果:

OpenSSL> s_client -connect localhost:5671 -cert client-certificate.pem -key client-key.pem -CAfile rabbitCA.crt
CONNECTED(00000198)
write:errno=10054
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 293 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
error in s_client

RabbitMQ日志(尝试连接1次:):>

2020-05-21 21:12:38.821 [debug] <0.2147.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:38.852 [debug] <0.2148.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:44.120 [debug] <0.2155.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:44.137 [debug] <0.2156.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:48.827 [debug] <0.2162.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:48.846 [debug] <0.2163.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:54.124 [debug] <0.2171.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:54.150 [debug] <0.2172.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:58.820 [debug] <0.2178.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:12:58.835 [debug] <0.2179.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:04.121 [debug] <0.2186.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:04.143 [debug] <0.2188.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:08.817 [debug] <0.2194.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:08.835 [debug] <0.2195.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:10.325 [debug] <0.2199.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:10.354 [debug] <0.2200.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:14.120 [debug] <0.2217.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:14.141 [debug] <0.2218.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:18.817 [debug] <0.2225.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal
2020-05-21 21:13:18.832 [debug] <0.2226.0> User 'guest' authenticated successfully by backend rabbit_auth_backend_internal

而且例外,它来自于“ val connection = connectionFactory.newConnection()”的行

2020-05-21 21:13:10,669 [Test worker] WARN  com.rabbitmq.client.TrustEverythingTrustManager - This trust manager trusts every certificate, effectively disabling peer verification. This is convenient for local development but prone to man-in-the-middle attacks. Please see http://www.rabbitmq.com/ssl.html#validating-cerficates to learn more about peer certificate validation.

Connection reset
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.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
    at sun.security.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1779)
    at sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:124)
    at sun.security.ssl.Handshaker.kickstart(Handshaker.java:1093)
    at sun.security.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1497)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1361)
    at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:757)
    at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
    at java.io.DataOutputStream.flush(DataOutputStream.java:123)
    at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:147)
    at com.rabbitmq.client.impl.SocketFrameHandler.sendHeader(SocketFrameHandler.java:153)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:303)
    at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:64)
    at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:134)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:997)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:956)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:914)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1068)

[当我尝试在Erlang https://www.rabbitmq.com/troubleshooting-ssl.html#verify-tls-support-in-erlang中检查TLS支持时,我在日志中得到此信息:

2020-05-21 21:52:03.031 [error] <0.1530.0> ** Connection attempt from disallowed node 'rabbitmqcli-23412-rabbit@DESKTOP-UI450MM' ** 
2020-05-21 21:52:03.065 [error] <0.1533.0> ** Connection attempt from disallowed node 'rabbitmqcli-23412-rabbit@DESKTOP-UI450MM' ** 

我也尝试为connectionFactory.useSslProtocol(SSLContext sslContext)方法配置SSLContext,但是输出是相同的,除了关于信任管理器的字符串,只是一个例外。我不明白哪里出了问题

我对此问题有同样的问题:RabbitMQ连接重置。我的代码在kotlin中,并且来自https://www.rabbitmq.com/ssl.html#java-client-connecting。 val connectionFactory = ...

java ssl rabbitmq
1个回答
0
投票

好吧,答案很简单:如果使用Windows,则需要为路径添加反斜杠。路径为{cacertfile,“ \\ path \\ to \\ rootCA.pem”}。

© www.soinside.com 2019 - 2024. All rights reserved.