Search code examples
c#rabbitmqmasstransitcloudamqp

How to connect MassTransit with RabbitMq on CloudAMQP


I have problem to connect MassTransit with RabbitMq on CloudAMQP. Below is my code

var bus = Bus.Factory.CreateUsingRabbitMq(otions => {
    var host = otions.Host(new Uri("rabbitmq://llama-01.rmq.cloudamqp.com"),
    h => { h.Username("my_username"); h.Password("my_password"); });
    otions.ReceiveEndpoint(host, "recvqueue", ep => {
        ep.Handler<Communicate>(Handle);
    });
});

bus.Start();

h.Password and h.Username are correct. While I try to start the bus I get following error:

RabbitMQ Connect Failed: Broker unreachable: [email protected]:5672/

I suspect that the problem is in URI address but I can't find out the correct one.


Solution

  • Well, I quickly browsed their Getting Started and I can see that your instance gets a vhost that has the same name as your user.

    enter image description here

    The image above is what I've got after subscribing to a free plan.

    For MassTransit, you either need to add the vhost at the end of your connection string, like rabbitmq://llama-01.rmq.cloudamqp.com/my_username, or configure it in the host configuration, along with the username and password.