stream - Creating an Apache Storm spout which emits tuples every X seconds -


I have a topology that is receiving data from the MQTT broker, and I have a spout to behave like this I want to:

  1. Amit a batch of Tuple (or a list of strings in a single tube) in every x seconds How will I achieve this? I read a bit about Storm Trident but its IBatchSpout does not allow me to emit Tuple in a batch with a specific time interval.

  2. What should be spout if no new data is coming? This thread can not stop because it's the main thread of the storm, okay?

You can apply your own MCT Spout Example For this, take a look at this.

The important part is the method.

When this method is called, then the storm is requesting that the collector of the scout output. This method should be non-blocked, so if there is no excitation in the spawn to exempt tuples, then this method should be returned. Next Toul, AK, and False All are called in Touch in a single thread. When there are no tuples to throw, then for a short time, be humble for the next sleep (like a millisecond) so that do not waste too much CPU.

You should not wait for a specified time at one time, but you can implement nextTuple so that it can only be emitted by a single tup at one time. Could.

  Private static last EMISSION_PERIOD = 2000; // 2 second private long last commission; @ Override Public Zero Next Tuple () (if (Last End == Zero) Last Entry + EMISSIPIIDA = System Syrent Mileis () & lt; Object & gt; Tupal = Polymetti (); If (tubal! = Null) {this.collector.emit (tubal); Return; }} Util. Sleep (50); }  

Note that I have found an open source, this product does not appear ready, but you can use it as its starting point.


Comments