I have a scenario where I am posting json to a Kafka instance. I am then using a Kafka Spout to emit the stream to a bolt.
But now I would like to add additional field (call it x
) to my json message. If x
is a
I would like it to be consumed by boltA, if x
is b
I would like it to be consumed by boltB.
Is there a way to direct the stream to the proper bolt depending on the streams contents?
The simplest way should be to add a
SplitBolt
that consumes fromKafkaSpout
, evaluates the fieldx
, and forwards to different output streams:When building your Topology, you connect
BoltA
to "stream-xa" andBoltB
to "stream-xb":As an alternative, it should also be possible, to inherit from
KafkaSpout
and emit to two different streams directly. However, the code is more tricky to get right.