-
Notifications
You must be signed in to change notification settings - Fork 51
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
NatsError code
is concat of code + message?
#273
Comments
The issue is that for the 404, the server is setting the 404 as a status code, which gets parsed earlier by the request handling, rather than at the JetStream API handling. - The JavaScript clients are looking for any status code and failing the request if set. |
… code was set, it turned that into an error. The logic for this was not quite correct one requirement is for the message payload of this type of error be empty and NATS core currently can only expect error of 503 (no responders). Any interpretation of the status code unless a 503, should be delegated - in this case to JetStream which can then make better interpretation of the code (which could simply be a marker for no messages, or a request timeout on requests that have an expiration. [CHANGE] js.pull(stream,dur) now also adds an optional expires - the expires also overrides the request timeout. FIX #273
Your code is almost correct - Also - in looking at your code, I have also updated |
So the following would be the correct simplification of the poll loop? And, if I'm reading the commit correctly: eb836b8 ,
If the above is correct, it makes my use-case easier... And I'm assuming that eb836b8 fix all cases of thanks |
correct, previously https://github.com/nats-io/nats.deno/blob/main/nats-base-client/types.ts#L247 Now the If you don't specify an expires, If you specify an expires, If you find yourself doing this more frequently - you may want to move to a pull subscription. - There's some overhead on setting up the If you want to move to a pull subscription, your code would look something like this: let inbox = "";
let sub: JetStreamPullSubscription;
const pullOpts = { batch: 1, expires: 30 * 1000 };
const opts = consumerOpts();
opts.bind(ci.stream, ci.durable);
opts.ackExplicit();
opts.manualAck();
opts.callback((err, m) => {
if (err) {
switch (err.code) {
case ErrorCode.JetStream404NoMessages:
case ErrorCode.JetStream408RequestTimeout:
// re-pull here
sub.pull(pullOpts);
break;
default:
// this is a real error
log.error(`error from ${ci.name}: ${err.message}\n${err.stack}`);
// this will make the service stop
sub.unsubscribe();
}
return;
}
// do something with your message
// next acks the message and requests the next batch
m.next(inbox, pullOpts);
});
const js = nc.jetstream();
sub = await js.pullSubscribe(
ci.subject,
opts,
);
const done = sub.closed;
inbox = sub.getSubject();
// do the initial pull
sub.pull(pullOpts); |
The above snippet is fairly server friendly you have a single subscription that is setup to handle all the polling for messages on the |
(note next(), and the new pull options are not yet released, but I'll do a release very soon in the next few days) |
…core request layer (#288) - [FIX] the base client request introspected a message, and if a status code was set, it turned that into an error. The logic for this was not entirely correct one requirement is for the message payload of this type of error to be empty and NATS core currently can only expect an error of 503 (no responders). Any interpretation of the status code unless a 503, should be delegated - in this case to JetStream which can then make a better interpretation of the code (which could simply be a marker for no messages or a request timeout on requests that have an expiration. - [CHANGE] `js.pull(stream,dur)` now also adds an optional `expires` argument - the expires also overrides the request timeout default if the expires is longer. - [CHANGE] [DEPRECATION] 409's take the description sent by the server - added a `ErrorCodeJetStream409` enum, and deprecated `ErrorCode.JetStream409MaxAckPendingExceeded` - [UPDATE] ci nats-server version to 2.8.2 FIX #273
Context
I have a pull consumer, to which I am calling single
js.pull()
s. From which I am attempting to catch the 404, 408 and 409 Jetstream errors to then "sleep" when no messages come back.Issue
Examining
err.code
does not match any values in theErrorCode
enum.Instead, the
code
field looks to be a concatenation of the enum code and a text message.Example:
I'm expecting
404
as thenats.ErrorCode.JetStream404NoMessages
code value, but i'm getting404 No Messages
...Sample Code
Environment
deps.ts
Dockerfile
Initialization:
The text was updated successfully, but these errors were encountered: