Home / .NET / NServiceBus new transports around the corner

NServiceBus new transports around the corner

Yes you hear right! That is one of the major upcoming and most exciting new feature which will be available in NServiceBus 4.0.0. Transports, transports and transports… NServiceBus out of the box supported MSMQ and also Azure transports. But now there are even more transports available! The 4.0.0 version will ship with the following transports on board: ActiveMQ, RabbitMQ, Sql Server, Azure and MSQM. Of course each transport comes with certain features or even restrictions but from now on you have a lot of choices depending on your infrastructure or interoperability needs. In the future blog posts we will dive into at least one of the transports mentioned above and deep dive what it offers compared to the other transports. But first I want to show you how you can configure each transport with the unified configuration/connection settings approach.

We first start with the configuration approach of the transport when you are using the NServiceBus.Host.exe. Configuring a different transport than the default MSMQ transport is pretty straight forward. Simply declare on you EndpointConfig.cs the following:

	// RabbitMQ
    public class EndpointConfig : IConfigureThisEndpoint, ..., 
		UsingTransport<NServiceBus.RabbitMQ>
    {
    }
	
	// ActiveMQ
    public class EndpointConfig : IConfigureThisEndpoint, ..., 
		UsingTransport<NServiceBus.ActiveMQ>
    {
    }

	// SqlServer
    public class EndpointConfig : IConfigureThisEndpoint, ..., 
		UsingTransport<NServiceBus.SqlServer>
    {
    }		

or if you use IWantCustomInitialization you can use the following approach (which is also the one you’d have to take when using self-hosting):

	// RabbitMQ
    public class EndpointConfig : IConfigureThisEndpoint, ..., IWantCustomInitialization
    {
		public void Init() {
			Configure.With()
				.UseTransport<NServiceBus.RabbitMQ>()
				...
		}
    }
	
	// ActiveMQ
    public class EndpointConfig : IConfigureThisEndpoint, ..., IWantCustomInitialization
    {
		public void Init() {
			Configure.With()
				.UseTransport<NServiceBus.ActiveMQ>()
				...
		}
    }
	
	// you see the pattern...

You might wonder how NServiceBus knows to which server, broker or connection hub the transport layer has to be connected to. By default if you don’t specify a connection string by using on of the UseTransport overloads it assumes that you have a connection string defined in your endpoints application configuration file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="NServiceBus/Transport" connectionString="host=localhost"/>
  </connectionStrings>
</configuration>

The connection string has to be named with the following constant: “NServiceBus/Transport”

Of course it is also possible to define a connection string in code. By specifying the string in the UseTransport overload. For example a connection string to the ActiveMQ broker which is running on localhost would look like:

            var config = Configure.With()
                .UseTransport<ActiveMQ>(() => "activemq:tcp://localhost:61616")

Happy transporting…