'Why I cannot create queue in rabbitmq in Windows?

I'm new to RabbitMQ.

I installed RabbitMQ server on Windows 10. I can login to the server in web browser. When I run the client code below (uses AMQP-CPP library), neigther channel.onSuccess nor channel.onError are called. And, I don't see my declared my-queue queue and my-exchange exchange in the web browser.

If I understood correctly, I need to add some event loop (?). But, I cannot find any example for Windows. Can you explain what can be the issue?

int main()
{
    // create an instance of your own tcp handler
    MyTcpHandler myHandler;

    // address of the server
    //AMQP::Address address("amqp://guest:guest@localhost:5672/");
    AMQP::Address address("localhost", 15672, AMQP::Login("guest", "guest"), "");

    // create a AMQP connection object
    AMQP::TcpConnection connection(&myHandler, address);

    // and create a channel b
    AMQP::TcpChannel channel(&connection);

    // use the channel object to call the AMQP method you like
    channel.declareExchange("my-exchange", AMQP::fanout)
        .onSuccess([]()
    {
        std::cout << "declared exchange " << std::endl;
    }).onError([](const char *message)
    {
        std::cout << "error: " << message << std::endl;

    });

    channel.declareQueue("my-queue");
    channel.bindQueue("my-exchange", "my-queue", "my-routing-key");

    std::cout << "Press Enter..." << std::endl;
    std::getchar();

    return 0;
}

MyTcpHandler

class MyTcpHandler : public AMQP::TcpHandler
{
public:

    virtual void onConnected(AMQP::TcpConnection *connection) {}
    virtual void onError(AMQP::TcpConnection *connection, const char *message) {}
    virtual void onClosed(AMQP::TcpConnection *connection) {}
    virtual void monitor(AMQP::TcpConnection *connection, AMQP::tcp::Socket fd, int flags) {}
};


Solution 1:[1]

You are connecting on the wrong port 15672 is the management plugin port , you need to connect on Port 5672 which is the AMQP port

Please correct the code as under

AMQP::Address address("localhost", 5672, AMQP::Login("guest", "guest"), "");

Solution 2:[2]

You could just use HareDu 2 Broker API to do it using the below code. Docs can be found here: https://github.com/ahives/HareDu2

var result = _container.Resolve<IBrokerObjectFactory>()
                .Object<Queue>()
                .Create(x =>
                {
                    x.Queue("your_queue");
                    x.Configure(c =>
                    {
                        c.IsDurable();
                        c.AutoDeleteWhenNotInUse();
                        c.HasArguments(arg =>
                        {
                            arg.SetQueueExpiration(1000);
                            arg.SetPerQueuedMessageExpiration(2000);
                        });
                    });
                    x.Targeting(t =>
                    {
                        t.VirtualHost("your_vhost");
                        t.Node("your_node");
                    });
                });

Solution 3:[3]

came across same issue myself today.
The problem is you have to implement your own hanlder, or nothing will be sent.

The bundled TcpHandler is based on boost asio tcpHandler which is posix only, and will not compile on windows. see this link

Too shame it's doesn't have internal built-in handler, this is so "basic"...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Soumen Mukherjee
Solution 2 Albert
Solution 3