Record Class ConsumerBuilder

java.lang.Object
java.lang.Record
com.bakdata.kafka.consumer.ConsumerBuilder

public record ConsumerBuilder(@NonNull ConsumerTopicConfig topics, @NonNull Map<String,Object> kafkaProperties, @NonNull ConsumerExecutionOptions executionOptions) extends Record
Provides all runtime configurations when running a ConsumerApp
See Also:
  • Constructor Details

    • ConsumerBuilder

      public ConsumerBuilder(@NonNull @NonNull ConsumerTopicConfig topics, @NonNull @NonNull Map<String,Object> kafkaProperties, @NonNull @NonNull ConsumerExecutionOptions executionOptions)
      Creates an instance of a ConsumerBuilder record class.
      Parameters:
      topics - the value for the topics record component
      kafkaProperties - the value for the kafkaProperties record component
      executionOptions - the value for the executionOptions record component
  • Method Details

    • createConsumer

      public <K, V> org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer()
      Create a new Consumer using kafkaProperties
      Type Parameters:
      K - type of keys
      V - type of values
      Returns:
      Consumer
      See Also:
      • KafkaConsumer(Map)
    • createConsumer

      public <K, V> org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer, org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer)
      Create a new Consumer using kafkaProperties and provided Deserializers
      Type Parameters:
      K - type of keys
      V - type of values
      Parameters:
      keyDeserializer - Deserializer to use for keys
      valueDeserializer - Deserializer to use for values
      Returns:
      Consumer
      See Also:
      • KafkaConsumer(Map, Deserializer, Deserializer)
    • createConfigurator

      public com.bakdata.kafka.Configurator createConfigurator()
      Create Configurator to configure Serde and Deserializer using kafkaProperties.
      Returns:
      Configurator
    • createConfiguration

      public AppConfiguration<ConsumerTopicConfig> createConfiguration()
      Create AppConfiguration used by this app
      Returns:
      AppConfiguration
    • subscribeToAllTopics

      public <K, V> void subscribeToAllTopics(org.apache.kafka.clients.consumer.Consumer<K,V> consumer)
      Subscribes the given Consumer to all input topics and patterns configured in topics. This includes all topics from getInputTopics(), getLabeledInputTopics(), getInputPattern(), and getLabeledInputPatterns().
      Type Parameters:
      K - type of keys
      V - type of values
      Parameters:
      consumer - Consumer instance to subscribe
    • createDefaultConsumerRunnable

      public <K, V> DefaultConsumerRunnable<K,V> createDefaultConsumerRunnable(org.apache.kafka.clients.consumer.Consumer<K,V> consumer, Consumer<org.apache.kafka.clients.consumer.ConsumerRecords<K,V>> recordProcessor)
      Creates a DefaultConsumerRunnable using the provided consumer, processor, and ConsumerExecutionOptions.
      Type Parameters:
      K - type of keys
      V - type of values
      Parameters:
      consumer - Consumer to be used by the runnable
      recordProcessor - Consumer to process ConsumerRecords
      Returns:
      A new DefaultConsumerRunnable instance
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • topics

      @NonNull public @NonNull ConsumerTopicConfig topics()
      Returns the value of the topics record component.
      Returns:
      the value of the topics record component
    • kafkaProperties

      @NonNull public @NonNull Map<String,Object> kafkaProperties()
      Returns the value of the kafkaProperties record component.
      Returns:
      the value of the kafkaProperties record component
    • executionOptions

      @NonNull public @NonNull ConsumerExecutionOptions executionOptions()
      Returns the value of the executionOptions record component.
      Returns:
      the value of the executionOptions record component