Ingesting data from Kafka to Storm
Apache Storm is a real-time, distributed stream-processing system. Storm simplifies real-time data processing, Kafka can work as the source for this data streaming.
Getting ready
Have a Kafka cluster up and running. To install Apache Storm follow the instructions on this page: http://storm.apache.org/downloads.html.
How to do it...
Storm has a built-in KafkaSpout to easily ingest data from Kafka to the Storm topology:
- The first step is to create the
ZkHostsobject with the ZooKeeper address inhost:portformat:
BrokerHosts hosts = new ZkHosts("127.0.0.1:2181"); - Next, create the
SpoutConfigobject that contains the parameters needed forKafkaSpout:
SpoutConfig kafkaConf = new SpoutConfig(hosts,"source-topic", "/brokers", "kafkaStormTest");
- Then, declare the scheme for the
KafkaSpoutconfig:
kafkaConf.scheme = new SchemeAsMultiScheme(new StringScheme());
- Using this scheme, create a
KafkaSpoutobject:
KafkaSpout kafkaSpout = new KafkaSpout(kafkaConf);
- Build that topology...