Class 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 arguments EnvironmentArgumentsParser. To implement your producer application inherit from this class and add your custom options. Call startApplication(KafkaProducerApplication, String[]) with a fresh instance of your class from your main.
    • Constructor Detail

      • KafkaProducerApplication

        public KafkaProducerApplication()
    • 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:
        createKafkaProperties in class KafkaApplication
        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:
        runCleanUp in class KafkaApplication