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/message-consumption.md
+14-10Lines changed: 14 additions & 10 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
### Synchronous message handlers
4
4
5
-
To retrieve messages from the queues you have to configure services that will handle received messages.
6
-
Message handlers are classes that implement `IMessageHandler` interface (or a few others) and implement functionality including error handling for processing messages.
5
+
To retrieve messages from queues you have to configure services that will handle received messages.
6
+
Message handlers are classes that implement `IMessageHandler` interface (or a few others) and contain functionality including error handling for processing messages.
7
7
You can register `IMessageHandler` in your `Startup` like this.
The RabbitMQ client configuration and exchange configuration sections not specified in this example, but covered [here](rabbit-configuration.md) and [here](exchange-configuration.md).
33
34
34
35
`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.
42
+
You can register it in two modes - **singleton** or **transient** using `AddMessageHandlerSingleton` or `AddMessageHandlerTransient` methods respectively.
`IMessageHandler` consists of one method `Handle` that gets a message in string format. You can deserialize (if it is a json message) it or handle a raw value.
69
+
`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.
You can also inject services inside `IMessageHandler`implementation.
83
+
You can also inject services inside `IMessageHandler`constructor.
83
84
84
85
```c#
85
86
publicclassCustomMessageHandler : IMessageHandler
@@ -98,7 +99,8 @@ public class CustomMessageHandler : IMessageHandler
98
99
```
99
100
100
101
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`.
101
-
`INonCyclicMessageHandler` can be registered the same way as `IMessageHandler`, there are similar semantic methods for adding it in singleton or transient mode.
102
+
`INonCyclicMessageHandler` can be registered the same way as `IMessageHandler`. There are similar semantic methods for adding it in **singleton** or **transient** mode.
@@ -126,8 +129,9 @@ public class CustomNonCyclicMessageHandler : INonCyclicMessageHandler
126
129
```
127
130
128
131
### Asynchronous message handlers
129
-
`IMessageHandler` and `INonCyclicMessageHandler` are synchronous message handlers, but if you want async versions then use `IAsyncMessageHandler` and `IAsyncNonCyclicMessageHandler`.
130
-
There are extension methods that allows you to register it the same way as synchronous ones in singleton or transient modes.
132
+
133
+
`IMessageHandler` and `INonCyclicMessageHandler` work synchronously, but if you want an async version then use `IAsyncMessageHandler` and `IAsyncNonCyclicMessageHandler`.
134
+
There are extension methods that allows you to register it the same way as synchronous ones in **singleton** or **transient** modes.
0 commit comments