Replies: 1 comment 8 replies
-
it should recover automatically in most cases, so you don't have to do anything. But, if you see a case where we can't recover, you can catch the exceptions and retry with a back off. Some documentation here: https://nats-io.github.io/nats.net.v2/documentation/jetstream/consume.html#handling-exceptions Example: while (!cancellationToken.IsCancellationRequested)
{
try
{
await consumer.RefreshAsync(cancellationToken); // or try to recreate consumer
await foreach (var msg in consumer.ConsumeAsync<Order>(serializer: orderSerializer).WithCancellation(cancellationToken))
{
// Process message
await msg.AckAsync(cancellationToken: cancellationToken);
}
}
catch (NatsJSProtocolException e)
{
// log exception
}
catch (NatsJSException e)
{
// log exception
await Task.Delay(Random.Shared.Next(1000)); // jitter
await Task.Delay(backoffSeries(retry++), cancellationToken); // backoff
}
} |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to know how to re start the ConsumeAsync when the connection to server is re-established?. At the moment I can see that the connection is close and re-open but the ConsumeAsync does not quit or re-start the consume for message that is pending when the connection was dropped/closed (server stopped or not contactable due to network issue).
Beta Was this translation helpful? Give feedback.
All reactions