Replay a Topic

 

In last tutorial I have demonstrate how to subscribe the topic, there is another way to read events from salesforce using Replay a topic which provides various options to read the events.

The Replay Topic Listener operation provides below options:

  • ALL: Subscriber receives all events, including past events that are within the 24-hour retention period and new events sent after the client subscribes
  • ONLY_NEW: Subscriber receives new events that are broadcast after the client subscribes.
  • FROM_REPLAY_ID: Subscriber receives all events after the specified event replayId.

Note: If you specify the ALL or ONLY_NEW the replay id values are ignored.

There is another option Resume from the Last Replay Id checkbox enables you to specify an automatic replay of stored events, based on the Replay ID of the last event processed by the connector.

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 Replay Topic Operation from mule palette,

Usecase -1

First I will provide the Topic Name created in last tutorial and Replay option as ONLY_NEW

 

Replay Topic

 

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

Replay Topic

 

Transform the message for the notifications received from the topic

%dw 2.0
output application/json
---
payload

Deploy the application and test

Create a new account as TestDemo in Salesforce

Replay Topic

 

Notification Received from Topic as shown in logs below

INFO 2020-05-08 10:47:22,688 [HttpClient@63be6608-132] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Handshake successful, subscribing.
INFO 2020-05-08 10:47:23,589 [[MuleRuntime].io.05: [replaytopic].io@org.mule.runtime.module.extension.internal.runtime.source.ExtensionMessageSource.lambda$null$9:329 @163225bc] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Subscribing to: /topic/AccountUpdate from replyId: -1
INFO 2020-05-08 10:47:25,266 [HttpClient@63be6608-130] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Successfully subscribed to /topic/AccountUpdate
INFO 2020-05-08 10:47:52,093 [[MuleRuntime].cpuIntensive.02: [replaytopic].replaytopicFlow.CPU_INTENSIVE @2088d06e] [event: 43ff98c1-90eb-11ea-9e9f-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
Payload Received 
{
	"Id": "0012w00000BHeVyAAL",
	"Name": "TestNew"
}

Usecase -2

Change the replay option to ALL

 

 

Deploy the application,as shown in the below logs all the events that has been created in last 24-hours will be received

INFO 2020-05-08 11:14:13,379 [HttpClient@572bbf05-151] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Successfully subscribed to /topic/AccountUpdate
INFO 2020-05-08 11:14:15,056 [[MuleRuntime].cpuIntensive.03: [replaytopic].replaytopicFlow.CPU_INTENSIVE @8c7a52] [event: f385f480-90ee-11ea-9e9f-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
Payload Received 
{
	"Id": "0012w00000BHeVyAAL",
	"Name": "TestNew"
}

INFO 2020-05-08 11:14:15,057 [[MuleRuntime].cpuIntensive.01: [replaytopic].replaytopicFlow.CPU_INTENSIVE @8c7a52] [event: f3841fc0-90ee-11ea-9e9f-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
Payload Received 
{
	"Id": "0012w00000BHeQEAA1",
	"Name": "TestReplayTopic"
}

 

Usecase-3

Change the replay option to FROM_REPLAY_ID and provide replay id value to process all the messages after that replay id

 

 

Deploy the application you can see the below logs received the message after replay id 2

INFO 2020-05-08 19:40:41,176 [[MuleRuntime].io.08: [replaytopic].io@org.mule.runtime.module.extension.internal.runtime.source.ExtensionMessageSource.lambda$null$9:329 @1fed881d] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Subscribing to: /topic/AccountUpdate from replyId: 2
INFO 2020-05-08 19:40:41,176 [[MuleRuntime].io.08: [replaytopic].io@org.mule.runtime.module.extension.internal.runtime.source.ExtensionMessageSource.lambda$null$9:329 @1fed881d] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: <strong>Subscribing to: /topic/AccountUpdate from replyId: 2</strong>
INFO 2020-05-08 19:40:43,015 [HttpClient@757cb098-108] [event: ] org.mule.extension.salesforce.internal.service.streaming.StreamingClient: Successfully subscribed to /topic/AccountUpdate
INFO 2020-05-08 19:40:45,180 [[MuleRuntime].cpuIntensive.02: [replaytopic].replaytopicFlow.CPU_INTENSIVE @7b6c17f8] [event: b564d580-9135-11ea-9aca-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
Payload Received 
{
	"Id": "0012w00000BHiH9AAL",
	"Name": "testforreplayid"
}

INFO 2020-05-08 19:40:45,180 [[MuleRuntime].cpuIntensive.03: [replaytopic].replaytopicFlow.CPU_INTENSIVE @7b6c17f8] [event: b56598d0-9135-11ea-9aca-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
Payload Received 
{
	"Id": "0012w00000BHiGBAA1",
	"Name": "testforreplay"
}

INFO 2020-05-08 19:40:45,180 [[MuleRuntime].cpuIntensive.01: [replaytopic].replaytopicFlow.CPU_INTENSIVE @7b6c17f8] [event: b5489af0-9135-11ea-9aca-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: 
Payload Received 
{
	"Id": "0012w00000BHeVyAAL",
	"Name": "TestNew"
}

Sample application: replaytopic sample application

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments