1

I'm firing platform event from an LWC component when a record is updated from tab 1 and subscribing to that event in tab 2 to get the latest updates. The published events shows correctly however, it's exceeding the daily limit for event deliveries.

For example if we published 1000 events, its delivering 40,000 events.

Is there a way to check why there are duplicate deliveries for a single published event?

Below is code that I have in tab 1 and tab 2. Thanks!

Tab 1 :

updateDetails() {
        const fields = {};
        const recordInput = { fields };
        updateRecord(recordInput)
            .then(() => {
                this.firePlatformEvent();
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: 'Record Updated',
                        variant: 'success'
                    })
                );
            })
            .catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error updating record',
                        message: error.body.message,
                        variant: 'error'
                    })
                );
            });
    }

firePlatformEvent(){
    fireEvent({message:'success',caseId: this.Case__c});      
}  

Tab 2 :

connectedCallback() {
    this.registerErrorListener();
    this.handleSubscribe();
} 
   
handleSubscribe() {
    const self = this;
    const messageCallback = function (response) {
        var platformEventOwner = response.data.payload.CreatedById;
        if(USER_ID == platformEventOwner && response.data.payload.CaseId__c == self.recordId){
            self.showComponent = false;
            const myTimeout = setTimeout(() => {self.showComponent=true;}, 50);
        }
    };
 
    // Invoke subscribe method of empApi. Pass reference to messageCallback
    subscribe(this.channelName, -1, messageCallback).then(response => {
        // Response contains the subscription information on subscribe call
        console.log('Subscription request sent to: ', JSON.stringify(response.channel));
        this.subscription = response;
    });
}
2
  • Sounds like you might have other tabs subscribed as well.
    – Adrian Larson
    Aug 12, 2023 at 15:43
  • 2
    Will it not be the case every user with that page open will have the event delivered to them? This is why I think using platform events and CometD or EMP is untenable - just won't scale. The limits are way too low.
    – Phil W
    Aug 12, 2023 at 18:05

1 Answer 1

2

As I understand it, LWC's are treated as external deliveries because they use the CometD bus to receive the events.

The empApi component uses a shared CometD-based Streaming API connection

Source

Only external systems count for event deliveries. An external system can be defined as a system that subscribes to the event using cometD.

Source

That means you have a very low threshold to consume events in LWCs. Multiple components subscribed to events, users with extra tabs, and other things would make 4:1 publish to delivery very simple to achieve, and therefore make it likely for an org to blow passed the limits.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .