Package org.springframework.kafka.core
Interface ConsumerFactory<K,V>
-
- Type Parameters:
K
- the key type.V
- the value type.
- All Known Implementing Classes:
DefaultKafkaConsumerFactory
public interface ConsumerFactory<K,V>
The strategy to produce aConsumer
instance(s).
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ConsumerFactory.Listener<K,V>
Called whenever a consumer is added or removed.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
addListener(int index, ConsumerFactory.Listener<K,V> listener)
Add a listener at a specific index.default void
addListener(ConsumerFactory.Listener<K,V> listener)
Add a listener.default void
addPostProcessor(ConsumerPostProcessor<K,V> postProcessor)
Add a post processor.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.default org.apache.kafka.clients.consumer.Consumer<K,V>
createConsumer(java.lang.String clientIdSuffix)
Create a consumer, appending the suffix to theclient.id
property, if present.default org.apache.kafka.clients.consumer.Consumer<K,V>
createConsumer(java.lang.String groupId, java.lang.String clientIdSuffix)
Create a consumer with an explicit group id; in addition, the client id suffix is appended to theclient.id
property, if both are present.org.apache.kafka.clients.consumer.Consumer<K,V>
createConsumer(java.lang.String groupId, java.lang.String clientIdPrefix, java.lang.String clientIdSuffix)
Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides theclient.id
property, if present.default org.apache.kafka.clients.consumer.Consumer<K,V>
createConsumer(java.lang.String groupId, java.lang.String clientIdPrefix, java.lang.String clientIdSuffix, java.util.Properties properties)
Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides theclient.id
property, if present.default java.util.Map<java.lang.String,java.lang.Object>
getConfigurationProperties()
Return an unmodifiable reference to the configuration map for this factory.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).default java.util.List<ConsumerFactory.Listener<K,V>>
getListeners()
Get the current list of listeners.default java.util.List<ConsumerPostProcessor<K,V>>
getPostProcessors()
Get the current list of post processors.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).boolean
isAutoCommit()
Return true if consumers created by this factory use auto commit.default void
removeConfig(java.lang.String configKey)
Remove the specified key from the configuration map.default boolean
removeListener(ConsumerFactory.Listener<K,V> listener)
Remove a listener.default boolean
removePostProcessor(ConsumerPostProcessor<K,V> postProcessor)
Remove a post processor.default void
updateConfigs(java.util.Map<java.lang.String,java.lang.Object> updates)
Update the consumer configuration map; useful for situations such as credential rotation.
-
-
-
Method Detail
-
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 java.lang.String clientIdSuffix)
Create a consumer, appending the suffix to theclient.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 java.lang.String groupId, @Nullable java.lang.String clientIdSuffix)
Create a consumer with an explicit group id; in addition, the client id suffix is appended to theclient.id
property, if both are present.- Parameters:
groupId
- the group id.clientIdSuffix
- the suffix.- Returns:
- the consumer.
- Since:
- 1.3
-
createConsumer
org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable java.lang.String groupId, @Nullable java.lang.String clientIdPrefix, @Nullable java.lang.String clientIdSuffix)
Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides theclient.id
property, if present.- Parameters:
groupId
- the group id.clientIdPrefix
- the prefix.clientIdSuffix
- the suffix.- Returns:
- the consumer.
- Since:
- 2.1.1
-
createConsumer
default org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable java.lang.String groupId, @Nullable java.lang.String clientIdPrefix, @Nullable java.lang.String clientIdSuffix, @Nullable java.util.Properties properties)
Create a consumer with an explicit group id; in addition, the client id suffix is appended to the clientIdPrefix which overrides theclient.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 java.util.Map<java.lang.String,java.lang.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 java.util.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 java.util.List<ConsumerPostProcessor<K,V>> getPostProcessors()
Get the current list of post processors.- Returns:
- the post processor.
- Since:
- 2.5.3
-
updateConfigs
default void updateConfigs(java.util.Map<java.lang.String,java.lang.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(java.lang.String configKey)
Remove the specified key from the configuration map.- Parameters:
configKey
- the key to remove.- Since:
- 2.7
-
-