You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 29, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/exchange-configuration.md
+20-19Lines changed: 20 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
3
3
### Basics
4
4
5
-
Client applications work with exchanges and queues, and they must be "declared" and "bound" to each other is a certain way before they can be used.
6
-
Queues and exchanges can also be customized by using additional parameters. This library allows to do this routine simply calling `AddExchange` method passing additional parameters to it.
5
+
Client applications work with exchanges and queues which must be "declared" and "bound" to each other in a certain way before they can be used.
6
+
Queues and exchanges can also be customized by using additional parameters. This library allows you to do this routine simply calling the`AddExchange` method passing additional parameters to it.
7
7
You are allowed to configure multiple exchanges with multiple queues bound to them.
8
8
9
9
Your `Startup` code will look like this.
@@ -57,26 +57,26 @@ And the `appsettings.json` file will be like this.
57
57
}
58
58
```
59
59
60
-
The RabbitMQ client configuration section not specified in this example, for more information see the [documentation](rabbit-configuration.md) file.
60
+
The RabbitMQ client configuration section is not specified in this example, for more information see the [documentation](rabbit-configuration.md) file.
61
61
62
62
Exchanges can be configured with properties:
63
-
-`Type` - exchange type (direct, topic, fanout). Default value is `"direct"`.
64
-
-`Durable` - durability option. Default value is `true`.
65
-
-`AutoDelete` - option for exchange auto deleting. Default value is `false`.
66
-
-`Arguments` - dictionary of additional arguments. Default value is `null`.
67
-
-`RequeueFailedMessages` - option that specifies behaviour of re-queueing failed messages with delay through dead-letter-exchange. Default value is `true`. Mechanism of sending delayed messages covered in the [documentation](message-production.md).
68
-
-`DeadLetterExchange` - default value for dead-letter-exchange. Default value for dead-letter-exchange name is `"default.dlx.exchange"`.
69
-
-`Queues` - collection of queues bound to the exchange.
63
+
-`Type` - an exchange type (direct, topic, fanout). The default value is `"direct"`.
64
+
-`Durable` - a durability option. The default value is `true`.
65
+
-`AutoDelete` - an option for exchange auto deleting. The default value is `false`.
66
+
-`Arguments` - a dictionary of additional arguments. The default value is `null`.
67
+
-`RequeueFailedMessages` - an option that specifies behaviour of re-queueing failed messages with certain delay through the dead-letter-exchange. The default value is `true`. The mechanism of sending delayed messages is covered in the [documentation](message-production.md).
68
+
-`DeadLetterExchange` - a value for dead-letter-exchange. The default value for the dead-letter-exchange name is `"default.dlx.exchange"`.
69
+
-`Queues` - a collection of queues bound to the exchange.
70
70
71
71
Queue options:
72
-
-`Name` - queue name.
73
-
-`Durable` - durability option. Default value is `true`.
74
-
-`AutoDelete` - option for queue auto deleting. Default value is `false`.
75
-
-`Exclusive` - exclusive option. Default value is `false`.
76
-
-`Arguments` - dictionary of additional [arguments](https://www.rabbitmq.com/queues.html#optional-arguments). Default value is `null`.
77
-
-`RoutingKeys` - collection of routing keys that queue "listens".
72
+
-`Name` - a queue name.
73
+
-`Durable` - a durability option. The default value is `true`.
74
+
-`AutoDelete` - an option for queue auto deleting. The default value is `false`.
75
+
-`Exclusive` - an exclusive option. The default value is `false`.
76
+
-`Arguments` - a dictionary of additional [arguments](https://www.rabbitmq.com/queues.html#optional-arguments). The default value is `null`.
77
+
-`RoutingKeys` - a collection of routing keys that the queue "listens".
78
78
79
-
Taking into account all the default values that you can skip configuration will look like this.
79
+
Taking into account all the default values that you can skip, configuration will look like this.
80
80
81
81
```json
82
82
{
@@ -92,7 +92,7 @@ Taking into account all the default values that you can skip configuration will
92
92
}
93
93
```
94
94
95
-
If you want to use routing keys matching with queue names you can skip `"RoutingKeys"` option and queues will be bound to the exchange by their names.
95
+
If you want to use routing keys matching with queue names you can skip the `"RoutingKeys"` option and queues will be bound to the exchange by their names.
Copy file name to clipboardExpand all lines: docs/message-consumption.md
+38-27Lines changed: 38 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,10 @@
2
2
3
3
### Starting a consumer
4
4
5
-
The first step that needs to be done to retrieve messages from queues is to start a consumer. This can be achieved by calling `StartConsuming` method of `IQueueService`.
6
-
Without calling `StartConsuming` consumption exchanges will work only in production mode.
5
+
The first step that has to be done to retrieve messages from queues is to start a consumer. This can be achieved by calling the`StartConsuming` method of `IQueueService`.
6
+
Consumption exchanges will work only in a message-production mode if the `StartConsuming` method won't be called.
7
7
8
-
Let's say that your configuration look like this.
8
+
Let's say that your configuration looks like this.
9
9
10
10
```c#
11
11
publicclassStartup
@@ -27,13 +27,13 @@ public class Startup
27
27
}
28
28
```
29
29
30
-
You can register an `IHostedService` and inject the instance of `IQueueService` into it.
30
+
You can register `IHostedService` and inject an instance of `IQueueService` into it.
And then simply call `StartConsuming` so consumer can work in a background.
36
+
And then simply call `StartConsuming` so a consumer can work in the background.
37
37
38
38
```c#
39
39
publicclassConsumingService : IHostedService
@@ -64,7 +64,7 @@ public class ConsumingService : IHostedService
64
64
}
65
65
```
66
66
67
-
Otherwise you can implement a worker service template from .Net Core 3 like this.
67
+
Otherwise, you can implement a worker service template from .Net Core 3 like this.
68
68
69
69
```c#
70
70
publicclassProgram
@@ -108,7 +108,7 @@ public class Worker : BackgroundService
108
108
109
109
The second step without which receiving messages does not make sense - configuration of message handling services. If there are no message handlers then received messages will not be processed.
110
110
111
-
Message handlers are classes that implement `IMessageHandler` interface (or a few others) and contain functionality including error handling for processing messages.
111
+
Message handlers are classes that implement the `IMessageHandler` interface (or a few others) and contain functionality (including error handling) for processing messages.
112
112
You can register `IMessageHandler` in your `Startup` like this.
113
113
114
114
```c#
@@ -132,30 +132,41 @@ public class Startup
132
132
}
133
133
```
134
134
135
-
The RabbitMQ client configuration and exchange configuration sections not specified in this example, but covered [here](rabbit-configuration.md) and [here](exchange-configuration.md).
135
+
RabbitMQ client and exchange configuration sections are not specified in this example, but covered [here](rabbit-configuration.md) and [here](exchange-configuration.md).
136
+
137
+
`IMessageHandler` implementation will "listen" for messages by the specified routing key, or a collection of routing keys. If it is necessary, you can also register multiple message handler at once.
You can also use **pattern matching** in routes where `*` (star) can substitute for exactly one word and `#` (hash) can substitute for zero or more words.
136
147
137
-
`IMessageHandler` implementation will "listen" for messages by specified routing key, or a collection of routing keys.
You can register it in two modes - **singleton** or **transient** using `AddMessageHandlerSingleton` or `AddMessageHandlerTransient` methods respectively.
155
+
You are also allowed to specify the exact exchange which will be "listened" by a message handler with the given routing key (or a pattern).
If it is necessary you can also register multiple message handler at once.
164
+
You can register it in two modes, **singleton** or **transient**, using `AddMessageHandlerSingleton` or `AddMessageHandlerTransient` methods respectively.
You can also set multiple message handlers for managing messages received by one routing key. This case can happen when you want to divide responsibilities between services (e.g. one contains business logic, and the other writes messages in the database).
`IMessageHandler` consists of one method `Handle` that gets a message in string format. You can deserialize it (if it is a json message) or handle a raw value.
172
-
Thus, message handler will look like this.
182
+
`IMessageHandler` consists of one method `Handle` that gets a message in a string format. You can deserialize it (if it is a json message) or handle a raw value.
183
+
Thus, a message handler will look like this.
173
184
174
185
```c#
175
186
publicclassCustomMessageHandler : IMessageHandler
@@ -182,7 +193,7 @@ public class CustomMessageHandler : IMessageHandler
182
193
}
183
194
```
184
195
185
-
You can also inject services inside `IMessageHandler` constructor.
196
+
You can also inject services inside the `IMessageHandler` constructor.
186
197
187
198
```c#
188
199
publicclassCustomMessageHandler : IMessageHandler
@@ -200,8 +211,8 @@ public class CustomMessageHandler : IMessageHandler
200
211
}
201
212
```
202
213
203
-
The only exception is `IQueueService`, you can't inject it because of the appearance of cyclic dependencies. If you want to use an instance of `IQueueService` (e.g. handle one message and send another) use `INonCyclicMessageHandler`.
204
-
`INonCyclicMessageHandler` can be registered the same way as `IMessageHandler`. There are similar semantic methods for adding it in **singleton** or **transient**mode.
214
+
The only exception is the `IQueueService`. You can't inject it inside a message handler because of the appearance of cyclic dependencies. If you want to use an instance of `IQueueService` (e.g. handle one message and send another) use `INonCyclicMessageHandler`.
215
+
`INonCyclicMessageHandler` can be registered the same way as `IMessageHandler`. There are similar semantic methods for adding it in **singleton** or **transient**modes.
205
216
206
217
```c#
207
218
services.AddRabbitMqClient(clientConfiguration)
@@ -232,8 +243,8 @@ public class CustomNonCyclicMessageHandler : INonCyclicMessageHandler
232
243
233
244
### Asynchronous message handlers
234
245
235
-
`IMessageHandler` and `INonCyclicMessageHandler` work synchronously, but if you want an async version then use `IAsyncMessageHandler` and `IAsyncNonCyclicMessageHandler`.
236
-
There are extension methods that allows you to register it the same way as synchronous ones in **singleton** or **transient** modes.
246
+
`IMessageHandler` and `INonCyclicMessageHandler` work synchronously, but if you want to use an async technology then use `IAsyncMessageHandler` and `IAsyncNonCyclicMessageHandler`.
247
+
There are extension methods that allow you to register it the same way as synchronous ones in **singleton** or **transient** modes.
237
248
238
249
```c#
239
250
services.AddRabbitMqClient(clientConfiguration)
@@ -288,11 +299,11 @@ So you can use async/await power inside your message handler.
288
299
289
300
The message handling process is organized as follows:
290
301
291
-
-`IQueueMessage` receives a message as a byte array and decodes it in UTF8 string.
292
-
-`IQueueMessage` checks if there are any message handlers in collections of `IMessageHandler`, `IAsyncMessageHandler`, `INonCyclicMessageHandler` and `IAsyncNonCyclicMessageHandler` instances and forwards a message to them.
293
-
- All subscribed message handlers (`IMessageHandler`, `IAsyncMessageHandler`, `INonCyclicMessageHandler`, `IAsyncNonCyclicMessageHandler`) process the message.
294
-
-`IQueueMessage` acknowledges the message by its `DeliveryTag`.
295
-
- If any exception occurs `IQueueMessage` acknowledges the message anyway and checks if the message has to be re-send. If exchange option `RequeueFailedMessages` is set `true` then `IQueueMessage` adds a header `"requeued"` to the message and sends it again with delay in 60 seconds. Mechanism of sending delayed messages covered in the message production [documentation](message-production.md).
302
+
-`IQueueMessage` receives a message and delegates it to `IMessageHandlingService`.
303
+
-`IMessageHandlingService` gets a message (as a byte array) and decodes it to the UTF8 string. It also checks if there are any message handlers in collections of `IMessageHandler`, `IAsyncMessageHandler`, `INonCyclicMessageHandler` and `IAsyncNonCyclicMessageHandler` instances and forwards a message to them.
304
+
- All subscribed message handlers (`IMessageHandler`, `IAsyncMessageHandler`, `INonCyclicMessageHandler`, `IAsyncNonCyclicMessageHandler`) process the given message.
305
+
-`IMessageHandlingService` acknowledges the message by its `DeliveryTag`.
306
+
- If any exception occurs `IMessageHandlingService` acknowledges the message anyway and checks if the message has to be re-send. If exchange option `RequeueFailedMessages` is set `true` then `IMessageHandlingService` adds a header `"requeued"` to the message and sends it again with delay in 60 seconds. Mechanism of sending delayed messages covered in the message production [documentation](message-production.md).
296
307
- If any exception occurs within handling the message that has been already re-sent that message will not be re-send again (re-send happens only once).
297
308
298
309
For message production features see the [Previous page](message-production.md)
0 commit comments