title | summary | tags | redirects | related | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Specifying a message owner |
Configure the owning endpoint for message types. |
|
|
|
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.
When a message is sent (and no destination is specified) then that message type be routed to the owning endpoint.
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.
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:
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.
This allows the mapping to know which message types to include in the mapping.
There are two, mutually exclusive approaches, to message resolution:
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.
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 viaAssembly
. - 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
.
}}
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.
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
Note that any types resolved as message from the above process are then further filtered by passing them through the Message conventions.
Endpoint mapping can be configured in several ways
You configure mapping in your app.config by adding <UnicastBusConfig>
and <MessageEndpointMappings>
nodes.
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.