Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring

Unobtrusive

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

Run the solution. Two console applications should start up, Client and Server.

Configuring conventions for unobtrusive mode

Look at the ConventionExtensions class. The code 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 =>
        {
            return type.Namespace != null &&
                   type.Namespace.EndsWith("Commands");
        });
    conventions.DefiningEventsAs(
        type =>
        {
            return type.Namespace != null &&
                   type.Namespace.EndsWith("Events");
        });
    conventions.DefiningMessagesAs(
        type =>
        {
            return type.Namespace == "Messages";
        });
    conventions.DefiningDataBusPropertiesAs(
        property =>
        {
            return property.Name.EndsWith("DataBus");
        });
    conventions.DefiningTimeToBeReceivedAs(
        type =>
        {
            if (type.Name.EndsWith("Expires"))
            {
                return TimeSpan.FromSeconds(30);
            }
            return TimeSpan.MaxValue;
        });
}

The code tells NServiceBus to treat all types with a namespace that ends with "Messages" the same as for messages that explicitly implement IMessage.

It also shows the unobtrusive way to tell NServiceBus which properties to deliver on a separate channel from the message itself using the data bus feature, and which messages have a defined time to be received.

Look at the code. There are a number of projects in the solution:

  • 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

Related Articles


Last modified