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");
#pragma warning disable CS0618 // Type or member is obsolete
conventions.DefiningDataBusPropertiesAs(
property => property.Name.EndsWith("DataBus"));
#pragma warning restore CS0618 // Type or member is obsolete
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.