You need to sign in to do that
Don't have an account?

Salesforce Streaming API
Hi everyone,
This question is for anyone that has implemented the Salesforce streaming client in Java. I am looking to find sugestions on the proper way to implement reconnect logic for the Java client. The code that is provided by Salesforce (in the StreamingClientExample.java class) has several listener methods that get events which tell the client whether or not a message was successful. In this code, if there is a failure, the client simply exits and I need logic that will attempt to reconnect the client x number of times.
>>> CODE PROVIDED BY SALESFORCE
client.getChannel(Channel.META_CONNECT).addListener(
new ClientSessionChannel.MessageListener() {
public void onMessage(ClientSessionChannel channel, Message message) {
System.out.println("[CHANNEL:META_CONNECT]: " + message);
boolean success = message.isSuccessful();
if (!success) {
String error = (String) message.get("error");
if (error != null) {
System.out.println("Error during CONNECT: " + error);
System.out.println("Exiting...");
System.exit(1);
}
}
}
});
I am considering putting the reconnect CALL in this method, like in the sample below, and I am wondering if anyone has done this and has come accross any issues with doing it this way. In particular, the kind of issues I am trying to avoid are inefficient loops where the client keeps trying to connect and fails, any threading issues, etc.
>>>> PROPOSED RECONNECT CALL:
public void addConnectListener(BayeuxClient client) {
client.getChannel(Channel.META_CONNECT).addListener(
new ClientSessionChannel.MessageListener() {
public void onMessage(ClientSessionChannel channel,
Message message) {
logger.info("[CHANNEL:META_CONNECT]: " + message);
boolean success = message.isSuccessful();
if (!success) {
String error = (String) message.get("error");
if (error != null) {
logger.error("Error during CONNECT: " + error);
exception = true;
try {
reconnect(message);
} catch (FatalStreamingErrorException e) {
throw new RuntimeException(e.getMessage());
}
}
}
}
});
}
Thanks in advance!
I am also looking into the same.