-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Observed behavior
When creating a durable consumer using $JS.API.CONSUMER.CREATE the server copies the value passed in the durable_name field of the consumer config, such that the consumer created has that value in both durable_name and in the name fields.
When creating a durable consumer using $JS.API.CONSUMER.DURABLE.CREATE however the server doesn't copy the value passed in durable_name into the name field (which remains empty) for the consumer created.
The issue with this, is that if you create the consumer using either one of the JS API calls, then attempt to create the consumer again (with the same exact configuration, so the consumer creation should be idempotent) but using the other API call then the operation is not idempotent and an error is returned. This is a problem if you want to have application written using different NATS client libraries (some use DURABLE.CREATE others use CREATE) being able to work on the same stream relying on the pattern of 'first create the durable consumer in case it doesn't exist, expecting the consumer creation to not return an error if the durable is already defined (with the same config)).
Expected behavior
Consumer create should not fail if the consumer is already defined with exactly the same config, regardless of which JS API call was used to create it in the first place.
Server and client version
Any server version
Host environment
No response
Steps to reproduce
Assuming you have a stream 'foo' created, you can emulate a client creating a consumer on the stream using one or the other JS API calls. Create the consumer with one, see how you can do the same request again and it doesn't complain. Then try to create the consumer using the other version, and see how it returns an error that the consumer already exists.
nats req '$JS.API.CONSUMER.CREATE.foo.test' '{"stream_name":"foo","config":{"durable_name":"test","deliver_policy":"all","ack_policy":"explicit","ack_wait":2000000000,"replay_policy":"instant","max_ack_pending":1,"num_replicas":0,"filter_subjects":[">"]},"action":"create"}'
nats req '$JS.API.CONSUMER.DURABLE.CREATE.foo.test' '{"stream_name":"foo","config":{"durable_name":"test","deliver_policy":"all","ack_policy":"explicit","ack_wait":2000000000,"replay_policy":"instant","max_ack_pending":1,"num_replicas":0,"filter_subjects":[">"]},"action":"create"}'