Class KafkaBundle<C extends io.dropwizard.core.Configuration>

java.lang.Object
org.sdase.commons.server.kafka.KafkaBundle<C>
All Implemented Interfaces:
io.dropwizard.core.ConfiguredBundle<C>

public class KafkaBundle<C extends io.dropwizard.core.Configuration> extends Object implements io.dropwizard.core.ConfiguredBundle<C>
  • Field Details

  • Method Details

    • builder

      public static KafkaBundle.InitialBuilder builder()
    • initialize

      public void initialize(io.dropwizard.core.setup.Bootstrap<?> bootstrap)
      Specified by:
      initialize in interface io.dropwizard.core.ConfiguredBundle<C extends io.dropwizard.core.Configuration>
    • run

      public void run(C configuration, io.dropwizard.core.setup.Environment environment)
      Specified by:
      run in interface io.dropwizard.core.ConfiguredBundle<C extends io.dropwizard.core.Configuration>
    • getTopicConfiguration

      public TopicConfig getTopicConfiguration(String key) throws ConfigurationException
      Provides a TopicConfig that is generated from the values within the configuration yaml
      Parameters:
      key - the name of the topic configuration
      Returns:
      the configured topic configuration
      Throws:
      ConfigurationException - if no such topic exists in the configuration
    • createMessageListener

      public <K, V> List<MessageListener<K,V>> createMessageListener(MessageListenerRegistration<K,V> registration)
      Creates a number of message listeners with the parameters given in the MessageListenerRegistration.
      Type Parameters:
      K - the key object type
      V - the value object type
      Parameters:
      registration - the registration configuration
      Returns:
      the newly registered message listeners
    • registerProducer

      public <K, V> MessageProducer<K,V> registerProducer(ProducerRegistration<K,V> registration) throws ConfigurationException
      creates a @MessageProducer based on the data in the ProducerRegistration

      if the kafka bundle is disabled, null is returned

      Type Parameters:
      K - key clazz type
      V - value clazz type
      Parameters:
      registration - the configuration object
      Returns:
      message producer
      Throws:
      ConfigurationException - if the registration has no ProducerRegistration.getProducerConfig() and there is no configuration available with the same name as defined in ProducerRegistration.getProducerConfigName()
    • createConsumer

      public <K, V> org.apache.kafka.clients.consumer.KafkaConsumer<K,V> createConsumer(org.apache.kafka.common.serialization.Deserializer<K> keyDeSerializer, org.apache.kafka.common.serialization.Deserializer<V> valueDeSerializer, String consumerConfigName)
      creates a new Kafka Consumer with deserializers and consumer config

      Note: after creating a KafkaConsumer you must always KafkaConsumer.close() it to avoid resource leaks.

      Type Parameters:
      K - Key object type
      V - Value object type
      Parameters:
      keyDeSerializer - deserializer for key objects. If null, value from config or default StringDeserializer will be used
      valueDeSerializer - deserializer for value objects. If null, value from config or * default * StringDeserializer * will be used
      consumerConfigName - name of a valid consumer config
      Returns:
      a new kafka consumer
    • createConsumer

      public <K, V> org.apache.kafka.clients.consumer.KafkaConsumer<K,V> createConsumer(org.apache.kafka.common.serialization.Deserializer<K> keyDeSerializer, org.apache.kafka.common.serialization.Deserializer<V> valueDeSerializer, ConsumerConfig consumerConfig, int instanceId)
      creates a new Kafka Consumer with deserializers and consumer config

      Note: after creating a KafkaConsumer you must always KafkaConsumer.close() it to avoid resource leaks.

      Type Parameters:
      K - Key object type
      V - Value object type
      Parameters:
      keyDeSerializer - deserializer for key objects. If null, value from config or default StringDeserializer will be used
      valueDeSerializer - deserializer for value objects. If null, value from config or * default * StringDeserializer * will be used
      consumerConfig - config of the consumer. If null a consumer with default config values is created.
      instanceId - the id of the consumer that is appended to the client ID
      Returns:
      a new kafka consumer
    • createProducer

      public <K, V> org.apache.kafka.clients.producer.Producer<K,V> createProducer(org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer, ProducerConfig producerConfig)
      Creates a new Kafka Producer with serializers and producer config

      Note: after creating a Kafka Producer you must always Producer.close() it to avoid resource leaks.

      Type Parameters:
      K - Key object type
      V - Value object type
      Parameters:
      keySerializer - deserializer for key objects. If null, value from config or default StringSerializer will be used
      valueSerializer - deserializer for value objects. If null, value from config or * default * StringSerializer * will be used
      producerConfig - config of the producer
      Returns:
      a new kafka producer
    • createProducer

      public <K, V> org.apache.kafka.clients.producer.Producer<K,V> createProducer(org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer, String producerConfigName)
      Creates a new Kafka Producer with serializers and producer config

      Note: after creating a Kafka Producer you must always Producer.close() it to avoid resource leaks.

      Type Parameters:
      K - Key object type
      V - Value object type
      Parameters:
      keySerializer - deserializer for key objects. If null, value from config or default StringSerializer will be used
      valueSerializer - deserializer for value objects. If null, value from config or efault StringSerializer will be used
      producerConfigName - name of the producer config to be used
      Returns:
      a new kafka producer
    • getConsumerConfiguration

      public ConsumerConfig getConsumerConfiguration(String name)
      returns a @ConsumerConfig as defined in the configuration
      Parameters:
      name - name of the consumer in the configuration
      Returns:
      Consumer Configuration
      Throws:
      ConfigurationException - when the configuration does not exist
    • getProducerConfiguration

      public ProducerConfig getProducerConfiguration(String name)
      returns a @ProducerConfig as defined in the configuration
      Parameters:
      name - name of the producer in the configuration
      Returns:
      Producer Configuration
      Throws:
      ConfigurationException - when the configuration does not exist