-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch on already deleted consumer does not throw an exception #628
Comments
do you get any notifications on opts.notificationhandler? |
var receivedMessages = consumer.FetchAsync<byte[]>(new NatsJSFetchOpts(){ Expires = TimeSpan.FromSeconds(10), MaxMsgs = 100, NotificationHandler = PrintNotifications });
await foreach (var msg in receivedMessages)
{
Console.WriteLine(msg);
}
Task PrintNotifications(INatsJSNotification ns, CancellationToken ct)
{
Console.WriteLine(ns.Name);
if(ns is NatsJSProtocolNotification protocolNotification)
{
Console.WriteLine($"{protocolNotification.Name}, {protocolNotification.HeaderCode}, {protocolNotification.HeaderMessageText}");
}
return Task.CompletedTask;
}
Adapted my example to print the notifications. The only notification i got is the |
Thank you for this report @NonnRa it's a good question. unfortunately server doesn't return any errors on requests in this case. you have to explicitly check for the consumer using await consumer.RefreshAsync(); // this will create an additional consumer info API call to JetStream server
var receivedMessages = consumer.FetchAsync<byte[]>(new NatsJSFetchOpts(){ Expires = TimeSpan.FromSeconds(10), MaxMsgs = 100, NotificationHandler = PrintNotifications });
await foreach (var msg in receivedMessages)
{
Console.WriteLine(msg);
} ... or check for the if (ns is NatsJSTimeoutNotification)
{
Console.WriteLine("Timeout");
try
{
await consumer.RefreshAsync(ct);
}
catch (NatsJSApiException e) when (e.Error.Code == 404)
{
Console.WriteLine("Consumer not found");
await myCancellationTokenSource.CancelAsync(); // somehow signal the fetch loop
}
catch (Exception e)
{
Console.WriteLine("Log other exceptions");
}
} |
Thanks for the response. I will try to build a safty net around it with you snippets. |
Observed behavior
When i create a pull consumer and the consumer is deleted on the server before i call
FetchAsync(..)
. I will never get any message from that consumer and i will never get an exception. So that i stuck in an endless loop callingFetchAsync
again and again.Expected behavior
I expected to get a Exception like described on the FetchAsync method.
NatsJSException — There is an error sending the message or this consumer object isn't valid anymore because it was deleted earlier
Server and client version
Client version: NATS.Net 2.3.3
Server verison: 2.10.20
Host environment
No response
Steps to reproduce
On the
FetchAsync(..)
i would expect to get an exception as the consumer is not valid anymoreThe text was updated successfully, but these errors were encountered: