Site icon WedgeCommerce

Plateform Event Basics

Banner

Before we jumped to understand the platform event, it is important to understand what are component or artifacts of an event-driven architecture. With the advent of the platform events, we really have the ability to implement the event-driven architecture. So that we can integrate different systems.

 

Event-driven Architecture:

It is like a typical publisher-subscriber model or we can say like the producer-consumer model. With the advent of the platform events, event-driven architecture is now possible. With the event-driven architecture the focus shifts from the entities involved in the integration to the actual message exchange that is exchanged between two entities. This architecture is much more loosely coupled so if we want to add or remove multiple producers or multiple consumers. It is very easy to do so. We can have different salesforce app or external app as a producer or the consumer.

Event Producer: A system produces or publishes events.

Event Consumer: it is the one that subscribes or listen to the events, takes in the event and processes the event

Event Bus: it is a centralized communication channel between producer and consumer.

 

Platform Event:

Platform Event is a sobject like a salesforce entity that you can create within your salesforce instance. Platform Event is suffixed with __e. We can define events based on the message exchange it means we can define different types of events for different types of integration.  We can define a custom field and attributes to define the message. An event is nothing but the definition of the message that you be exchanging between the publisher and the subscriber. The apex  setSavepoint()  and  rollback()  Database methods aren’t supported with platform events. There is a standard field, which you get when you create a platform event and that is known as ReplayId. ReplayId is very important because that ReplayId can be used to replay that specific event.

Steps to Create Platform Events:

 

 

Publishing/Subscribing   Platform Events:

 

We can publish platform events in 3 ways:

 

 Subscribing Platform Event:

Write an “after insert” Apex trigger on the event object to subscribe to incoming events.

Triggers receive event notifications from various sources—whether they are published through Apex or APIs.

CometD is a scalable HTTP-based event routing bus that uses an AJAX push technology pattern known as Comet.

Exit mobile version