Subscribing to Salesforce Platform Events using External Java Client - CometD
Platform Events follow event based Architecture, where multiple subscribers can subscribe to a published event in real time manner.
Below diagram shows the basic Architecture of the event-based communication Model:
Event - This is a change in state for a business process
Event Message - Data about the event
Producer - Publisher of the event
Event Bus - A communication and storage service for published events
Event Consumer - A subscriber to the channel
Platform events can be subscribed internally and also externally
Platfrom events - Internal Subscription
Below are some scenarios in which you can consume platform events internally:
1. When we need to execute functionalities asynchronously to save govornor limits
2. To build a proper exception logging framework - You can find more details here
How to subscribe Internally?
we can see more details about this in a different blogpost.
Platfrom events - External Consumption
Many Organizations are moving to event-based integration approach and Salesforce Platform Events redefines and make the process easy, when we need to communicate with multiple external systems with same content.
Platform events are useful for external communication in the below scenarios:
- We are looking for real time data delivery
- We need to send same data to multiple subscribers
- Only changed data needs to be send and not entire record
Subscription Using CometD Client
CometD is a web messaging framework/library which supports pub-subscribe model. You can see more details here.
We can build our own CometD client or there is an opensource, community supported client - EMPConnector available, which we can use.
Why I tried EMPConnector?
In our current project, we used platform events as a messaging mechanism to communicate to an external system, whenever an order record is changed in Salesforce. We used Dell BOOMI as a middleware to subscribe to this event, but they started to receive/consume duplicate events. To verify the issue is on Salesoforce side or BOOMI side, we wanted to verify the event subscription using some other client and EMP Connector helped to verify this.
Steps involved to set up and execute EMP Connector:
- Set up Java Developer Kit 8
And executable jar files will be created downloading all the dependencies:
Once the set up is completed successfully, we can subscribe to the platform event using below command:
java -classpath target/emp-connector-0.0.1-SNAPSHOT-phat.jar com.salesforce.emp.connector.example.LoginExample <username> <password+token> /event/Member__e
If the login and subscription is success, we can see a message like below:
6. Publish Event and Verify Subscription
Nice and Informative Article. Can you tell me where was the duplicate issue? And how did you mitigate it?
ReplyDeleteIt was a middle ware issue, where they had multiple listeners added for parallel processing, and listeners receiving same events and processing it. They changed the model on their side to fix this.
DeleteHi Meera,
ReplyDeleteExactly what I was looking for :)
Its works like a charm in Trailhead playground but getting invalid username in my Sandbox, any idea why?
Thanks,
Ram
Hi Ram,
DeleteI updated post with steps required to connect to a sandbox. Basically you need to update Loginhelper.java class to point endpoint url to test.salesforce.com
Hi Meera,
DeleteThanks a lot for your quick reply. It worked :)
Congratulations! for your Salesforce MVP
Thank you Ram!
DeleteThis comment has been removed by the author.
ReplyDeleteThanks for this Meera.. Very helpful..
ReplyDeleteHi Meera,
ReplyDeleteI am having a requirement like this.
Connect to Java app from salesforce app using rest API and insert records to salesforce custom object on daily basis. How can we achieve this? If yes in how many ways and what are those?
Can you pls help me on this ?
Hi Meera, thanks for this article.As you said Boomi could be one of the MW which could be used to subscribe to the platform events in SF.
ReplyDeleteWas there any other evaluatation made on alternate tools, if yes are there any, please advise.
Thanks for your information. very good article.
ReplyDeletesalesforce cpq training
salesforce cpq online training
Thank For sharing Valuable Information
ReplyDeleteSalesforce CPQ Online Training Hyderabad
Salesforce CPQ Online Training India
I am honestly turned on by way of this wonderful issues. I'd favor to consider high quality material which often position I stumbled onto in just a particular person write-up. Cheers intended for providing. Printed Articles
ReplyDeleteHi Meera
Deletecan we send event data to kinesis data stream from Emp connectore?
I was looking for an easy way to subscribe to platform events. This really helped.
ReplyDeleteThank you for publishing this
I really liked your blog post.Much thanks again. Awesome.
ReplyDeleteSalesforce CPQ Training
Salesforce CPQ Online Training
Hi Meera
ReplyDeletecan we send event data to kinesis data stream from Emp connectore?
Thank For sharing Valuable Information
ReplyDeleteMulesoft Training in Hyderabad
Mulesoft Online Training in India
Hi Meera, wonderful article, how does the external system like oracle cloud subscribe to salesforce platform event
ReplyDelete