Class KafkaBundle<C extends io.dropwizard.Configuration>

  • All Implemented Interfaces:
    io.dropwizard.ConfiguredBundle<C>

    public class KafkaBundle<C extends io.dropwizard.Configuration>
    extends java.lang.Object
    implements io.dropwizard.ConfiguredBundle<C>
    • Field Detail

      • HEALTHCHECK_NAME

        public static final java.lang.String HEALTHCHECK_NAME
        See Also:
        Constant Field Values
      • EXTERNAL_HEALTHCHECK_NAME

        public static final java.lang.String EXTERNAL_HEALTHCHECK_NAME
        See Also:
        Constant Field Values
    • Method Detail

      • initialize

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

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

        public TopicConfig getTopicConfiguration​(java.lang.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> java.util.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
      • 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,
                                                                                                     java.lang.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,
                                                                                                java.lang.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​(java.lang.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​(java.lang.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