Class DelegatingByTopicSerializer
- java.lang.Object
-
- org.springframework.kafka.support.serializer.DelegatingByTopicSerialization<org.apache.kafka.common.serialization.Serializer<?>>
-
- org.springframework.kafka.support.serializer.DelegatingByTopicSerializer
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,org.apache.kafka.common.serialization.Serializer<java.lang.Object>
public class DelegatingByTopicSerializer extends DelegatingByTopicSerialization<org.apache.kafka.common.serialization.Serializer<?>> implements org.apache.kafka.common.serialization.Serializer<java.lang.Object>
ASerializer
that delegates to other serializers based on a topic pattern.- Since:
- 2.8
- Author:
- Gary Russell
-
-
Field Summary
-
Fields inherited from class org.springframework.kafka.support.serializer.DelegatingByTopicSerialization
CASE_SENSITIVE, KEY_SERIALIZATION_TOPIC_CONFIG, KEY_SERIALIZATION_TOPIC_DEFAULT, VALUE_SERIALIZATION_TOPIC_CONFIG, VALUE_SERIALIZATION_TOPIC_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description DelegatingByTopicSerializer()
Construct an instance that will be configured inconfigure(Map, boolean)
with producer propertiesDelegatingByTopicSerialization.VALUE_SERIALIZATION_TOPIC_CONFIG
andDelegatingByTopicSerialization.KEY_SERIALIZATION_TOPIC_CONFIG
.DelegatingByTopicSerializer(java.util.Map<java.util.regex.Pattern,org.apache.kafka.common.serialization.Serializer<?>> delegates, org.apache.kafka.common.serialization.Serializer<?> defaultDelegate)
Construct an instance with the supplied mapping of topic patterns to delegate serializers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
protected org.apache.kafka.common.serialization.Serializer<?>
configureDelegate(java.util.Map<java.lang.String,?> configs, boolean isKey, org.apache.kafka.common.serialization.Serializer<?> delegate)
Configure the delegate.protected boolean
isInstance(java.lang.Object instance)
Return true if this object is an instance of T.byte[]
serialize(java.lang.String topic, java.lang.Object data)
byte[]
serialize(java.lang.String topic, org.apache.kafka.common.header.Headers headers, java.lang.Object data)
-
Methods inherited from class org.springframework.kafka.support.serializer.DelegatingByTopicSerialization
addDelegate, build, buildDefault, close, findDelegate, instantiateAndConfigure, removeDelegate, setCaseSensitive
-
-
-
-
Constructor Detail
-
DelegatingByTopicSerializer
public DelegatingByTopicSerializer()
Construct an instance that will be configured inconfigure(Map, boolean)
with producer propertiesDelegatingByTopicSerialization.VALUE_SERIALIZATION_TOPIC_CONFIG
andDelegatingByTopicSerialization.KEY_SERIALIZATION_TOPIC_CONFIG
.
-
DelegatingByTopicSerializer
public DelegatingByTopicSerializer(java.util.Map<java.util.regex.Pattern,org.apache.kafka.common.serialization.Serializer<?>> delegates, org.apache.kafka.common.serialization.Serializer<?> defaultDelegate)
Construct an instance with the supplied mapping of topic patterns to delegate serializers.- Parameters:
delegates
- the map of delegates.defaultDelegate
- the default to use when no topic name match.
-
-
Method Detail
-
configure
public void configure(java.util.Map<java.lang.String,?> configs, boolean isKey)
- Specified by:
configure
in interfaceorg.apache.kafka.common.serialization.Serializer<java.lang.Object>
- Overrides:
configure
in classDelegatingByTopicSerialization<org.apache.kafka.common.serialization.Serializer<?>>
-
configureDelegate
protected org.apache.kafka.common.serialization.Serializer<?> configureDelegate(java.util.Map<java.lang.String,?> configs, boolean isKey, org.apache.kafka.common.serialization.Serializer<?> delegate)
Description copied from class:DelegatingByTopicSerialization
Configure the delegate.- Specified by:
configureDelegate
in classDelegatingByTopicSerialization<org.apache.kafka.common.serialization.Serializer<?>>
- Parameters:
configs
- the configs.isKey
- true if this is for keys.delegate
- the delegate.- Returns:
- the delegate.
-
isInstance
protected boolean isInstance(java.lang.Object instance)
Description copied from class:DelegatingByTopicSerialization
Return true if this object is an instance of T.- Specified by:
isInstance
in classDelegatingByTopicSerialization<org.apache.kafka.common.serialization.Serializer<?>>
- Parameters:
instance
- the delegate.- Returns:
- true if a T.
-
serialize
public byte[] serialize(java.lang.String topic, java.lang.Object data)
- Specified by:
serialize
in interfaceorg.apache.kafka.common.serialization.Serializer<java.lang.Object>
-
serialize
public byte[] serialize(java.lang.String topic, org.apache.kafka.common.header.Headers headers, java.lang.Object data)
- Specified by:
serialize
in interfaceorg.apache.kafka.common.serialization.Serializer<java.lang.Object>
-
-