August 2017
Beginner to intermediate
284 pages
6h 51m
English
If none of the preceding groupings fit your use case, you can define your own custom grouping by implementing the backtype.storm.grouping.CustomStreamGrouping interface.
Here is a sample custom grouping that partitions the stream on the basis of the category in the tuples:
public class CategoryGrouping implements CustomStreamGrouping, Serializable { private static final Map<String, Integer> categories = ImmutableMap.of ( "Financial", 0, "Medical", 1, "FMCG", 2, "Electronics", 3 ); private int tasks = 0; public void prepare(WorkerTopologyContext context, GlobalStreamId stream, List<Integer> targetTasks) { tasks = targetTasks.size(); } public List<Integer> chooseTasks(int taskId, List<Object> values) { String category = (String) ...Read now
Unlock full access