The sample demonstrates how to use a file to describe the mapping between logical endpoints and their physical instances (deployments of given logical endpoint to a concrete VM).
Make sure MSMQ is set up as described in the MSMQ Transport - NServiceBus Configuration section.
- Start the solution
- The text
Press <enter> to send a messageshould be displayed in the Client's console window.
- Hit enter several times to send some messages.
- The Sales.1 and Sales.2 consoles display information about accepted orders in round-robin fashion.
- The Shipping endpoint displays information that orders were shipped.
- The Billing endpoint displays information that orders were billed.
This sample contains four projects.
Shared between all endpoints.
<endpoints> <endpoint name="Samples.InstanceMappingFile.Sales"> <!-- Scaled-out endpoint --> <instance queue="Samples.InstanceMappingFile.Sales-1"/> <instance queue="Samples.InstanceMappingFile.Sales-2"/> </endpoint> <!--Multiple endpoints hosted on same machine--> <endpoint name="Samples.InstanceMappingFile.Billing"> <instance machine="localhost"/> </endpoint> <endpoint name="Samples.InstanceMappingFile.Shipping"> <instance machine="localhost"/> </endpoint> </endpoints>
The Client application submits the orders for processing by the back-end systems by sending a
PlaceOrder command. The client, as well as all other endpoints, uses the file based instance mapping:
var transport = endpointConfiguration.UseTransport<MsmqTransport>(); var routing = transport.Routing(); var routingTable = routing.InstanceMappingFile(); routingTable.FilePath(@"..\..\..\instance-mapping.xml");
The Sales application accepts clients' orders and publishes the
Shipping and Billing applications subscribe to
OrderAccepted event in order to execute their business logic.
The shared project contains definitions for messages.
For the sake of simplicity, in this sample all the endpoints run on a single machine. In real world is is usually best to run each instance on a separate virtual machine. In such case the instance mapping file would contain
machine attributes mapping instances to their machines' host names instead of
queue attributes used to run more than one instance on a single box.