Skip to main content

MassTransit–Using RabbitMQ Virtual Hosts

Today I want to talk about a specific feature in RabbitMQ and how we can use this feature with my favorite messaging library MassTransit.

Virtual Hosts

With virtual hosts you can create a logical grouping in  your RabbitMQ cluster. Every exchange, queue, binding, user permissions, and so on is bound to a specific virtual host and isolated from the other virtual hosts. This helps to avoid naming collisions.

There is always at least one virtual host in use; the default one is ‘/’.

To create a new virtual host in your RabbitMQ cluster, you can use the rabbitmqctl's add_vhost command:

rabbitmqctl add_vhost development

Or you can use the RabbitMQ Management portal:

  • In the Management Portal go to the Admin tab and click on the Virtual Hosts section on the right:

  • Go to the Add Virtual Host form and enter a name and an optional description and tags:

  • Click on Add virtual host to create the new virtual host.

Remark: Be aware that virtual hosts are a security boundary, so I would recommend to create different users per virtual host.

Using Virtual Hosts in MassTransit

Now that we have a new Virtual Host created, let’s see how we can use this in MassTransit.

Let’s have a look at a simple example from the MassTransit documentation:

In the example above, the virtual host is passed as a second parameter after the servername in the Host() method:

You can also specify it through the URI:

Popular posts from this blog

XUnit - Assert.Collection

A colleague asked me to take a look at the following code inside a test project: My first guess would be that this code checks that the specified condition(the contains) is true for every element in the list.  This turns out not to be the case. The Assert.Collection expects a list of element inspectors, one for every item in the list. The first inspector is used to check the first item, the second inspector the second item and so on. The number of inspectors should match the number of elements in the list. An example: The behavior I expected could be achieved using the Assert.All method:

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

Angular --deploy-url and --base-href

As long you are running your Angular application at a root URL (e.g. www.myangularapp.com ) you don’t need to worry that much about either the ‘--deploy-url’ and ‘--base-href’ parameters. But once you want to serve your Angular application from a server sub folder(e.g. www.mywebsite.com/angularapp ) these parameters become important. --base-href If you deploy your Angular app to a subfolder, the ‘--base-href’ is important to generate the correct routes. This parameter will update the <base href> tag inside the index.html. For example, if the index.html is on the server at /angularapp/index.html , the base href should be set to <base href="/angularapp/"> . More information: https://angular.io/guide/deployment --deploy-url A second parameter that is important is ‘--deploy-url’. This parameter will update the generated url’s for our assets(scripts, css) inside the index.html. To make your assets available at /angularapp/, the deploy url should