[JetStream] Pull consumers with durable are not automatically created
roman-supy-io opened this issue · comments
We're using Pull (pullSubscribe
) strategy to fetch messages periodically and currently facing an issue with consumers not being created automatically.
Prerequisites:
- Stream
random
is created - Subject
api-consumer-1-random-test-activity123
is created
Steps to reproduce:
- Connect:
this.#connection = await connect({
name: 'api-1',
servers: [/* servers */]
});
this.#jetstream = this.#connection.jetstream();
- Subscribe:
const subscription = await this.#jetstream.pullSubscribe('random.test.activity123', {
...this.options.consumer,
config: {
mack: true,
name: 'api-consumer-1',
config: {
max_deliver: 10,
ack_policy: AckPolicy.Explicit,
deliver_policy: DeliverPolicy.LastPerSubject,
durable_name: 'api-consumer-1-random-test-activity123',
filter_subject: 'random.test.activity123',
},
},
} as JetStreamConsumerOptions);
for await (const message of subscription) {
// handle message
}
At the time of subscription (2nd step) the error is thrown:
{
"name":"NatsError",
"code":"404",
"api_error":{
"code":404,"err_code":10014,"description":"consumer not found"
}
}
Question: should the durable consumers be created manually or is there any option to specify that?
We couldn't find any.
P.S.:
Currently we managed to do this by manually creating consumer
s but:
- this is not documented anywhere.
- it involves the usage of non-public
JetStreamClientImpl.prototype.findStream
to be called.
@roman-supy-io Sorry this fell through the cracks.
I think the issue may have to do with the name
property that you are specifying. You shouldn't be giving a name and durable_name in the options. When the consumer is created, the name will be either a generated one by the server or the durable_name you specified.
As you have it, name
on consumer creation could be tagging the consumer as an ephemeral, which means that if you don't perform API calls on it after a few seconds it is deleted. This would match what you are experiencing, if you are not calling pull often, the server deletes the consumer, so a subsequent pull will give you the error you are reporting.
Also - we have a new API that simplifies the use of the pull consumer:
https://github.com/nats-io/nats.deno/blob/main/jetstream.md#processing-messages
@roman-supy-io please reopen if the proposed solution didn't work for you.