Connecting to RabbitMQ Across Machines With .NET Clients
Trying to connect to RabbitMQ with .NET clients? Here's a great tutorial which builds on RabbitMQ with .NET basics.
Join the DZone community and get the full member experience.
Join For Freemy earlier article “ getting started with rabbitmq with .net ” showed how it’s easy to use the rabbitmq .net client to connect to an instance of rabbitmq running locally. in fact, omitting the code that declares a queue and consumes messages, we are essentially left with this:
static void main(string[] args)
{
var factory = new connectionfactory() { hostname = "localhost" };
using (var connection = factory.createconnection())
{
console.writeline("connected!");
console.readline();
}
}
if we replace
localhost
with the hostname of a machine which actually does have a rabbitmq instance running, however, we’re in for a surprise:
this stackoverflow answer
suggests that we may need a username and password when setting up the connection. we can add these by changing our
factory
declaration as follows:
var factory = new connectionfactory()
{
hostname = "ariel",
username = "joe",
password = "joe"
};
connections using the default guest user don’t seem to work across machines, so we’re going to have to create a user account.
from the rabbitmq management ui, add a new user, giving him all tags available (
administrator,monitoring,policymaker,management
):
that’s not enough to connect using our new user, though. you can see why if you click on the user:
you can easily rectify the problem by clicking on that set permission button to give the new user access to the root ( / ) virtual host. note that this can also be done from the virtual hosts section… but doing it from the user page is easier.
it works now. yay.
Published at DZone with permission of Daniel D'agostino, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments