question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

replay functionality is not working - Platform events

See original GitHub issue

I am trying to subscribe to a platform event in salesforce and it works fine - except ability to replay events -either from a specific replayId or from the earliest available (-2). Below is the code that I am using - which is taken from a sample code provided in a salesforce doc but is not working - any help would be greatly appreciated.

`org.authenticate({ username: USERNAME, password: PASSWORD,securityToken: SECURITY_TOKEN }, function(err, oauth) { if(err) return console.log("Error authenticating to Salesforce, " + err); var client = org.createStreamClient();

	    REPLAY_ID = -2;
	    console.log("Latest REPLAY_ID - ", REPLAY_ID);			
	  }
	});
	
	
	var accs = client.subscribe({topic:TOPIC, isEvent:true, **retry: -2**});`

I have also tried using “replayId” and “replayFrom” instead of retry but still no good. I am running this code from AWS Lambda - Node JS .

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
hassanazharkhancommented, Mar 9, 2020

This workaround also works for me, thanks @Alasano ! & @karoldylewski Finally I ended up with below code and its working fine with typescript.

import * as nforce from 'nforce'
import * as config from 'config'
import oAuth from '../types/oAuth'

class SalesforcePlatformEvents {
  private organization: any;
  constructor() {
    this.organization = nforce.createConnection({
      clientId: config.get('app.nforceKeys.clientId'),
      clientSecret: config.get('app.nforceKeys.clientSecret'),
      redirectUri: config.get('app.nforceKeys.redirectUri'),
      environment: config.get('app.nforceKeys.environment'),
      apiVersion: 'v44.0',
    })
  }

  public startEventListner() {
    const self = this.organization
    self.authenticate({
      username: config.get('app.nforceCredentials.user'),
      password: config.get('app.nforceCredentials.pass'),
    },
    function(err: any, oauth: oAuth) {
      if (err) return console.log(err)
      if (!err) console.log('*** Successfully connected to Salesforce ***')

      const client = self.createStreamClient({oauth})
      const sub = client.subscribe({topic: config.get('app.nforceTopic.topic')})

      client.on('connect', function() {
        console.log('*** Streaming client transport: UP ***')
      })

      client.on('disconnect', function(data: any) {
        console.log('*** Streaming disconnect : ' + data.reason)
        console.log('*** Disconnect data', data)
      })

      sub.on('connect', function() {
        console.log('*** Connected to topic: ' + sub.getTopic())
      })

      sub.on('error', function(error: Error) {
        console.log('*** Error: ' + error)
        sub.cancel()
        client.disconnect()
      })

      sub.on('data', function(data: any) {
        console.log('Data: ', data)
        console.log('Current replay id: ' + sub.getReplayId())
      })
    })
  }
}

export default SalesforcePlatformEvents
3reactions
Alasanocommented, May 16, 2019

Not 100% related but digging through here did allow me to make my pushtopic work in 1.12.2

Connecting in single mode as described in the doc I was getting this error

"400::The replayId for channel {/topic/mypushtopic} wasn't found using the " +
    'provided replay ID map {{}}. Ensure that the channel name you provided in ' +
    'the replay map is valid and matches the channel name used for subscribing.'

I replaced the fdcstream.js in the 1.12.2 release with the one from the streaming-2.0 branch and changed the way I subscribe to the pushtopic (passing in /topic/mypushtopic instead of just the topic name, found here https://github.com/kevinohara80/nforce/blob/streaming-2.0/examples/stream.js)

With that I’m able to connect succesfully for the moment. Looking forward to the full 2.0 release, especially the typescript part! Nice work @kevinohara80

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Replay Id of child event is less than the parent event
I am publishing the events in such a way that first the controller executes the publish method for Parent and then the child...
Read more >
Salesforce Replay Channel Listener Does Not Subscribe To ...
After restarting a Mule application, Salesforce Replay Channel Listener does not consume Platform Events. It was solved after another Mule app ...
Read more >
Retrieving old platform events using replayId as -2
I could not figure out why it sometimes retrieves old events and sometimes throws out error message. Also, it is giving stored events...
Read more >
HOW TO: Manually restart the execution of Salesforce platform ...
In order to trigger the process for Msg1, the replayID of previous platform event is required. ... As an alternative to republishing the ......
Read more >
How to use IBM App Connect with Salesforce
App Connect has enabled support for the replay ID with Salesforce platform events. This means that if for any reason you had to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found