How to call a particular method before killing a s

2020-02-12 06:50发布

问题:

How to call a particular method before killing a storm topology.

I have created a topology in storm, I wanted to call particular method, just before topology gets killed.

is there any predefined overridden or any method available to do this in storm framework.

Thanks in advance:)

回答1:

There is no such thing...

As a workaround, you can deactivate the topology before killing it. This ensures, that Spout.deactivate() is called.

If you need to call a method at bolts, use Spout.deactivate() to sent a "notification tuple" (that does not contain data to be processed) through the whole topology. And in each bolt, call your special method if a "notification tuple" is received.

Furthermore, this "notification tuple" must be forwarded by the bolt to all its predecessors. You need to make sure, that the "notification tuples" is sent to all parallel executors of each bolt. For this, use a dedicated "notification stream" and subscribe each bolt via allGrouping() to this steam (in addition to the regular input streams). Within each bolt, you need to check if the tuple is a notification tuple or not (for example via Tuple.getSourceStreamId())

After clean up is finished, you can kill the topology finally.