Package com.networknt.kafka.producer
Class SidecarProducer
- java.lang.Object
-
- com.networknt.kafka.producer.SidecarProducer
-
- All Implemented Interfaces:
LightProducer,NativeLightProducer
public class SidecarProducer extends Object implements NativeLightProducer
This is the guaranteed producer to ensure that the message is acknowledged from the Kafka brokers before the service is respond to the consumer call. Although this producer is not the best one for high throughput batch producing, it is the safest one. Once the caller receives the successful response from the service, it can make sure that the message is on the Kafka cluster.- Author:
- Steve Hu
-
-
Field Summary
Fields Modifier and Type Field Description static KafkaProducerConfigconfigorg.apache.kafka.clients.producer.Producer<byte[],byte[]>producer
-
Constructor Summary
Constructors Constructor Description SidecarProducer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This method is called by a shutdown hook to close the producer if it is not null.org.apache.kafka.clients.producer.ProducergetProducer()Return the Kafka Producer instance so that it can be used to produce message to a Kafka topic.voidopen()This method is used to create an instance of producer in a startup hook for most of the producers.
-
-
-
Field Detail
-
config
public static final KafkaProducerConfig config
-
producer
public org.apache.kafka.clients.producer.Producer<byte[],byte[]> producer
-
-
Method Detail
-
open
public void open()
Description copied from interface:LightProducerThis method is used to create an instance of producer in a startup hook for most of the producers. Queued producer will start a background thread to process the queued message in batch and this method can be used to start the thread in a startup hook.- Specified by:
openin interfaceLightProducer
-
getProducer
public org.apache.kafka.clients.producer.Producer getProducer()
Description copied from interface:NativeLightProducerReturn the Kafka Producer instance so that it can be used to produce message to a Kafka topic. Instead of using a queue like QueuedLightProducer to hide the producer from the user, this interface will provide the native producer to work with.- Specified by:
getProducerin interfaceNativeLightProducer- Returns:
- Kafka producer instance
-
close
public void close()
Description copied from interface:LightProducerThis method is called by a shutdown hook to close the producer if it is not null.- Specified by:
closein interfaceLightProducer
-
-