Skip to content
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

Add identification property to subscriptions #1731

Open
maurobalbi opened this issue Oct 27, 2024 · 1 comment
Open

Add identification property to subscriptions #1731

maurobalbi opened this issue Oct 27, 2024 · 1 comment
Labels
proposal Enhancement idea or proposal

Comments

@maurobalbi
Copy link

Proposed change

Add an additional property to allow identification of individual subscriptions
e.g.

sub, _  := nc.Subscribe(...)

sub.SetId("special subscription")

Use case

I have an admittedly special case where multiple subscriptions subscribe to the same subject in the same application.
In case of a slow subscriber, it's currently hard to figure out exactly which subscription is causing the error:

sub1, _ := nats.Subscribe("topic", func() { time.Sleep(100 * time.Second) })

sub2, _ := nats.Subscribe("topic", func() {} )

in the error callback only the subject and queue are available:

natsErrHandler(nc *nats.Conn, sub *nats.Subscription, natsErr error) {
    if natsErr == nats.ErrSlowConsumer {
       // which subscription is causing the error?
    }
)

adding the Id property would allow us to identify the subscription in the handler:

sub1, _ := nats.Subscribe("topic", func() { time.Sleep(100 * time.Second) })
sub1.SetId("sub1")

sub2, _ := nats.Subscribe("topic", func() {} )
sub2.SetId("sub2")

// ..... 
natsErrHandler(nc *nats.Conn, sub *nats.Subscription, natsErr error) {
    if natsErr == nats.ErrSlowConsumer {
       fmt.Println("slow consumer in subscription: ", sub.Id())
    }
)

Contribution

Yes, seems a straightforward implementation.

@maurobalbi maurobalbi added the proposal Enhancement idea or proposal label Oct 27, 2024
@Jarema
Copy link
Member

Jarema commented Oct 27, 2024

Hey.

There is ongoing work on that topic while working on iterators: #1728

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

2 participants