Skip to content

Commit a884650

Browse files
Merge pull request #2179 from MrXhh/main
fix: code error
2 parents d032f18 + feebbca commit a884650

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tutorials/tutorial-two-dotnet.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ time:
103103

104104
```csharp
105105
var consumer = new AsyncEventingBasicConsumer(channel);
106-
consumer.Received += async (model, ea) =>
106+
consumer.ReceivedAsync += async (model, ea) =>
107107
{
108+
var body = ea.Body.ToArray();
109+
var message = Encoding.UTF8.GetString(body);
108110
Console.WriteLine($" [x] Received {message}");
109111

110112
int dots = message.Split('.').Length - 1;
@@ -219,9 +221,15 @@ examples we explicitly turned them off by setting the autoAck
219221
remove this flag and manually send a proper acknowledgment from the
220222
worker, once we're done with a task.
221223

222-
After the existing _WriteLine_, add a call to _BasicAck_ and update _BasicConsume_ with _autoAck:false_:
223-
```csharp reference
224-
https://github.com/rabbitmq/rabbitmq-tutorials/blob/main/dotnet/Worker/Worker.cs#L26-L32
224+
After the existing _WriteLine_, add a call to _BasicAckAsync_ and update _BasicConsumeAsync_ with _autoAck:false_:
225+
```csharp
226+
Console.WriteLine(" [x] Done");
227+
228+
// here channel could also be accessed as ((AsyncEventingBasicConsumer)sender).Channel
229+
await channel.BasicAckAsync(deliveryTag: ea.DeliveryTag, multiple: false);
230+
};
231+
232+
await channel.BasicConsumeAsync("hello", autoAck: false, consumer: consumer);
225233
```
226234

227235
Using this code, you can ensure that even if you terminate a worker node using

0 commit comments

Comments
 (0)