@@ -1588,8 +1588,23 @@ func (o *consumer) unsubscribe(sub *subscription) {
1588
1588
1589
1589
// We need to make sure we protect access to the outq.
1590
1590
// Do all advisory sends here.
1591
- func (o * consumer ) sendAdvisory (subj string , msg []byte ) {
1592
- o .outq .sendMsg (subj , msg )
1591
+ func (o * consumer ) sendAdvisory (subject string , e any ) {
1592
+ if o .acc == nil {
1593
+ return
1594
+ }
1595
+
1596
+ // If there is no one listening for this advisory then save ourselves the effort
1597
+ // and don't bother encoding the JSON or sending it.
1598
+ if sl := o .acc .sl ; (sl != nil && ! sl .HasInterest (subject )) && ! o .srv .hasGatewayInterest (o .acc .Name , subject ) {
1599
+ return
1600
+ }
1601
+
1602
+ j , err := json .Marshal (e )
1603
+ if err != nil {
1604
+ return
1605
+ }
1606
+
1607
+ o .outq .sendMsg (subject , j )
1593
1608
}
1594
1609
1595
1610
func (o * consumer ) sendDeleteAdvisoryLocked () {
@@ -1605,13 +1620,8 @@ func (o *consumer) sendDeleteAdvisoryLocked() {
1605
1620
Domain : o .srv .getOpts ().JetStreamDomain ,
1606
1621
}
1607
1622
1608
- j , err := json .Marshal (e )
1609
- if err != nil {
1610
- return
1611
- }
1612
-
1613
1623
subj := JSAdvisoryConsumerDeletedPre + "." + o .stream + "." + o .name
1614
- o .sendAdvisory (subj , j )
1624
+ o .sendAdvisory (subj , e )
1615
1625
}
1616
1626
1617
1627
func (o * consumer ) sendPinnedAdvisoryLocked (group string ) {
@@ -1629,13 +1639,8 @@ func (o *consumer) sendPinnedAdvisoryLocked(group string) {
1629
1639
Group : group ,
1630
1640
}
1631
1641
1632
- j , err := json .Marshal (e )
1633
- if err != nil {
1634
- return
1635
- }
1636
-
1637
1642
subj := JSAdvisoryConsumerPinnedPre + "." + o .stream + "." + o .name
1638
- o .sendAdvisory (subj , j )
1643
+ o .sendAdvisory (subj , e )
1639
1644
1640
1645
}
1641
1646
func (o * consumer ) sendUnpinnedAdvisoryLocked (group string , reason string ) {
@@ -1653,13 +1658,8 @@ func (o *consumer) sendUnpinnedAdvisoryLocked(group string, reason string) {
1653
1658
Reason : reason ,
1654
1659
}
1655
1660
1656
- j , err := json .Marshal (e )
1657
- if err != nil {
1658
- return
1659
- }
1660
-
1661
1661
subj := JSAdvisoryConsumerUnpinnedPre + "." + o .stream + "." + o .name
1662
- o .sendAdvisory (subj , j )
1662
+ o .sendAdvisory (subj , e )
1663
1663
1664
1664
}
1665
1665
@@ -1679,13 +1679,8 @@ func (o *consumer) sendCreateAdvisory() {
1679
1679
Domain : o .srv .getOpts ().JetStreamDomain ,
1680
1680
}
1681
1681
1682
- j , err := json .Marshal (e )
1683
- if err != nil {
1684
- return
1685
- }
1686
-
1687
1682
subj := JSAdvisoryConsumerCreatedPre + "." + o .stream + "." + o .name
1688
- o .sendAdvisory (subj , j )
1683
+ o .sendAdvisory (subj , e )
1689
1684
}
1690
1685
1691
1686
func (o * consumer ) sendPauseAdvisoryLocked (cfg * ConsumerConfig ) {
@@ -1705,13 +1700,8 @@ func (o *consumer) sendPauseAdvisoryLocked(cfg *ConsumerConfig) {
1705
1700
e .Paused = time .Now ().Before (e .PauseUntil )
1706
1701
}
1707
1702
1708
- j , err := json .Marshal (e )
1709
- if err != nil {
1710
- return
1711
- }
1712
-
1713
1703
subj := JSAdvisoryConsumerPausePre + "." + o .stream + "." + o .name
1714
- o .sendAdvisory (subj , j )
1704
+ o .sendAdvisory (subj , e )
1715
1705
}
1716
1706
1717
1707
// Created returns created time.
@@ -2652,12 +2642,7 @@ func (o *consumer) processNak(sseq, dseq, dc uint64, nak []byte) {
2652
2642
Domain : o .srv .getOpts ().JetStreamDomain ,
2653
2643
}
2654
2644
2655
- j , err := json .Marshal (e )
2656
- if err != nil {
2657
- return
2658
- }
2659
-
2660
- o .sendAdvisory (o .nakEventT , j )
2645
+ o .sendAdvisory (o .nakEventT , e )
2661
2646
2662
2647
// Check to see if we have delays attached.
2663
2648
if len (nak ) > len (AckNak ) {
@@ -2732,15 +2717,8 @@ func (o *consumer) processTerm(sseq, dseq, dc uint64, reason, reply string) bool
2732
2717
Domain : o .srv .getOpts ().JetStreamDomain ,
2733
2718
}
2734
2719
2735
- j , err := json .Marshal (e )
2736
- if err != nil {
2737
- // We had an error during the marshal, so we can't send the advisory,
2738
- // but we still need to tell the caller that the ack was processed.
2739
- return ackedInPlace
2740
- }
2741
-
2742
2720
subj := JSAdvisoryConsumerMsgTerminatedPre + "." + o .stream + "." + o .name
2743
- o .sendAdvisory (subj , j )
2721
+ o .sendAdvisory (subj , e )
2744
2722
return ackedInPlace
2745
2723
}
2746
2724
@@ -3052,12 +3030,7 @@ func (o *consumer) sampleAck(sseq, dseq, dc uint64) {
3052
3030
Domain : o .srv .getOpts ().JetStreamDomain ,
3053
3031
}
3054
3032
3055
- j , err := json .Marshal (e )
3056
- if err != nil {
3057
- return
3058
- }
3059
-
3060
- o .sendAdvisory (o .ackEventT , j )
3033
+ o .sendAdvisory (o .ackEventT , e )
3061
3034
}
3062
3035
3063
3036
// Process an ACK.
@@ -3946,12 +3919,7 @@ func (o *consumer) notifyDeliveryExceeded(sseq, dc uint64) {
3946
3919
Domain : o .srv .getOpts ().JetStreamDomain ,
3947
3920
}
3948
3921
3949
- j , err := json .Marshal (e )
3950
- if err != nil {
3951
- return
3952
- }
3953
-
3954
- o .sendAdvisory (o .deliveryExcEventT , j )
3922
+ o .sendAdvisory (o .deliveryExcEventT , e )
3955
3923
}
3956
3924
3957
3925
// Check if the candidate subject matches a filter if its present.
0 commit comments