Package com.bakdata.kafka
Class KafkaProducerApplication
- java.lang.Object
-
- com.bakdata.kafka.KafkaApplication
-
- com.bakdata.kafka.KafkaProducerApplication
-
- All Implemented Interfaces:
java.lang.Runnable
public abstract class KafkaProducerApplication extends KafkaApplication
The base class of the entry point of a producer application.
This class provides common configuration options, e.g.,KafkaApplication.brokers, for producer applications. Hereby it automatically populates the passed in command line arguments with matching environment argumentsEnvironmentArgumentsParser. To implement your producer application inherit from this class and add your custom options. CallstartApplication(KafkaProducerApplication, String[])with a fresh instance of your class from your main.
-
-
Field Summary
-
Fields inherited from class com.bakdata.kafka.KafkaApplication
ADMIN_TIMEOUT, brokers, cleanUp, debug, extraOutputTopics, outputTopic, RESET_SLEEP_MS
-
-
Constructor Summary
Constructors Constructor Description KafkaProducerApplication()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcleanUpRun(SchemaTopicClient schemaTopicClient)protected java.util.PropertiescreateKafkaProperties()This method should give a default configuration to run your producer application with.protected <K,V>
org.apache.kafka.clients.producer.KafkaProducer<K,V>createProducer()voidrun()protected abstract voidrunApplication()protected voidrunCleanUp()This methods deletes all output topics.protected static voidstartApplication(KafkaProducerApplication app, java.lang.String[] args)This methods needs to be called in the executable custom application class inheriting fromKafkaProducerApplication.java.lang.StringtoString()-
Methods inherited from class com.bakdata.kafka.KafkaApplication
createAdminClient, getBrokers, getExtraOutputTopics, getKafkaProperties, getOutputTopic, getOutputTopic, getSchemaRegistryUrl, getStreamsConfig, isCleanUp, isDebug, isHelpRequested, setBrokers, setCleanUp, setDebug, setExtraOutputTopics, setHelpRequested, setOutputTopic, setSchemaRegistryUrl, setStreamsConfig
-
-
-
-
Method Detail
-
startApplication
protected static void startApplication(KafkaProducerApplication app, java.lang.String[] args)
This methods needs to be called in the executable custom application class inheriting from
KafkaProducerApplication.- Parameters:
app- An instance of the custom application class.args- Arguments passed in by the custom application class.
-
run
public void run()
-
runApplication
protected abstract void runApplication()
-
createKafkaProperties
protected java.util.Properties createKafkaProperties()
This method should give a default configuration to run your producer application with.
To add a custom configuration please add a similar method to your custom application class:protected Properties createKafkaProperties() { # Try to always use the kafka properties from the super class as base Map Properties kafkaConfig = super.createKafkaProperties(); kafkaConfig.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, GenericAvroSerializer.class); kafkaConfig.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, GenericAvroSerializer.class); return kafkaConfig; }- Specified by:
createKafkaPropertiesin classKafkaApplication- Returns:
- Returns a default Kafka configuration
Properties
-
createProducer
protected <K,V> org.apache.kafka.clients.producer.KafkaProducer<K,V> createProducer()
-
runCleanUp
protected void runCleanUp()
This methods deletes all output topics.- Specified by:
runCleanUpin classKafkaApplication
-
cleanUpRun
protected void cleanUpRun(SchemaTopicClient schemaTopicClient)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classKafkaApplication
-
-