Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit 234410a

Browse files
authored
Create README.md
1 parent 9f3b304 commit 234410a

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# NServiceBus.FileBasedRouting
2+
An alternative approach to configure message routing information and event subscribers via XML file. The routing file can be configured once and then shared across all endpoints for easier routing and publish/subscribe management.
3+
4+
5+
## Configuration
6+
7+
Enable the `FileBasedRouting` feature in the endpoint configuration:
8+
9+
endpointConfiguration.EnableFileBasedRouting();
10+
11+
This will configure the endpoint to look for a `endpoints.xml` file in the endpoints [base directory](https://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory(v=vs.110).aspx).
12+
13+
It is possible to configure a different relative or absolute file path, e.g.:
14+
15+
endpointConfiguration.EnableFileBasedRouting(@"C:\routingFile.xml");
16+
17+
The routing file provides routing information like shown in the following example:
18+
19+
Create a new XML file named `endpoints.xml` and include it on every endpoint using file based routing.
20+
21+
```
22+
<endpoints>
23+
<endpoint name="endpointA">
24+
<handles>
25+
<!-- Define that endpointA can handle the DemoCommand command -->
26+
<command type="Contracts.Commands.DemoCommand, Contracts" />
27+
<!-- Define that endpointA can handle the DemoEvent event -->
28+
<event type="Contracts.Events.DemoEvent, Contracts" />
29+
</handles>
30+
</endpoint>
31+
<endpoint name="endpointb">
32+
<!-- ... -->
33+
</endpoint>
34+
</endpoints>
35+
```
36+
37+
The `type` attribute needs to provide the [Assembly Qualified Type Name](https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx).
38+
Make sure that the routing file is copied to the binaries output folder.
39+
40+
Instead of defining every single message type, it's also possible to configure entire assemblies or namespaces in bulk:
41+
42+
```
43+
<endpoints>
44+
<endpoint name="endpointA">
45+
<handles>
46+
<!-- Define that endpointA can handle all commands in assembly "MyApp.Contracts" -->
47+
<commands assembly="MyApp.Contracts" />
48+
<!-- Define that endpointA can handle all events in assembly "MyApp.Contracts" within the namespace "Events" -->
49+
<events assembly="MyApp.Contracts" namespace="Events" />
50+
</handles>
51+
</endpoint>
52+
</endpoints>
53+
```
54+
55+
56+
### Updating the routing configuration
57+
58+
The routing configuration is read every 30 seconds. You can therefore change the routing at runtime (e.g. unsubscribe an endpoint by removing its `event` entry from the `handles` collection). If the routing file is no longer valid after an update, the endpoint continues to use the previously loaded routing file.
59+
60+
61+
### Sharing the routing file
62+
63+
In order to allow centralized configuration of the routing file, the file needs to be shared with the endpoints. This can be done in various ways, e.g.
64+
* Make the file available via a shared network folder.
65+
* Distribute the file as a part of your deployment process.
66+
* Include the file on your project/solution and its build artifacts. Note: This approach does not allow for a centralized routing file management out of the box.
67+
68+
69+
## Scaling out
70+
71+
It's possible to use sender-side distribution to scale out messages and events to multiple instances of the same logical endpoint. This is done with the instance mapping file documented here:https://docs.particular.net/nservicebus/msmq/routing?version=Core_6
72+
73+
In short: create a new xml file named `instance-mapping.xml` and include it on every endpoint. Make sure to copy the file over to the binaries folder.
74+
75+
```
76+
<endpoints>
77+
<endpoint name="endpointB">
78+
<instance discriminator="1" machine="machine1" />
79+
<instance discriminator="2" machine="machine1" />
80+
<instance machine="machine2" />
81+
</endpoint>
82+
</endpoints>
83+
```

0 commit comments

Comments
 (0)