I recently needed to upgrade several NServiceBus endpoints to Version 5. As usually happens with major version upgrades, lots of things change. I should have just installed the NSB sample projects and taken the time to review some of the new syntax, but I needed to convert and deploy asap.
In this post I will document how I converted my NserviceBus configuration statements from version 3 to version 5. I have not used version 4 so I can’t speak directly to converting that vesrion. However, the Particular website uses version 3/4 together several times so one might assume 3 and 4 are virtually the same.
IConfigureThisEndpoint
The IConfigureThisEnpoint interface is still applicable but the signature of the method you must implement has changed from Init() to Customize(BusConfiguration). Instead of accessing the configuration through static method on the Configure object, NServiceBus passes an instance of the configuration to the new method. Additionally, the marker Interface AsA_Publisher is no longer valid.
Version 3
public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher { public void Init() { ... Setup the endpoint } }
Version 5
public class EndpointConfig : IConfigureThisEndpoint { public void Customize(BusConfiguration configuration) { ... Setup the endpoint } }
Configure.With()
Version 3
Configure .With(AllAssemblies.Except("some.dll"))
Vesion 5
configuration.AssembliesToScan( AllAssemblies.Except("some.dll"));
Persistence
If you continue to use RavenDB as your persistence database, you’ll now need to specify it explicitly.
Version 5
configuration.UsePersistence<RavenDBPersistence>();
Transport
LIkewise MSMQ is no longer the default Transport method, so you must specify it explicitly, or override and use an alternative.
Version 5
configuration.UseTransport<MsmqTransport>();
Dependency Injection Container
Version 3
Configure .AutofacBuilder()
Vesrion 5
configuration.UseContainer<AutofacBuilder>();
FileShareDataBus
Version 3
Configure .FileShareDataBus("\\some\folder")
Version 5
configuration.UseDataBus<FileShareDataBus>().BasePath("\\some\folder");
Message Conventions
Version 3
Configure .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.Contains(".Commands"))
Version 5
configuration .Conventions().DefiningCommandsAs(t => t.Namespace != null && t.Namespace.Contains(".Commands"));
Transaction Isolation Level
Version 3
Configure.Instance.IsolationLevel(IsolationLevel.ReadCommitted);
Version 5
configuration.Transactions().IsolationLevel(IsolationLevel.ReadCommitted);
Configure Component
Version 3
Configure.Instance.Configurer .ConfigureComponent<MyService>(DependencyLifecycle.InstancePerCall);
Version 5
config.RegisterComponents(c => c.ConfigureComponent<MyService>(DependencyLifecycle.InstancePerCall));
That wraps up what I wanted to document here (for myself as much as anything). I will probably find other configuration options that need to be documented here, but this is a start.
Thanks for reading.
Tags: NServiceBus, programming, Upgrade
Leave a comment