|
1 | 1 | ---
|
2 | 2 | title: Routing Slips
|
3 |
| -reviewed: 2023-09-15 |
| 3 | +reviewed: 2025-08-14 |
4 | 4 | component: MessageRouting
|
5 | 5 | ---
|
6 | 6 |
|
7 | 7 | ## Introduction
|
8 | 8 |
|
9 |
| -Uses the [Routing Slip pattern](https://www.enterpriseintegrationpatterns.com/patterns/messaging/RoutingTable.html) feature of the [MessageRouting](https://github.com/jbogard/NServiceBus.MessageRouting) project. |
| 9 | +This sample demonstrates the use of the [Routing Slip pattern](https://www.enterpriseintegrationpatterns.com/patterns/messaging/RoutingTable.html) with the [MessageRouting](https://github.com/jbogard/NServiceBus.MessageRouting) project. |
10 | 10 |
|
| 11 | +A **routing slip** allows a message to carry a list of destinations it should pass through. Each endpoint processes the message and then forwards it to the next stop on the slip. This enables dynamic workflows without hardcoding routes between endpoints. |
11 | 12 |
|
12 |
| -## Code walk-through |
| 13 | +## Solution Overview |
13 | 14 |
|
14 |
| -The solution consists of 6 Projects |
| 15 | +The solution consists of six projects: |
15 | 16 |
|
16 |
| - * Messages: The shared message definitions. |
17 |
| - * Sender: Initiates the message sends. |
18 |
| - * StepA, StepB, StepC: The handling endpoints to to show how the message flows between endpoints. |
19 |
| - * ResultHost: The final destination endpoint for messages that logs all the endpoints the message was routed through. |
| 17 | +- **Messages** – Shared message definitions. |
| 18 | +- **Sender** – Initiates the message send and defines the route. |
| 19 | +- **StepA, StepB, StepC** – Processing endpoints that demonstrate how a message flows between steps. |
| 20 | +- **ResultHost** – The final destination that logs all endpoints the message passed through. |
20 | 21 |
|
| 22 | +## Enabling Routing Slips |
21 | 23 |
|
22 |
| -### Enabling Routing Slips Feature |
23 |
| - |
24 |
| -All endpoints have routing slips enabled: |
| 24 | +All endpoints have the routing slip feature enabled: |
25 | 25 |
|
26 | 26 | snippet: enableRoutingSlips
|
27 | 27 |
|
| 28 | +## Multiple Message Interpretations |
28 | 29 |
|
29 |
| -## Multiple message interpretations |
| 30 | +Each step in the route defines its own interpretation of the message. |
30 | 31 |
|
31 |
| -Each step in the routing has its own definition of the message. For example StepA considers the message contract to be. |
| 32 | +For example, StepA treats the message contract as follows: |
32 | 33 |
|
33 | 34 | snippet: single-message
|
34 | 35 |
|
35 |
| -Both the Sender and the ResultHost have the full message context by referencing the Messages project. |
| 36 | +Both the Sender and ResultHost projects use the full message context by referencing the **Messages** project: |
36 | 37 |
|
37 | 38 | snippet: multi-message
|
38 | 39 |
|
39 |
| -On Send all share properties are set. |
| 40 | +When sending, all shared properties are set: |
40 | 41 |
|
41 | 42 | snippet: multi-message-send
|
42 | 43 |
|
43 |
| -But in each step project they are only aware of the specific their specific message interpretations: |
| 44 | +However, in each step project, handlers only work with their own specific interpretation of the message: |
44 | 45 |
|
45 | 46 | snippet: step-handler
|
46 | 47 |
|
| 48 | +## Message Sending |
47 | 49 |
|
48 |
| -### Message sending |
49 |
| - |
50 |
| -The Sender project alternates between two send actions: |
| 50 | +The **Sender** project alternates between two send actions: |
51 | 51 |
|
52 | 52 | snippet: alternate
|
53 | 53 |
|
54 |
| - |
55 |
| -#### Route to A, C and ResultHost |
| 54 | +### Route to A, C, and ResultHost |
56 | 55 |
|
57 | 56 | snippet: SendAC
|
58 | 57 |
|
59 |
| - |
60 |
| -#### Route to A, B, C and ResultHost |
| 58 | +### Route to A, B, C, and ResultHost |
61 | 59 |
|
62 | 60 | snippet: SendABC
|
63 | 61 |
|
64 |
| - |
65 | 62 | ## Runtime Behavior
|
66 | 63 |
|
| 64 | +### When routing to A, C, and ResultHost |
67 | 65 |
|
68 |
| -### When routing to A, C and ResultHost |
69 |
| - |
70 |
| - 1. StepA receives message |
71 |
| - 1. StepC receives message |
72 |
| - 1. ResultHost receives message |
| 66 | +1. StepA receives the message |
| 67 | +2. StepC receives the message |
| 68 | +3. ResultHost receives the message |
73 | 69 |
|
74 | 70 | ```mermaid
|
75 | 71 | sequenceDiagram
|
76 |
| -
|
77 | 72 | Participant Sender
|
78 | 73 | Participant StepA
|
79 | 74 | Participant StepB
|
80 | 75 | Participant StepC
|
81 | 76 | Participant ResultHost
|
82 | 77 | Sender ->> StepA: Route
|
83 |
| -Note over StepA: Sets Attachment "Foo = Bar" |
84 |
| -StepA->> StepC: Route |
85 |
| -Note over StepC: Read Attachment "Foo" |
86 |
| -StepC->> ResultHost: Route |
| 78 | +Note over StepA: Sets attachment "Foo = Bar" |
| 79 | +StepA ->> StepC: Route |
| 80 | +Note over StepC: Reads attachment "Foo" |
| 81 | +StepC ->> ResultHost: Route |
87 | 82 | ```
|
88 | 83 |
|
| 84 | +### When routing to A, B, C, and ResultHost |
89 | 85 |
|
90 |
| -### When routing to A, B, C and ResultHost |
91 |
| - |
92 |
| - 1. StepA receives message |
93 |
| - 1. StepB receives message |
94 |
| - 1. StepC receives message |
95 |
| - 1. ResultHost receives message |
| 86 | +1. StepA receives the message |
| 87 | +2. StepB receives the message |
| 88 | +3. StepC receives the message |
| 89 | +4. ResultHost receives the message |
96 | 90 |
|
97 | 91 | ```mermaid
|
98 | 92 | sequenceDiagram
|
99 |
| -
|
100 | 93 | Participant Sender
|
101 | 94 | Participant StepA
|
102 | 95 | Participant StepB
|
103 | 96 | Participant StepC
|
104 | 97 | Participant ResultHost
|
105 | 98 | Sender ->> StepA: Route
|
106 |
| -Note over StepA: Sets Attachment "Foo = Bar" |
107 |
| -StepA->> StepB: Route |
108 |
| -StepB->> StepC: Route |
109 |
| -Note over StepC: Read Attachment "Foo" |
110 |
| -StepC->> ResultHost: Route |
| 99 | +Note over StepA: Sets attachment "Foo = Bar" |
| 100 | +StepA ->> StepB: Route |
| 101 | +StepB ->> StepC: Route |
| 102 | +Note over StepC: Reads attachment "Foo" |
| 103 | +StepC ->> ResultHost: Route |
111 | 104 | ```
|
112 | 105 |
|
113 |
| - |
114 | 106 | ## Attachments
|
115 | 107 |
|
116 |
| -Note that StepA sets a routing slip attachment: |
| 108 | +StepA sets a routing slip attachment: |
117 | 109 |
|
118 | 110 | snippet: set-attachments
|
119 | 111 |
|
120 |
| -Which is then retrieved by StepC |
| 112 | +StepC then retrieves the attachment: |
121 | 113 |
|
122 | 114 | snippet: read-attachment
|
0 commit comments