Loading

How to Subscribe to Salesforce Platform Events with Mule 4

게시 일자: Mar 2, 2024
과업

GOAL

This applies to Mule 4, Anypoint Studio 7.x
Salesforce Connector can subscribe to Salesforce Platform Events, in order to receive events from Salesforce. This article explains how to Subscribe to Salesforce Platform Events in Mule Application flow.

단계

In this article, please follow an example in Trailhead Define and Publish Platform Events.

1. Login to Salesforce and create a Salesforce Platform Events. Please follow the example in the Trailhead to create a Platform Events “Cloud_News__e”.
2. Create a Mule application
2-1. Create a component Subscribe Channel, then specify “/event/Cloud_News__e” as Streaming channel.
2-2. Create a logger component to show payload, so that we will see the received message on Console.
Example)

<flow name="SampleFlow" doc:id="d25ff96a-aec9-45ee-89f2-74080fb83b45" >
  <salesforce:subscribe-channel doc:name="Subscribe channel" doc:id="cb21f452-9280-41f8-ba52-93c49a03ea38" config-ref="Salesforce_Config" 
   streamingChannel="/event/Cloud_News__e"/>
  <logger level="INFO" doc:name="Logger" doc:id="5ebd77bf-87de-4f55-ab81-2af3abbe2bee" message="#[payload]"/>
</flow>

3. As written in the above Trailhead content, Publish a Platform Event Message to “Cloud_News__e“. You can use Apex code, Process, Flow, or Salesforce APIs. For example, you can request POST with the below body.

{
   "Location__c" : "Mountain City",
   "Urgent__c" : true,
   "News_Content__c" : "Lake Road is closed due to mudslides."
}

4. You will see something like below in the Console log, which is equivalent to the above POST body.

INFO  2019-10-26 16:11:50,483 [[MuleRuntime].cpuLight.05: [test].SampleFlow.CPU_LITE @2b42bef0] 
[event: e00096e0-f7bf-11e9-b534-8c85907d741e] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
{data={schema=eGRz2Sfoy-YO9mVvH8J4fg, 
payload=
{News_Content__c=Lake Road is closed due to mudslides.,
 CreatedById=0050o00000U3Q8vAAF,
 CreatedDate=2019-10-26T07:12:01.026Z,
 Location__c=Mountain City, Urgent__c=true},
 event={replayId=49544589}},
 channel=/event/Cloud_News__e}

Disclaimer: This example is provided as a reference for your own usage and is not to be considered a MuleSoft product. This example should be considered as a custom solution. The custom solution is not a Supported MuleSoft product.
Knowledge 기사 번호

001116948

 
로드 중
Salesforce Help | Article