Package org.springframework.kafka.core
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(s).- Author:
- Gary Russell, Artem Bilan
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCalled whenever a consumer is added or removed. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidaddListener(int index, ConsumerFactory.Listener<K, V> listener) Add a listener at a specific index.default voidaddListener(ConsumerFactory.Listener<K, V> listener) Add a listener.default voidaddPostProcessor(ConsumerPostProcessor<K, V> postProcessor) Add a post processor.Create a consumer with the group id and client id as configured in the properties.createConsumer(String clientIdSuffix) Create a consumer, appending the suffix to theclient.idproperty, if present.createConsumer(String groupId, String clientIdSuffix) Create a consumer with an explicit group id; in addition, the client id suffix is appended to theclient.idproperty, if both are present.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 theclient.idproperty, if present.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 theclient.idproperty, if present.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).default List<ConsumerFactory.Listener<K,V>> Get the current list of listeners.default List<ConsumerPostProcessor<K,V>> 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).booleanReturn true if consumers created by this factory use auto commit.default voidremoveConfig(String configKey) Remove the specified key from the configuration map.default booleanremoveListener(ConsumerFactory.Listener<K, V> listener) Remove a listener.default booleanremovePostProcessor(ConsumerPostProcessor<K, V> postProcessor) Remove a post processor.default voidupdateConfigs(Map<String, Object> updates) Update the consumer configuration map; useful for situations such as credential rotation.
-
Method Details
-
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 theclient.idproperty, 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 theclient.idproperty, 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 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 theclient.idproperty, 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 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 theclient.idproperty, 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
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
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
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
Remove a listener.- Parameters:
listener- the listener.- Returns:
- true if removed.
- Since:
- 2.5.3
-
addListener
Add a listener at a specific index.- Parameters:
index- the index (list position).listener- the listener.- Since:
- 2.5.3
-
addListener
Add a listener.- Parameters:
listener- the listener.- Since:
- 2.5.3
-
getListeners
Get the current list of listeners.- Returns:
- the listeners.
- Since:
- 2.5.3
-
addPostProcessor
Add a post processor.- Parameters:
postProcessor- the post processor.- Since:
- 2.5.3
-
removePostProcessor
Remove a post processor.- Parameters:
postProcessor- the post processor.- Returns:
- true if removed.
- Since:
- 2.5.3
-
getPostProcessors
Get the current list of post processors.- Returns:
- the post processor.
- Since:
- 2.5.3
-
updateConfigs
Update the consumer configuration map; useful for situations such as credential rotation.- Parameters:
updates- the configuration properties to update.- Since:
- 2.7
-
removeConfig
Remove the specified key from the configuration map.- Parameters:
configKey- the key to remove.- Since:
- 2.7
-