K - the key type.V - the value type.public class DefaultKafkaConsumerFactory<K,V> extends java.lang.Object implements ConsumerFactory<K,V>, org.springframework.beans.factory.BeanNameAware
ConsumerFactory implementation to produce new Consumer instances
for provided Map configs and optional Deserializers on each ConsumerFactory.createConsumer()
invocation.
If you are using Deserializers that have no-arg constructors and require no setup, then simplest to
specify Deserializer classes against ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG and
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG keys in the configs passed to the
DefaultKafkaConsumerFactory constructor.
If that is not possible, but you are using Deserializers that may be shared between all Consumer
instances (and specifically that their close() method is a no-op), then you can pass in Deserializer
instances for one or both of the key and value deserializers.
If neither of the above is true then you may provide a Supplier for one or both Deserializers
which will be used to obtain Deserializer(s) each time a Consumer is created by the factory.
| Constructor and Description |
|---|
DefaultKafkaConsumerFactory(java.util.Map<java.lang.String,java.lang.Object> configs)
Construct a factory with the provided configuration.
|
DefaultKafkaConsumerFactory(java.util.Map<java.lang.String,java.lang.Object> configs,
org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer,
org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer)
Construct a factory with the provided configuration and deserializers.
|
DefaultKafkaConsumerFactory(java.util.Map<java.lang.String,java.lang.Object> configs,
java.util.function.Supplier<org.apache.kafka.common.serialization.Deserializer<K>> keyDeserializerSupplier,
java.util.function.Supplier<org.apache.kafka.common.serialization.Deserializer<V>> valueDeserializerSupplier)
Construct a factory with the provided configuration and deserializer suppliers.
|
| Modifier and Type | Method and Description |
|---|---|
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 the
client.id property, if present. |
org.apache.kafka.clients.consumer.Consumer<K,V> |
createConsumer(java.lang.String groupId,
java.lang.String clientIdPrefix,
java.lang.String clientIdSuffixArg,
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 the
client.id property, if present. |
protected org.apache.kafka.clients.consumer.KafkaConsumer<K,V> |
createKafkaConsumer(java.util.Map<java.lang.String,java.lang.Object> configProps) |
protected org.apache.kafka.clients.consumer.KafkaConsumer<K,V> |
createKafkaConsumer(java.lang.String groupId,
java.lang.String clientIdPrefix,
java.lang.String clientIdSuffixArg)
Deprecated.
|
protected org.apache.kafka.clients.consumer.KafkaConsumer<K,V> |
createKafkaConsumer(java.lang.String groupId,
java.lang.String clientIdPrefix,
java.lang.String clientIdSuffixArg,
java.util.Properties properties) |
java.util.Map<java.lang.String,java.lang.Object> |
getConfigurationProperties()
Return an unmodifiable reference to the configuration map for this factory.
|
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).
|
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.
|
void |
setBeanName(java.lang.String name) |
void |
setKeyDeserializer(org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer) |
void |
setValueDeserializer(org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateConsumer, createConsumer, createConsumerpublic DefaultKafkaConsumerFactory(java.util.Map<java.lang.String,java.lang.Object> configs)
configs - the configuration.public DefaultKafkaConsumerFactory(java.util.Map<java.lang.String,java.lang.Object> configs,
@Nullable
org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer,
@Nullable
org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer)
configs - the configuration.keyDeserializer - the key Deserializer.valueDeserializer - the value Deserializer.public DefaultKafkaConsumerFactory(java.util.Map<java.lang.String,java.lang.Object> configs,
@Nullable
java.util.function.Supplier<org.apache.kafka.common.serialization.Deserializer<K>> keyDeserializerSupplier,
@Nullable
java.util.function.Supplier<org.apache.kafka.common.serialization.Deserializer<V>> valueDeserializerSupplier)
configs - the configuration.keyDeserializerSupplier - the key Deserializer supplier function.valueDeserializerSupplier - the value Deserializer supplier function.public void setBeanName(java.lang.String name)
setBeanName in interface org.springframework.beans.factory.BeanNameAwarepublic void setKeyDeserializer(@Nullable
org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer)
public void setValueDeserializer(@Nullable
org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer)
public java.util.Map<java.lang.String,java.lang.Object> getConfigurationProperties()
ConsumerFactorygetConfigurationProperties in interface ConsumerFactory<K,V>public org.apache.kafka.common.serialization.Deserializer<K> getKeyDeserializer()
ConsumerFactorygetKeyDeserializer in interface ConsumerFactory<K,V>public org.apache.kafka.common.serialization.Deserializer<V> getValueDeserializer()
ConsumerFactorygetValueDeserializer in interface ConsumerFactory<K,V>public org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable java.lang.String groupId, @Nullable java.lang.String clientIdPrefix, @Nullable java.lang.String clientIdSuffix)
ConsumerFactoryclient.id property, if present.createConsumer in interface ConsumerFactory<K,V>groupId - the group id.clientIdPrefix - the prefix.clientIdSuffix - the suffix.public org.apache.kafka.clients.consumer.Consumer<K,V> createConsumer(@Nullable java.lang.String groupId, @Nullable java.lang.String clientIdPrefix, @Nullable java.lang.String clientIdSuffixArg, @Nullable java.util.Properties properties)
ConsumerFactoryclient.id property, if present. In addition, consumer properties can
be overridden if the factory implementation supports it.createConsumer in interface ConsumerFactory<K,V>groupId - the group id.clientIdPrefix - the prefix.clientIdSuffixArg - the suffix.properties - the properties to override.@Deprecated protected org.apache.kafka.clients.consumer.KafkaConsumer<K,V> createKafkaConsumer(@Nullable java.lang.String groupId, @Nullable java.lang.String clientIdPrefix, @Nullable java.lang.String clientIdSuffixArg)
protected org.apache.kafka.clients.consumer.KafkaConsumer<K,V> createKafkaConsumer(@Nullable java.lang.String groupId, @Nullable java.lang.String clientIdPrefix, @Nullable java.lang.String clientIdSuffixArg, @Nullable java.util.Properties properties)
protected org.apache.kafka.clients.consumer.KafkaConsumer<K,V> createKafkaConsumer(java.util.Map<java.lang.String,java.lang.Object> configProps)
public boolean isAutoCommit()
ConsumerFactoryisAutoCommit in interface ConsumerFactory<K,V>