Skip to content

Instantly share code, notes, and snippets.

@seregasheypak
Created December 27, 2015 16:04
Show Gist options
  • Save seregasheypak/0adc0fd79e7784483c50 to your computer and use it in GitHub Desktop.
Save seregasheypak/0adc0fd79e7784483c50 to your computer and use it in GitHub Desktop.
// A builder with single spout and bolt. Spout could emit tuples using two streams:
// user event with fieldGouping with streamId UserEvent.class.getSimpleName()
// game event with streamId GameEvent.class.getSimpleName()
builder.setSpout(GenericEventSpout.class.getSimpleName(), new GenericEventSpout(), 2)
builder.setBolt(UserContextBolt.class.getSimpleName(), new UserContextBolt(), 2)
.addConfigurations(env)
.fieldsGrouping(GenericEventSpout.class.getSimpleName(), UserEvent.class.getSimpleName(), new Fields(Const.userId.name()))
.allGrouping(GenericEventSpout.class.getSimpleName(), GameEvent.class.getSimpleName());
// Here are stream declarations in Spout:
@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declareStream(UserEvent.simpleName, new Fields(Const.userId.name(), UserEvent.simpleName))
declarer.declareStream(GameEvent.simpleName, new Fields(GameEvent.simpleName))
}
// Here is Bolt:
// I see my tuples, it's ok, but all Tupl metadata fields are null
@Override
public void execute(Tuple input) {
LOG.info("input: $input | ${input.messageId}|${input.sourceComponent} ${input.sourceGlobalStreamid} ${input.sourceStreamId} ${input.sourceTask} ")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment