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

Function processConsInfo

js.go:1559–1609  ·  view source on GitHub ↗
(info *ConsumerInfo, userCfg *ConsumerConfig, isPullMode bool, subj, queue string)

Source from the content-addressed store, hash-verified

1557}
1558
1559func processConsInfo(info *ConsumerInfo, userCfg *ConsumerConfig, isPullMode bool, subj, queue string) (string, error) {
1560 ccfg := &info.Config
1561
1562 // Make sure this new subject matches or is a subset.
1563 if ccfg.FilterSubject != _EMPTY_ && subj != ccfg.FilterSubject {
1564 return _EMPTY_, ErrSubjectMismatch
1565 }
1566
1567 // Prevent binding a subscription against incompatible consumer types.
1568 if isPullMode && ccfg.DeliverSubject != _EMPTY_ {
1569 return _EMPTY_, ErrPullSubscribeToPushConsumer
1570 } else if !isPullMode && ccfg.DeliverSubject == _EMPTY_ {
1571 return _EMPTY_, ErrPullSubscribeRequired
1572 }
1573
1574 // If pull mode, nothing else to check here.
1575 if isPullMode {
1576 return _EMPTY_, checkConfig(ccfg, userCfg)
1577 }
1578
1579 // At this point, we know the user wants push mode, and the JS consumer is
1580 // really push mode.
1581
1582 dg := info.Config.DeliverGroup
1583 if dg == _EMPTY_ {
1584 // Prevent an user from attempting to create a queue subscription on
1585 // a JS consumer that was not created with a deliver group.
1586 if queue != _EMPTY_ {
1587 return _EMPTY_, errors.New("cannot create a queue subscription for a consumer without a deliver group")
1588 } else if info.PushBound {
1589 // Need to reject a non queue subscription to a non queue consumer
1590 // if the consumer is already bound.
1591 return _EMPTY_, errors.New("consumer is already bound to a subscription")
1592 }
1593 } else {
1594 // If the JS consumer has a deliver group, we need to fail a non queue
1595 // subscription attempt:
1596 if queue == _EMPTY_ {
1597 return _EMPTY_, fmt.Errorf("cannot create a subscription for a consumer with a deliver group %q", dg)
1598 } else if queue != dg {
1599 // Here the user's queue group name does not match the one associated
1600 // with the JS consumer.
1601 return _EMPTY_, fmt.Errorf("cannot create a queue subscription %q for a consumer with a deliver group %q",
1602 queue, dg)
1603 }
1604 }
1605 if err := checkConfig(ccfg, userCfg); err != nil {
1606 return _EMPTY_, err
1607 }
1608 return ccfg.DeliverSubject, nil
1609}
1610
1611func checkConfig(s, u *ConsumerConfig) error {
1612 makeErr := func(fieldName string, usrVal, srvVal any) error {

Callers 1

subscribeMethod · 0.85

Calls 2

checkConfigFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected