问题
I am currently working with apache spark streaming. I want to know how to detect whether the connection has lost or not with the external data source, so that we may stop streaming and restart connecting to data source.
Thanks in advance for any help
回答1:
Add a listener to the receiver you have and stop the streaming context when the receiver has stopped.
example:
streamContext.addStreamingListener(new StreamingListener() {
@Override
public void onReceiverStopped(StreamingListenerReceiverStopped arg0) {
streamContext.stop(true, true);
}
}
来源:https://stackoverflow.com/questions/27272141/detecting-connection-lost-in-spark-streaming