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.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
src
targets
.editorconfig
.gitattributes
.gitignore
.travis.yml
Directory.Build.props
LICENSE
README.md
appveyor.yml
build.cmd
build.sh

README.md

NServiceBus.AttributeRouting

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

[RouteTo("DestinationEndpoint")]
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:

endpointConfiguration.UseAttributeRouting();

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:

endpointConfiguration.UseTransport<YourChoice>()
   .Routing()
      .RouteToEndopoint( typeof( SampleMessage ), "NewDestination" );
endpointConfiguration.EnableAttributeRouting();

NewDestination will take precedence over DestinationEndpoint.

Downloads

Nuget package: https://www.nuget.org/packages/NServiceBus.AttributeRouting/


Icon: route by revo250 from the Noun Project

You can’t perform that action at this time.