function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Baljeet LalotraBaljeet Lalotra 

Controlling Platform Events Publishing Rate

Hi All,
The platform Events documentation at below link:-
https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_cometd.htm
which talks about "Subscription to Platform Event Notifications with CometD" says that " a CometD client can receive a batch of events at once. The number of event messages in a batch can vary. If the client uses a buffer for the received events, ensure that the buffer size is large enough to hold all event messages in the batch. The buffer size needed depends on the publishing rate and the event message size."

Question/Query:- Is there a way in which we can control the the publishing rate by Salesforce when we are publishing using the Apex Trigger on Salesforce side.

Thanks
Baljeet
ShivankurShivankur (Salesforce Developers) 
Hi Baljeet,

You can control the Publish Behavior of Platform events within the setup.And this way you could also control the publishing rate from Salesforce side.
  1. From Setup, enter Platform Events in the Quick Find box, then select Platform Events.
  2. On the Platform Events page, click New Platform Event or edit the exisiting Platform Event.
  3. Complete the standard fields, and optionally add a description for new record.
  4. For Publish Behavior, choose when the event message is published in a transaction.
  5. Click Save.
For Publich Behavior you can select Publish After Commit, here is the summary what it will do:
  • Publish After Commit to have the event message published only after a transaction commits successfully. Select this option if subscribers rely on data that the publishing transaction commits. For example, a process publishes an event message and creates a task record. A second process that is subscribed to the event is fired and expects to find the task record. Another reason for choosing this behavior is when you don't want the event message to be published if the transaction fails.
  • Publish Immediately to have the event message published when the publish call executes. Select this option if you want the event message to be published regardless of whether the transaction succeeds. Also choose this option if the publisher and subscribers are independent, and subscribers don't rely on data committed by the publisher. For example, the immediate publishing behavior is suitable for an event used for logging purposes. With this option, a subscriber might receive the event message before data is committed by the publisher transaction.
You can find more details about it on below documentation:
https://help.salesforce.com/articleView?id=sf.platform_events.htm&type=5

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.