Skip to content
Attribute Routing support for NServiceBus messages and commands
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Enables to configure messages and commands routing by using attributes on message types:

public class SampleMessage

NOTE: Attributes are defined in a separate NServiceBus.AttributeRouting.Contracts package to prevent coupling endpoints to the NServiceBus version this feature depends on.

and when configuring the endpoint:


NOTE: Only Messages and Commands are supported. In NServiceBus Events are treated differently based on the underlying transport capabilities: If the transport supports native pub/sub (e.g. RabbitMQ or Azure Service Bus) everything is handled automatically, otherwise publishers needs to be manually registered. As of now registering publishers using attributes is not supported.

Routes override

Attributes based routes are applied after explicitely defined routes, this allows to define overrides for routes defined using attributes.

Use case: an assembly containing a message decorated with the RouteTo attribute is distributed to endpoints. Later handlers topology change causing the message to end up at the wrong destination service.

In such a scenario it’s suggested to deploy a new version of the messages assembly, if this is not possibile on not doable in a timely fashion attribute based routes can be overwritten by explicitly defining routes for a given message. If SampleMessage is the message type for which a route override needs to be defined, endpoint configuration can be changed as follows:

      .RouteToEndopoint( typeof( SampleMessage ), "NewDestination" );

NewDestination will take precedence over DestinationEndpoint.


Nuget package:

Icon: route by revo250 from the Noun Project

You can’t perform that action at this time.