Interface ConsumerFactory<K,V>

Type Parameters:
K - the key type.
V - the value type.
All Known Implementing Classes:
DefaultKafkaConsumerFactory, MockConsumerFactory

public interface ConsumerFactory<K,V>
The strategy to produce a Consumer instance.
Author:
Gary Russell, Artem Bilan
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Called whenever a consumer is added or removed.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    addListener(int index, ConsumerFactory.Listener<K,V> listener)
    Add a listener at a specific index.
    default void
    Add a listener.
    default void
    Add a post processor.
    default org.apache.kafka.clients.consumer.Consumer<K,V>
    Create a consumer with the group id and client id as configured in the properties.
    default org.apache.kafka.clients.consumer.Consumer<K,V>
    createConsumer(String clientIdSuffix)
    Create a consumer, appending the suffix to the client.id property, if present.
    default org.apache.kafka.clients.consumer.Consumer<K,V>
    createConsumer(String groupId, String clientIdSuffix)
    Create a consumer with an explicit group id; in addition, the client id suffix is appended to the client.id property, if both are present.
    default org.apache.kafka.clients.consumer.Consumer<K,V>
    createConsumer(String groupId, String clientIdPrefix, String clientIdSuffix)
    Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides the client.id property, if present.
    org.apache.kafka.clients.consumer.Consumer<K,V>
    createConsumer(String groupId, String clientIdPrefix, String clientIdSuffix, Properties properties)
    Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides the client.id property, if present.
    default Map<String,Object>
    Return an unmodifiable reference to the configuration map for this factory.
    default org.apache.kafka.common.serialization.Deserializer<K>
    Return the configured key deserializer (if provided as an object instead of a class name in the properties).
    Get the current list of listeners.
    Get the current list of post processors.
    default org.apache.kafka.common.serialization.Deserializer<V>
    Return the configured value deserializer (if provided as an object instead of a class name in the properties).
    boolean
    Return true if consumers created by this factory use auto commit.
    default void
    removeConfig(String configKey)
    Remove the specified key from the configuration map.
    default boolean
    Remove a listener.
    default boolean
    Remove a post processor.
    default void
    Update the consumer configuration map; useful for situations such as credential rotation.
  • Method Details

    • createConsumer

      default org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer()
      Create a consumer with the group id and client id as configured in the properties.
      Returns:
      the consumer.
    • createConsumer

      default org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable String clientIdSuffix)
      Create a consumer, appending the suffix to the client.id property, if present.
      Parameters:
      clientIdSuffix - the suffix.
      Returns:
      the consumer.
      Since:
      1.3
    • createConsumer

      default org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable String groupId, @Nullable String clientIdSuffix)
      Create a consumer with an explicit group id; in addition, the client id suffix is appended to the client.id property, if both are present.
      Parameters:
      groupId - the group id.
      clientIdSuffix - the suffix.
      Returns:
      the consumer.
      Since:
      1.3
    • createConsumer

      default org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable String groupId, @Nullable String clientIdPrefix, @Nullable String clientIdSuffix)
      Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides the client.id property, if present.
      Parameters:
      groupId - the group id.
      clientIdPrefix - the prefix.
      clientIdSuffix - the suffix.
      Returns:
      the consumer.
      Since:
      2.1.1
    • createConsumer

      org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable String groupId, @Nullable String clientIdPrefix, @Nullable String clientIdSuffix, @Nullable Properties properties)
      Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides the client.id property, if present. In addition, consumer properties can be overridden if the factory implementation supports it.
      Parameters:
      groupId - the group id.
      clientIdPrefix - the prefix.
      clientIdSuffix - the suffix.
      properties - the properties to override.
      Returns:
      the consumer.
      Since:
      2.2.4
    • isAutoCommit

      boolean isAutoCommit()
      Return true if consumers created by this factory use auto commit.
      Returns:
      true if auto commit.
    • getConfigurationProperties

      default Map<String,Object> getConfigurationProperties()
      Return an unmodifiable reference to the configuration map for this factory. Useful for cloning to make a similar factory.
      Returns:
      the configs.
      Since:
      2.0
    • getKeyDeserializer

      @Nullable default org.apache.kafka.common.serialization.Deserializer<K> getKeyDeserializer()
      Return the configured key deserializer (if provided as an object instead of a class name in the properties).
      Returns:
      the deserializer.
      Since:
      2.0
    • getValueDeserializer

      @Nullable default org.apache.kafka.common.serialization.Deserializer<V> getValueDeserializer()
      Return the configured value deserializer (if provided as an object instead of a class name in the properties).
      Returns:
      the deserializer.
      Since:
      2.0
    • removeListener

      default boolean removeListener(ConsumerFactory.Listener<K,V> listener)
      Remove a listener.
      Parameters:
      listener - the listener.
      Returns:
      true if removed.
      Since:
      2.5.3
    • addListener

      default void addListener(int index, ConsumerFactory.Listener<K,V> listener)
      Add a listener at a specific index.
      Parameters:
      index - the index (list position).
      listener - the listener.
      Since:
      2.5.3
    • addListener

      default void addListener(ConsumerFactory.Listener<K,V> listener)
      Add a listener.
      Parameters:
      listener - the listener.
      Since:
      2.5.3
    • getListeners

      default List<ConsumerFactory.Listener<K,V>> getListeners()
      Get the current list of listeners.
      Returns:
      the listeners.
      Since:
      2.5.3
    • addPostProcessor

      default void addPostProcessor(ConsumerPostProcessor<K,V> postProcessor)
      Add a post processor.
      Parameters:
      postProcessor - the post processor.
      Since:
      2.5.3
    • removePostProcessor

      default boolean removePostProcessor(ConsumerPostProcessor<K,V> postProcessor)
      Remove a post processor.
      Parameters:
      postProcessor - the post processor.
      Returns:
      true if removed.
      Since:
      2.5.3
    • getPostProcessors

      default List<ConsumerPostProcessor<K,V>> getPostProcessors()
      Get the current list of post processors.
      Returns:
      the post processor.
      Since:
      2.5.3
    • updateConfigs

      default void updateConfigs(Map<String,Object> updates)
      Update the consumer configuration map; useful for situations such as credential rotation.
      Parameters:
      updates - the configuration properties to update.
      Since:
      2.7
    • removeConfig

      default void removeConfig(String configKey)
      Remove the specified key from the configuration map.
      Parameters:
      configKey - the key to remove.
      Since:
      2.7