The sample demonstrates how to use a file to describe the mapping between logical endpoints and their physical instances (i.e. deployments of a given logical endpoint to a concrete virtual machine).
Ensure MSMQ is installed and configured as described in the MSMQ transport - MSMQ configuration section.
- Start the solution
- The text
Pressshould be displayed in the Client's console window.
<enter> to send a message
- Press 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 client orders and publishes the
The Shipping and Billing applications subscribe to
OrderAccepted events in order to execute their business logic.
The shared project contains definitions for messages.
For the sake of simplicity, all the endpoints in this sample run on a single machine. In production, it is recommended to run each instance on a separate virtual machine. In this 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.