How to integrate Storm with Kafka
_ spoutConfig.stateUpdateIntervalMs) {commit ();}} @ Override public void ack (Object msgId) {KafkaMessageId id = (KafkaMessageId) msgId; PartitionManager m = _ coordinator.getManager (id.partition); if (m! = null) {m.ack (id.offset) } @ Override public void fail (Object msgId) {KafkaMessageId id = (KafkaMessageId) msgId; PartitionManager m = _ coordinator.getManager (id.partition); if (m! = null) {m.fail (id.offset) } @ Override public void deactivate () {/ / stop working commit ();} @ Override public void declareOutputFields (OutputFieldsDeclarer declarer) {System.out.println (_ spoutConfig.scheme.getOutputFields ()); declarer.declare (_ spoutConfig.scheme.getOutputFields ()) } private void commit () {_ lastUpdateMs = System.currentTimeMillis (); for (PartitionManager manager: _ coordinator.getMyManagedPartitions ()) {manager.commit ();}
After reading the shallow code, analyze it in detail here:
1 KafkaSpout holds an inner class of MessageAndRealOffset
Public static class MessageAndRealOffset {public Message msg; public long offset; public MessageAndRealOffset (Message msg,long offset) {this.msg = msg; this.offset = offset;}}
2 in Spout we also hold a PartitionCoordinator partition coordinator, which we instantiate by default
It's ZKCoordinator.
On how to integrate Storm and Kafka to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.