nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
15.16k stars 1.37k forks source link

Ability to set consumer_name for Key Value store #5257

Open suikast42 opened 3 months ago

suikast42 commented 3 months ago

Proposed change

I am using the jnats java libraray an subsribe to a kv bucket with

 natKvStoreService.deviceAggregateStore().watchAll(new KeyValueWatcher() {

This generates on every boot different consumer name

jetstream_consumer_ack_floor_stream_seqaccount$Gaccount_id$Gclusterconsumer_descconsumer_leaderconsumer_nameDGix6yiNaWdomainis_consumer_leadertrueis_meta_leadertrueis_stream_leadertruemeta_leaderserver_idamovabi_infra.nats[0]server_nameamovabi_infra.nats[0]stream_leaderamovabi_infra.nats[0]stream_nameKV_DeviceAggregateStore 1087

Is it possible to add consumer name to KeyValueWatchOption ?

Use case

Listen to KV stores

Contribution

No response

Jarema commented 3 months ago

Watch uses ordered consumer, which might be recreated on the fly if it discovers any issue. Because of that, it needs random name. However, we can consider adding possibility to fill the watcher's Consumer Metadata with information allowing you to identify it in other way than by checking on which stream it is, or which KV it is watching.

Would that address your case?

suikast42 commented 3 months ago

The stream name is already included.