Skip to content

Latest commit

 

History

History
145 lines (75 loc) · 5.3 KB

message-owner.md

File metadata and controls

145 lines (75 loc) · 5.3 KB
title summary tags redirects related
Specifying a message owner
Configure the owning endpoint for message types.
Message Mapping
Message destination
Mapping
nservicebus/how-do-i-specify-to-which-destination-a-message-will-be-sent
nservicebus/messaging/specify-message-destination
samples/pubsub

NServiceBus had the concept of an "Owning Endpoint" for any given message type.

Message mapping is a configurable convention that, based on some information about a message, that message can be routed to a specific endpoint without the sending code needing to be aware of the destination. A message mapping contains the following information.

How "Owning Endpoint" manifests

When Sending a message

When a message is sent (and no destination is specified) then that message type be routed to the owning endpoint.

At startup on a subscriber

When a endpoint is started the Auto Subscribe functionality will use the owning endpoint to determine which message, and on which endpoint, should be subscribed to.

Message Mapping

The owning endpoint for any given message type can be configured using message mappings.

An endpoint may have multiple message mappings where each mapping consists of two pieces of information:

1. The Owning "Endpoint"

The owning endpoint (sometimes referred to as "target" or "destination" endpoint) can be of the form QueueName@ServerName, or just QueueName if the destination is the local machine.

2. Resolving the Messages Types to map

This allows the mapping to know which message types to include in the mapping.

There are two, mutually exclusive approaches, to message resolution:

Resolving with the Assembly

If this is defined then all types in that assembly will included in the initial set. This effectively uses Assembly.Load(Assembly) followed by Assembly.GetTypes().

Note: This value is the AssemblyName not the file name.

Filtering

The type list from Assembly can be further filtered via one of the following:

  • Type: If Type is defined then only that type will be included in the mapping. This effectively calls Assembly.GetType on the Assembly resolved via Assembly.
  • Namespace: If Namespace is defined then only the types that have that namespace will be included in the mapping. It does not include sub namespaces.

{{Note: The xml configuration version (app.config) the the code based API differ slightly.

In app.config the attributes are Assembly and Type.

In the code API the properties are AssemblyName and TypeFullName. }}

Resolving with Messages

If the Messages represents a valid Type (i.e. Type.GetType returns a Type) then that type will be mapped to the target endpoint.

Otherwise it will be assumed Messages is an assembly name and all types in that assembly will be mapped to the target endpoint. This effectively uses Assembly.Load(Assembly) followed by Assembly.GetTypes().

WARNING: Since Messages is ambiguous in its usage the Assembly, Type and Namespace attributes are the recommended approach for mapping types. The Messages attribute is still supported for backwards comparability.

Some example mappings

To register all message types defined in an assembly:

  • Assembly = YourMessagesAssemblyName
  • Endpoint = queue@machinename

To register all message types defined in an assembly with a specific namespace:

  • Assembly = YourMessagesAssemblyName
  • Namespace = YourMessageNamespace
  • Endpoint = queue@machinename

To register a specific type in an assembly:

  • Assembly = YourMessagesAssemblyName
  • Type = YourMessageFullTypeName
  • Endpoint = queue@machinename

Conventions

Note that any types resolved as message from the above process are then further filtered by passing them through the Message conventions.

Configuring Endpoint Mapping

Endpoint mapping can be configured in several ways

Using app.config

You configure mapping in your app.config by adding <UnicastBusConfig> and <MessageEndpointMappings> nodes.

Using a ConfigurationSource

The IConfigurationSource

Injecting the IConfigurationSource

Using a configuration provider

Bypassing the owning endpoint

You can also call the following, even though it is not recommended for application-level code:

Bus.Send(string destination, object message);

Even if it is possible to specify a message destination in code it is highly suggested to specify message destinations at application-configuration level to maintain a high level of flexibility.