Adding support for the no_responders feature. - #259
Conversation
Maybe we should make it a property on the message itself? (Rust client seems to be doing that) Also looking at Go and Rust clients there isn't an option to set |
That's possible. I still think an exception is more intuitive though from a C# convention perspective (compared to the NatsNoReplyException for timeouts), unless explicitly documented, since another side effect is that the Msg.Data property will be a default value (null for objects, 0 for ints etc.)
In that case we should default the |
right, I think exception is the right thing to do. I was suggesting the way we detect no responders can be a calculated property on the message object.
I'm thinking less options the better but if you say there may be a use case for it we could leave it in the options but yes I think it should default to true if we left it as an option. |
|
|
Excellent. thank you @stebet! One last thing, should we have the check in |
|
@stebet don't worry about tests. there may be quite a few failing I can fix them later. |
Fixed the ones that my changes broke :) which were counting on timeouts when they were received NoResponders instead. We could also just drop the |
Thank you :-) yes good point. would there be a need to distinguish the two? e.g. trying to pick up the fastest responder in a set of responders? |
Not apart from the exception message I think. They're sort of equivalent, one will just be returned pretty much instantly (no responders) since there is no responder that will ever answer, or they simply took too long and the request timed out (exceeded the NatsOpts.RequestTimeout threshold) We can also just keep them separate for clarity to avoid confusion. |
| } | ||
| } | ||
|
|
||
| public bool IsNoRespondersError => Headers?.Code == 503; |
There was a problem hiding this comment.
I don't know if it makes sense to offer just 1 public IsNoRespondersError here. If we do one, we should probably enumerate every single error code. I don't know if using Go or Rust as examples is great. Those languages don't have exceptions.
There was a problem hiding this comment.
Not a standard error very specific message from the server. Other errors should still be check from the headers. we can't rely throw exceptions at this level without destroying the subscription.
|
I am pretty sure that Go will return a No Responders error in any subscription if it receives one, not just in the Request-Reply APIs: Also, I do think they should be separate Exceptions. |
We can't throw exception per message. We'd need to end the subscription. |
|
see also #262 |
|
I somewhat disagree with handling no-responders at subscription level having said that I also can't see a nice way of doing that. But maybe I'm missing something. |
|
No responders at a subscription level is an edge case imo so I don't think it warrants an exception. It should never happen unless the client is explicitly doing his own response-request mechanism, since it's only returned to the reply_to subject if the subscriotion is on the same connection as the one making the publish. It's not sent if the connection listening to the reply_to subject is different from the one making the publish. In that case it's good to have the property to do a quick check. On that note, a class with constant values for possible status codes might be a good idea for a later PR to make it clearer in the code what each status code means (similar to the StatusCodes constants in the ASP.NET Core libraries). |
Ah good point. Then it's probably fine just to throw in the Request-Reply patterns
That sounds like a good idea! |
|
@stebet please resolve conflict then we can merge. thanks! |
Adding a IsNoRespondersError property to NatsMsg
0d8f107 to
b265f7a
Compare
Rebased on latest main |
This solves #258
NatsNoRespondersExceptionif triggered via.RequestAsync, but not if triggered viaPublishAsync.no_responders, in case the client is using his ownrequest-replymechanism through PubSub andreply_to, does NOT throw an exception but the subscriber receives an empty message withmsg.Headers.Codeequal to503.RequestAsyncbut that's open for discussion. It could even be another configuration value for NatsOpts (bool ThrowOnNoResponders) so let's discuss that.RequestAsyncand customPubSubto trigger the behavior.dotnet formatwhich formatted some unrelated files.