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
The previous sample contains a callback that cleans the dictionary when
222
-
confirms arrive. Note this callback handles both single and multiple
223
-
confirms. This callback is used when confirms arrive (`Channel#BasicAcks`). The callback for nack-ed messages
224
-
retrieves the message body and issues a warning. It then re-uses the
225
-
previous callback to clean the dictionary of outstanding confirms (whether
226
-
messages are confirmed or nack-ed, their corresponding entries in the dictionary
227
-
must be removed.)
228
-
229
-
> #### How to Track Outstanding Confirms?
230
-
>
231
-
> Our samples use a `ConcurrentDictionary` to track outstanding confirms.
232
-
> This data structure is convenient for several reasons. It allows to
233
-
> easily correlate a sequence number with a message (whatever the message data
234
-
> is) and to easily clean the entries up to a given sequence id (to handle
235
-
> multiple confirms/nacks). At last, it supports concurrent access, because
236
-
> confirm callbacks are called in a thread owned by the client library, which
237
-
> should be kept different from the publishing thread.
238
-
>
239
-
> There are other ways to track outstanding confirms than with
240
-
> a sophisticated dictionary implementation, like using a simple concurrent hash table
241
-
> and a variable to track the lower bound of the publishing sequence, but
242
-
> they are usually more involved and do not belong to a tutorial.
169
+
The previous sample contains a callback that cleans the linked list when
170
+
confirms arrive. Note this callback handles both single and multiple confirms.
171
+
This callback is used when confirms arrive (`IChannel#BasicAcks`). The callback
172
+
for nack-ed messages issues a warning. It then re-uses the previous callback to
173
+
clean the linked list of outstanding confirms.
243
174
244
175
To sum up, handling publisher confirms asynchronously usually requires the
245
176
following steps:
@@ -278,53 +209,44 @@ to the constraints in the application and in the overall system. Typical techniq
278
209
279
210
## Putting It All Together
280
211
281
-
The [`PublisherConfirms.cs`](https://github.com/rabbitmq/rabbitmq-tutorials/blob/main/dotnet/PublisherConfirms/PublisherConfirms.cs)
212
+
The [`PublisherConfirms.cs`](https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/PublisherConfirms/PublisherConfirms.cs)
282
213
class contains code for the techniques we covered. We can compile it, execute it as-is and
283
214
see how they each perform:
284
215
285
-
```bash
286
-
dotnet run
216
+
```PowerShell
217
+
> dotnet run .\PublisherConfirms.csproj
218
+
9/9/2024 11:07:11 AM [INFO] publishing 50,000 messages individually and handling confirms all at once
219
+
9/9/2024 11:07:12 AM [INFO] published 50,000 messages individually in 796 ms
220
+
9/9/2024 11:07:12 AM [INFO] publishing 50,000 messages and handling confirms in batches
221
+
9/9/2024 11:07:13 AM [INFO] published 50,000 messages in batch in 1,034 ms
222
+
9/9/2024 11:07:13 AM [INFO] publishing 50,000 messages and handling confirms asynchronously
223
+
9/9/2024 11:07:14 AM [INFO] published 50,000 messages and handled confirm asynchronously 763 ms
287
224
```
288
225
289
-
The output will look like the following:
290
-
291
-
```bash
292
-
Published 50,000 messages individually in 5,549 ms
293
-
Published 50,000 messages in batch in 2,331 ms
294
-
Published 50,000 messages and handled confirms asynchronously in 4,054 ms
295
-
```
296
-
297
-
The output on your computer should look similar if the client and the server sit
298
-
on the same machine. Publishing messages individually performs poorly as expected,
299
-
but the results for asynchronously handling are a bit disappointing compared to batch publishing.
226
+
The output on your computer should look similar if the client and the server
227
+
sit on the same machine.
300
228
301
229
Publisher confirms are very network-dependent, so we're better off
302
230
trying with a remote node, which is more realistic as clients
303
231
and servers are usually not on the same machine in production.
304
232
`PublisherConfirms.cs` can easily be changed to use a non-local node:
0 commit comments