August 2017
Beginner to intermediate
284 pages
6h 51m
English
If none of the preceding repartitioning fits your use case, you can define your own custom repartition function by implementing the org.apche.storm.grouping.CustomStreamGrouping interface.
Here is a sample custom repartition that partitions the stream on the basis of the value of the country field:
public class CountryRepartition implements CustomStreamGrouping, Serializable { private static final long serialVersionUID = 1L; private static final Map<String, Integer> countries = ImmutableMap.of ( "India", 0, "Japan", 1, "United State", 2, "China", 3, "Brazil", 4 ); private int tasks = 0; public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) { tasks = targetTasks.size(); ...Read now
Unlock full access