public class KafkaBolt<K,V> extends BaseTickTupleAwareRichBolt
Bolt implementation that can send Tuple data to Kafka.
Most configuration for this bolt should be through the various setter methods in the bolt. For backwards compatibility it supports the producer configuration and topic to be placed in the storm config under ‘kafka.broker.properties’ and ‘topic’ respectively.| Constructor and Description |
|---|
KafkaBolt() |
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup() |
void |
declareOutputFields(OutputFieldsDeclarer declarer) |
protected org.apache.kafka.clients.producer.KafkaProducer<K,V> |
mkProducer(Properties props)
Intended to be overridden for tests.
|
void |
prepare(Map stormConf,
TopologyContext context,
OutputCollector collector) |
protected void |
process(Tuple input) |
void |
setAsync(boolean async)
If set to true(the default) the bolt will not wait for the message to be fully sent to Kafka before getting another tuple to send.
|
void |
setFireAndForget(boolean fireAndForget)
If set to true the bolt will assume that sending a message to kafka will succeed and will ack the tuple as soon as it has handed the message off to the producer API if false (the default) the message will be acked after it was successfully sent to kafka or failed if it was not successfully sent.
|
String |
toString() |
KafkaBolt<K,V> |
withProducerProperties(Properties producerProperties) |
KafkaBolt<K,V> |
withTopicSelector(KafkaTopicSelector selector) |
KafkaBolt<K,V> |
withTopicSelector(String topic)
Set the messages to be published to a single topic
|
KafkaBolt<K,V> |
withTupleToKafkaMapper(TupleToKafkaMapper<K,V> mapper) |
execute, onTickTuplegetComponentConfigurationclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetComponentConfigurationpublic static final String TOPIC
public KafkaBolt<K,V> withTopicSelector(String topic)
Set the messages to be published to a single topic
topic - the topic to publish topublic KafkaBolt<K,V> withTopicSelector(KafkaTopicSelector selector)
public KafkaBolt<K,V> withProducerProperties(Properties producerProperties)
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector)
protected org.apache.kafka.clients.producer.KafkaProducer<K,V> mkProducer(Properties props)
Intended to be overridden for tests. Make the producer with the given props
protected void process(Tuple input)
process in class BaseTickTupleAwareRichBoltpublic void declareOutputFields(OutputFieldsDeclarer declarer)
public void cleanup()
cleanup in interface IBoltcleanup in class BaseRichBoltpublic void setFireAndForget(boolean fireAndForget)
If set to true the bolt will assume that sending a message to kafka will succeed and will ack the tuple as soon as it has handed the message off to the producer API if false (the default) the message will be acked after it was successfully sent to kafka or failed if it was not successfully sent.
fireAndForget - public void setAsync(boolean async)
If set to true(the default) the bolt will not wait for the message to be fully sent to Kafka before getting another tuple to send.
async - true to have multiple tuples in flight to kafka, else false.Copyright © 2018 The Apache Software Foundation. All Rights Reserved.