Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring

Unobtrusive

Component: NServiceBus
NuGet Package: NServiceBus (9.x)

Code walk-through

There sample consists of the following projects:

  • Client: sends a request and a command to the server and handles a published event
  • Server: handles requests and commands, and publishes events
  • Shared: the shared message definitions

Configuring conventions for unobtrusive mode

The ConventionExtensions class tells NServiceBus how to determine which types are message definitions by passing in custom conventions instead of using the IMessage, ICommand, or IEvent interfaces:

public static void ApplyCustomConventions(this EndpointConfiguration endpointConfiguration)
{
    var conventions = endpointConfiguration.Conventions();

    conventions.DefiningCommandsAs(
        type =>
        type.Namespace != null &&
        type.Namespace.EndsWith("Commands"));

    conventions.DefiningEventsAs(
        type =>
        type.Namespace != null &&
        type.Namespace.EndsWith("Events"));

    conventions.DefiningMessagesAs(
        type => type.Namespace == "Messages");

    conventions.DefiningDataBusPropertiesAs(
        property => property.Name.EndsWith("DataBus"));

    conventions.DefiningTimeToBeReceivedAs(
        type =>
        {
            if (type.Name.EndsWith("Expires"))
            {
                return TimeSpan.FromSeconds(30);
            }
            return TimeSpan.MaxValue;
        });
}

It also demonstrates how to configure conventions for the data bus and time-to-be-received features.

Related Articles