bloomberg / amqpprox

An AMQP 0.9.1 proxy server, designed for use in front of an AMQP 0.9.1 compliant message queue broker such as RabbitMQ.
Apache License 2.0
78 stars 16 forks source link

Expose received broker connection close method, in case of any error, to client during handshake #72

Closed Chinmay1412 closed 2 years ago

Chinmay1412 commented 2 years ago

At the moment, if client is not able to connect to broker because of reasons like invalid credentials, port, user or anything else, broker sends the connection Close method to the amqpprox server. And amqpprox immediately shutdowns and closes the sockets for clients. Because of that, client never receives the connection Close method, which is not good for the client. Because the Close method specifies the reason behind the closing the connection abruptly and it would be hard for client to debug any existing problem. So this PR fixes that issue. And it forwards the received connection close method to client. This way client will be able to know the reason of closure during handshake. And then it continues to shutdown and close sockets. Once we have the successful connection, amqpprox will forwards complete traffic to client as usual.

For example, if any client tries to connect to any vhost using wrong credentials, amqpprox will get the connection Close method from the server. And amqpprox will forward this method to client, before shutting down the socket.

Sample received Close method on client side, which describes the correct reason of the disconnection:

Received message: MESSAGE=Connection Close = [replyCode: 403, replyText: "ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.", classId: 0, methodId: 0] CHANNEL=0 LEN=119