Subscribe to a Topic
To subscribe to a topic, add the Subscribe topic listener (subscribe-topic-listener) or Replay topic listener (replay-topic-listener) as an input source for your flow from mule palette
The input source acts as an inbound endpoint. Every time the subscription receives an event, the input source executes the rest of the flow in your Mule app.
Prerequisites:
- Installing salesforce connector(by login into anypoint exchange from studio you can install the salesfoce conenctor)
- Salesforce developer account
- Security token
- Consumer key and secret(If you are using the Salesforce connector to access an OAuth API, you also need a consumer key and secret)
Create project in anypoint studio
Drag and drop Salesforce Subscribe Topic Operation from mule palette
Configure the connection details for salesforce and use the Basic Username and Password connection(Username,Password,Securitytoken),you can also use other connections as well to do the configuration like Oauth UserName and Password etc
Configure Topic name as AccountUpdate created in last tutorial(Publish Topic)
Transform the message for the notifications received from the topic
%dw 2.0 output application/json --- payload
Deploy the application and test
For testing purpose create a new account as TestDemo in Salesforce
Notification Received from Topic as shown in logs below
INFO 2020-05-04 14:03:19,082 [[MuleRuntime].io.06: [subscribetopic].io@org.mule.runtime.module.extension.internal.runtime.source.ExtensionMessageSource.lambda$null$9:329 @76dd4add] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: BayeuxClient starting.
INFO 2020-05-04 14:03:21,704 [HttpClient@694460cb-110] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Handshake successful, subscribing.
INFO 2020-05-04 14:03:22,384 [[MuleRuntime].io.06: [subscribetopic].io@org.mule.runtime.module.extension.internal.runtime.source.ExtensionMessageSource.lambda$null$9:329 @76dd4add] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Subscribing to: /topic/AccountUpdate from replyId: -1
INFO 2020-05-04 14:03:24,633 [HttpClient@694460cb-104] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Successfully subscribed to /topic/AccountUpdate
INFO 2020-05-04 14:07:54,522 [[MuleRuntime].cpuIntensive.01: [subscribetopic].subscribetopicFlow.CPU_INTENSIVE @5f3571ea] [event: 8c1e1b10-8de2-11ea-96d4-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Payload Received From Topic: {
“Id”: “0012w00000BFeJsAAL”,
“Name”: “TestDemo”
}
Sample application: subscribetopic sample application