Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Streaming stops without emitting an error #168

Closed
erangahn opened this issue Jan 21, 2019 · 6 comments
Closed

Streaming stops without emitting an error #168

erangahn opened this issue Jan 21, 2019 · 6 comments

Comments

@erangahn
Copy link

erangahn commented Jan 21, 2019

I am using the current version of nforce library with the modifications of replayId from crimson-education. The client works for some time and stops getting new events from Salesforce without emitting any errors. Below here is how I have implemented the streaming client.

Could you help find what I did wrong?

const params = {
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  redirectUri: CALLBACK_URL + '/oauth/_callback',
  mode: 'single',
  environment: ENVIRONMENT,
  apiVersion: 'v41.0',
  autoRefresh: true,
  replayId: -1
};
const connection = nforce.createConnection(params);
const userInfo = { username: USERNAME, password: PASSWORD };
const oauth = await connection.authenticate(userInfo);
const params = { topic, oauth, replayId };
const client = await connection.createStreamClient();
const stream = await client.subscribe(params);
stream.on('connect', onConnectHandler);
stream.on('error', onErrorHandler);
stream.on('data', onDataHandler);

Above is the minimalistic code that explains my order of execution.
CC: @kevinohara80

@djkeshawa
Copy link

I have the same issue...

@kolithawarnakulasooriya

I also have the same issue. I used the forked 'https://github.com/crimson-education/nforce' instead using this. and my implementation also looks like this. no messages are received after some time but the connection is still there. so curious.

@kevinohara80
Copy link
Owner

kevinohara80 commented Jan 21, 2019 via email

@kevinohara80
Copy link
Owner

@erangahn I'm going to close this only because it appears to be the same as #131. This has been a long-running issue with the Faye client.

Keep an eye on that issue as I'm going to be working on a fix. If you feel that this issue is different somehow, feel free to re-open it.

@erangahn
Copy link
Author

For anyone who comes up with the same issue I had, here's how I handled this.

First, I forked this repo and changed the lib/fdcstream.js file and add following lines to the end of Client function (client definition).

var reconnectExtension = {
  incoming: function(message, callback) {
    if (message.channel === '/meta/disconnect') {
      self.emit('reconnect');
    }
    callback(message);
  }
};

this._fayeClient.addExtension(reconnectExtension);

Now Faye client will emit a reconnect event whenever it gets /meta/disconnect.

Then publish this as a separate npm module or use the git path itself in package.json when using nforce module.

Now in your code, you can simply check whether streaming client emits a reconnect event and do necessary handling.

Here's my sample code:

const connection = nforce.createConnection({
  clientId: CLIENT_ID,
  clientSecret: CLIENT_SECRET,
  redirectUri: CALLBACK_URL + '/oauth/_callback',
  mode: 'single',
  environment: ENVIRONMENT,
  apiVersion: 'v41.0',
  autoRefresh: true,
  username: USERNAME,
  password: PASSWORD
});
connection.authenticate();
const client = connection.createStreamClient();
const stream = client.subscribe({
  topic: TOPIC,
  replayId: REPLAY_ID
});
client.on('reconnect', this.onReconnectHandler);
stream.on('connect', this.onConnectHandler);
stream.on('error', this.onErrorHandler);
stream.on('data', this.onDataHandler);

Note this line client.on('reconnect', this.onReconnectHandler); where I try to reconnect back to topic.

Hope this helps until Kevin updates nforce.

@kevinohara80
Copy link
Owner

kevinohara80 commented Feb 7, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants