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

Method getConsumerInfoContext

js.go:3513–3540  ·  view source on GitHub ↗
(ctx context.Context, stream, consumer string)

Source from the content-addressed store, hash-verified

3511}
3512
3513func (js *js) getConsumerInfoContext(ctx context.Context, stream, consumer string) (*ConsumerInfo, error) {
3514 ccInfoSubj := fmt.Sprintf(apiConsumerInfoT, stream, consumer)
3515 resp, err := js.apiRequestWithContext(ctx, js.apiSubj(ccInfoSubj), nil)
3516 if err != nil {
3517 if errors.Is(err, ErrNoResponders) {
3518 err = ErrJetStreamNotEnabled
3519 }
3520 return nil, err
3521 }
3522
3523 var info consumerResponse
3524 if err := json.Unmarshal(resp.Data, &info); err != nil {
3525 return nil, err
3526 }
3527 if info.Error != nil {
3528 if errors.Is(info.Error, ErrConsumerNotFound) {
3529 return nil, ErrConsumerNotFound
3530 }
3531 if errors.Is(info.Error, ErrStreamNotFound) {
3532 return nil, ErrStreamNotFound
3533 }
3534 return nil, info.Error
3535 }
3536 if info.Error == nil && info.ConsumerInfo == nil {
3537 return nil, ErrConsumerNotFound
3538 }
3539 return info.ConsumerInfo, nil
3540}
3541
3542// a RequestWithContext with tracing via TraceCB
3543func (js *js) apiRequestWithContext(ctx context.Context, subj string, data []byte) (*Msg, error) {

Callers 2

getConsumerInfoMethod · 0.95
ConsumerInfoMethod · 0.95

Calls 3

apiRequestWithContextMethod · 0.95
apiSubjMethod · 0.95
IsMethod · 0.45

Tested by

no test coverage detected