function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
osf_teamosf_team 

Streaming API - Channel Getting Disconnected after certain interval

Hi Everyone,

I am using the code sample provided Java client for Streaming API in the below link
http://www.salesforce.com/developer/docs/api_streaming/Content/code_sample_java_add_source.htm

I am not able to understand why the channel is getting disconnected after sometime. Is there a way to keep the channel alive? I have a requirement where i dont want to miss out on any of the events in salesforce. And disconnection will certainly lead to data loss.

Below are the logs that appear whenever channel is getting disconnected.

[CHANNEL:META_CONNECT]: {"id":"133048","successful":true,"channel":"/meta/connect","clientId":"1zro8qr2rfbesar24zjqa3okgvv"}
[CHANNEL:META_DISCONNECT]: {"successful":true,"channel":"/meta/disconnect","clientId":"1zro8qr2rfbesar24zjqa3okgvv"}
[CHANNEL:META_CONNECT]: {"id":"133049","successful":true,"channel":"/meta/connect","clientId":"1zro8qr2rfbesar24zjqa3okgvv"}
[CHANNEL:META_CONNECT]: {"id":"133050","error":"403::Unknown client","successful":false,"advice":{"interval":500,"reconnect":"handshake"},"channel":"/meta/connect","clientId":"1zro8qr2rfbesar24zjqa3okgvv"}
Error during CONNECT: 403::Unknown client
Exiting...

An early response on this would be highly appreciated.

Thanks,
Shalindra
Gaurav NirwalGaurav Nirwal
Streaming API doesn’t guarantee durability and reliable delivery of notifications. Streaming servers don’t maintain any client state and don’t keep track of what’s delivered. The client may not receive messages for a variety of reasons, including:

When a client first subscribes or reconnects, it doesn’t receive messages that were processed while it wasn’t subscribed to the channel.
If a client disconnects and starts a new handshake, it may be working with a different application server, so it receives only new messages from that point on.
Some events may be dropped if the system is being heavily used.
If an application server is stopped, all the messages being processed but not yet sent are lost.
osf_teamosf_team
Thanks Mathews,

Non Reluability in Message delivery is known from Salesforce documentation. But once I have subscribed to event (push topic) and my server is up and running, then also channel is getting discunnected automatcally after certain interval. which require me to again subscribe to same push topic (such behaviour is not documentd in Salesforce documentation). In my opinion this should not be the case. Once I have subscribed to event (push topic) it should continue to listen to that event unless server is down or i unsubscribe it.
Or am I missing some configuration related to channel disconnection?

Thanks
Shalndra Singh
MuratMurat
Hi Shalndra,

Here is a piece of information that may help you out, first; check the link below, which basically saying disconnection may happen from time to time based on bunch of various factors which when this happens, recommending start all over again;

http://www.salesforce.com/developer/docs/api_streaming/Content/DebuggingStreamingAPIApplications.htm

Second; another piece of information that may be useful to you is that in Version 28.0 API document (Summer '13), they state as below (which is not placed in later docs);
Maximum CometD session lifetime: 2 hours
A client subscription is valid for a maximum of 2 hours, irrespective of activity on the connection. Therefore the client must handshake, subscribe, and connect before the session is timed out on the server side. A new subscription creates a new server session: the server timeout clock restarts again.


This may be your case.. There are a lot of factors that may contribute to disconnection. Since the server actually looks for some sort of 'activity', I suggest do a "handshake" with a timer/thread so that you have constant activity on server which restarts your session clock again. Even in this case, you may get disconnections which then you need to start all over again.

Hope this helps.
zgcharley_09zgcharley_09
Any new updates with latest Salesforce Streaming API? How long Salesforce will disconnect clients? Any documentation?
Vaclav CarnogurskyVaclav Carnogursky
I am experiencing disconnects every 3 hours with a connect message response:
{advice={reconnect=handshake, interval=0}, channel=/meta/connect, id=109, error=403::Unknown client, successful=false}
Cometd client handles re-handshake well, I just neeed to re-subscribe. It works but I don't see any documentation on the 3 hours limit. Neither on Salesforce nor Cometd sites. @Murat mentioned "Maximum CometD session lifetime" but there is no reference to it anymore. Any idea how this can be configured?

Another real problem is that sometimes after a successful re-handshake I get a connect response:
{clientId=3l3b3idqno9c6dl1ur3j270flmt8, advice={reconnect=none, interval=0}, channel=/meta/connect, id=215, error=403::Unknown client, successful=false}
I am confused by advice={reconnect=none, interval=0}. The Cometd Java client handles it by putting the client into DISCONNECTED state.
It is a server way to tell its clients to disconnect? E.g. beacuse it is shutting down?