Search code examples
c#rabbitmqsocketexceptioneasynetqeconnrefused

SocketException: Connection refused using EasyNetQ ManagementClient


I have RabbitMQ with management console installed on my machine. Web interface is working on http://localhost:15672

When I try to access Rabbit via code, I'm getting an exception:

var mcGuest = new ManagementClient("http://localhost", "guest", "guest", 15672);
var vhost = mcGuest.GetVhost("/");

{"No connection could be made because the target machine actively refused it [::1]:15672"}

(source code for Management Client at https://github.com/EasyNetQ/EasyNetQ.Management.Client)

I'm running Visual Studio as Administrator, getting following output when running netstat -anb:

Line 35:   TCP    0.0.0.0:5672           0.0.0.0:0              LISTENING
Line 37:   TCP    0.0.0.0:15672          0.0.0.0:0              LISTENING
Line 39:   TCP    0.0.0.0:25672          0.0.0.0:0              LISTENING
Line 200:   TCP    127.0.0.1:15672        127.0.0.1:18577        ESTABLISHED
Line 212:   TCP    127.0.0.1:18577        127.0.0.1:15672        ESTABLISHED
Line 484:   TCP    [::]:5672              [::]:0                 LISTENING

What could be the issue?


Solution

  • Apparently the issue is with IPv6. Could be related to my environment.

    When running EasyNetQ api on Debug, IPv6 is used and I'm getting the error. When running on Release, IPv4 is used and sockets works.

    The immediate solution is to use

    new ManagementClient("http://127.0.0.1", "guest", "guest", 15672);
    

    Though I still don't know why localhost and IPv6 wouldn't work. You can see IPv6 is used by the exception details - [::1] which stands for localhost IP in v6.