Publish and Subscribe to Salesforce Platform Events
Last updated November 09, 2023
Table of Contents
You can architect apps using an event-driven approach with the Salesforce enterprise messaging platform. Platform Events provides a powerful technique for integrating business processes in Salesforce, or for integrating such processes with external systems, such as Heroku apps. The architecture is suitable for large distributed systems because it decouples event producers from event consumers, simplifying the communication model in connected systems.
Heroku applications can behave as event producers, event consumers, or some combination of the two.
When to Use
You want to build a modern integration with the Salesforce enterprise messaging platform. The messaging platform lets you build modular integrations with clean integration boundaries using an event bus, instead of point-to-point integrations.
Publishing Platform Events From Heroku
Publish platform events with Pub/Sub API using a programming language that Pub/Sub API and Heroku support, including Java, Node.js, Go, and Python. Based on gRPC API and HTTP/2, Pub/Sub API provides a single interface to efficiently publish and deliver binary event messages in the Apache Avro format. For more information, see Publish Event Messages with Pub/Sub API in the Platform Events Developer Guide.
To write an app for publishing events, you can start with the getting started code example provided for a supported language in Language Support. Then modify the example to add your code to create a Pub/Sub API client and publish an event with the Publish RPC method or the PublishStream RPC method. For Pub/Sub API client code examples, see the Pub/Sub API GitHub repo. Also, check out the E-Bikes Manufacturing Demo app which you can deploy to Heroku. The E-Bikes Manufacturing app is a Node app that uses the Lightning Web Runtime. For more information, see Platform Event Samples in the Platform Events Developer Guide.
Subscribing to Platform Events
Subscribe to platform events and change data capture events with Pub/Sub API using a programming language that Pub/Sub API and Heroku support, including Java, Node.js, Go, and Python. Based on gRPC API and HTTP/2, Pub/Sub API provides a single interface to efficiently publish and deliver binary event messages in the Apache Avro format. For more information, see Subscribe to Platform Event Notifications with Pub/Sub API in the Platform Events Developer Guide.
To write an app for subscribing to events, you can start with the getting started code example provided for a supported language in Language Support. Then modify the example to add your code for subscribing to events using the Subscribe RPC method. For Pub/Sub API client code examples, see the Pub/Sub API GitHub repo. Also, check out the E-Bikes Manufacturing Demo app which you can deploy to Heroku. The E-Bikes Manufacturing app is a Node app that uses the Lightning Web Runtime. For more information, see Platform Event Samples in the Platform Events Developer Guide. The E-Bikes app subscribes to change data capture events for incoming orders and then publishes platform events to update orders. You can modify the topic parameter to subscribe to a specific platform event or change event.
Limits & Considerations
Read the Salesforce docs that describe what to consider when building with Platform Events, including avoiding infinite trigger loops, API limits, and more.
Security and Heroku/Salesforce integrations shows how to secure this integration.