简体   繁体   中英

How to shutdown spout in Apache Storm while giving bolts time to finish?

I have a Storm topology which reads from a remote server and then processes the text in its bolts.

I want to deactivate/shutdown the spout when it detects that there is no data left to read while leaving the bolts time to finish their processing.

I tried using the deactivate() method in the spout by calling it when detects there is no data left to read. I could not figure out how to make it work (couldn't find much documentation about it).

I decided to go with calling the method I wrote bellow in the spout when I detected there was no data left to read. I used KillOptions when shutting down the topology to specify some wait time, but it continues to kill it as soon as the method is called without waiting.

private void endReading() {
    Map conf = Utils.readStormConfig();
    conf.put("nimbus.seeds", "localhost");
    NimbusClient cc = NimbusClient.getConfiguredClient(conf);
    Nimbus.Client client = cc.getClient();
    try {
         KillOptions ko = new KillOptions();
         ko.set_wait_secs(600);
         ko.set_wait_secs_isSet(true);
         client.killTopologyWithOpts("local-topology", ko); 
    } catch (TException e) {
        e.printStackTrace();
    }
}

Am I using KillOptions incorrectly? Is there a simpler way to shutdown the spout while giving time for the bolts to finish? Any advice would be appreciated.

EDIT: I am running this locally, which is the reason why it was not working, as explained in a follow-up to the answer.

What you are doing is a good solution. The code you posted will shut down the entire topology when you run it. Keep in mind that it will shut down both the spout calling it, and any other spout in the same topology.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM