MCPcopy
hub / github.com/nats-io/nats.go / Unsubscribe

Method Unsubscribe

nats.go:5181–5204  ·  view source on GitHub ↗

Unsubscribe will remove interest in the given subject. For a JetStream subscription, if the library has created the JetStream consumer, it will send a DeleteConsumer request to the server (if the unsubscribe itself was successful). If the delete operation fails, the error will be returned. If you d

()

Source from the content-addressed store, hash-verified

5179// create the consumer with AddConsumer and bind to this consumer (using
5180// the nats.Bind() option).
5181func (s *Subscription) Unsubscribe() error {
5182 if s == nil {
5183 return ErrBadSubscription
5184 }
5185 s.mu.Lock()
5186 conn := s.conn
5187 closed := s.closed
5188 dc := s.jsi != nil && s.jsi.dc
5189 s.mu.Unlock()
5190 if conn == nil || conn.IsClosed() {
5191 return ErrConnectionClosed
5192 }
5193 if closed {
5194 return ErrBadSubscription
5195 }
5196 if conn.IsDraining() {
5197 return ErrConnectionDraining
5198 }
5199 err := conn.unsubscribe(s, 0, false)
5200 if err == nil && dc {
5201 err = s.deleteConsumer()
5202 }
5203 return err
5204}
5205
5206// checkDrained will watch for a subscription to be fully drained
5207// and then remove it.

Callers 15

TestSetPendingLimitsFunction · 0.95
TestNilConnectionFunction · 0.95
cleanupReplySubMethod · 0.80
subscribeMethod · 0.80
StopMethod · 0.80
GetMethod · 0.80
StopMethod · 0.80
bindRecvChanMethod · 0.80
oldRequestMethod · 0.80

Calls 4

deleteConsumerMethod · 0.95
IsClosedMethod · 0.80
unsubscribeMethod · 0.80
IsDrainingMethod · 0.45