Get Started with Pub/Sub API

Pub/Sub API provides a single interface for publishing and subscribing to platform events, including real-time event monitoring events, and change data capture events. Based on gRPC API and HTTP/2, Pub/Sub API efficiently publishes and delivers binary event messages in the Apache Avro format.

REQUIRED EDITIONS
Available in: Enterprise, Performance, Unlimited, and Developer Editions
Not Available in: Government Cloud

The Pub/Sub API provides many benefits:

  • Publishing, subscribing, and event schema retrieval all in one API.
  • Final publish results of publish operations, and not intermediate queueing results.
  • Flow control that lets you specify how many events to receive in a subscribe call based on event processing speed in the client.
  • Scalable and secure publishing and delivery of platform events, change data capture events, and real-time event monitoring events.
  • Real-time, highly performant data streaming that uses compression through HTTP/2.
  • Support for 11 programming languages in the client that are offered by the gRPC API, such as Python, Java, Node, and C++. For all the supported languages, see https://grpc.io/docs/languages/.
  • An active online developer community presence for gRPC.
  • Bidirectional data streaming through the gRPC API. The client and the server can send a sequence of messages to each other using two independent streams.
  • Cross-cloud integration capabilities enabling the development of event-driven apps that integrate across Salesforce clouds.

Simplify your development with Pub/Sub API by using a single API to work with events instead of using disparate APIs. This table compares the tasks that you perform with Pub/Sub API versus other APIs.

TaskCan accomplish with Pub/Sub APIHow to accomplish with other APIs
Publish platform eventsPub/Sub APIData APIs: SOAP API, REST API, Bulk API
Subscribe to events: platform events, change data capture events, real-time event monitoring events, and standard eventsPub/Sub APIStreaming API
Get the event schemaPub/Sub APIREST API

Before Pub/Sub API was introduced, the only way to subscribe to events in an external client was with Streaming API. This table compares some features of the two subscription APIs.

Pub/Sub APIStreaming API
Event EncodingBinary (Apache Avro)JSON
ProtocolgRPC and protocol buffersCometD, an implementation of the Bayeux protocol
Subscription modelPull-based—the client requests the number of events to receive as they become available in the event bus.Push-based—the server delivers events as they become available in the event bus.
Subscription flow controlClient specifies how many events to receive for a Subscribe call based on event processing speed in the client.Client doesn’t control the amount of events delivered from the server.
Publish statusFinal publishing result returned indicates that the event was successfully published or that the publish failed.Not supported with Streaming API. When using data APIs to publish events, the event queueing result is returned. When system resources are available, queued events are published.
Bitmap field data in change data capture eventsClient has to decode the bitmap field data to JSON.Streaming API decodes bitmap field data to JSON before delivering events to the client.

Pub/Sub API enables you to build event-driven integration apps. Here are some examples of what you can do with the Pub/Sub API.

  • Subscribe to Event Monitoring real-time events, and publish a platform event back into Salesforce to restrict a user’s profile when they log into Salesforce after working hours.
  • Subscribe to change data capture events, and synchronize order data in an external inventory system.
  • Subscribe to a standard platform event, such as AppointmentSchedulingEvent, and integrate with Google Calendar to update users’ calendars.

Using the Pub/Sub API, you can interface with the expanded and improved Salesforce event bus by publishing and subscribing to events. The event bus is a multitenant, multicloud event storage and delivery service based on a publish-subscribe model. The event bus is based on a time-ordered event log, which ensures that event messages are stored and delivered in the order that they’re received by Salesforce. Platform events and change data capture events are published to the event bus, where they’re stored temporarily. You can retrieve stored event messages from the event bus with the Pub/Sub API. Each event message contains the replay ID field, represented as replay_id in the protocol specification. It’s an opaque ID that identifies the event in the stream and enables replaying the stream after a specific replay ID.

Salesforce event bus

The expanded event bus service is built outside the main Salesforce CRM stack, which powers Sales Cloud and Service Cloud, Salsforce’s original products. As a result, the API provides cross-cloud integration capabilities between Sales Cloud and Service Cloud and other Salesforce clouds, such as Marketing Cloud, Commerce Cloud, and Tableau Analytics. It also provides enhanced scalability and performance. Developers can focus on building event-driven apps that scale and integrate across various Salesforce clouds.

See Also