@Internal public class KafkaSerializationSchemaWrapper<T> extends Object implements KafkaSerializationSchema<T>, KafkaContextAware<T>
SerializationSchema
, FlinkKafkaPartitioner
to the KafkaSerializationSchema
.Constructor and Description |
---|
KafkaSerializationSchemaWrapper(String topic,
FlinkKafkaPartitioner<T> partitioner,
boolean writeTimestamp,
SerializationSchema<T> serializationSchema) |
Modifier and Type | Method and Description |
---|---|
String |
getTargetTopic(T element)
Returns the topic that the presented element should be sent to.
|
void |
open(SerializationSchema.InitializationContext context)
Initialization method for the schema.
|
org.apache.kafka.clients.producer.ProducerRecord<byte[],byte[]> |
serialize(T element,
Long timestamp)
Serializes given element and returns it as a
ProducerRecord . |
void |
setNumParallelInstances(int numParallelInstances)
Sets the parallelism with which the parallel task of the Kafka Producer runs.
|
void |
setParallelInstanceId(int parallelInstanceId)
Sets the number of the parallel subtask that the Kafka Producer is running on.
|
void |
setPartitions(int[] partitions)
Sets the available partitions for the topic returned from
KafkaContextAware.getTargetTopic(Object) . |
void |
setWriteTimestamp(boolean writeTimestamp) |
public KafkaSerializationSchemaWrapper(String topic, FlinkKafkaPartitioner<T> partitioner, boolean writeTimestamp, SerializationSchema<T> serializationSchema)
public void open(SerializationSchema.InitializationContext context) throws Exception
KafkaSerializationSchema
KafkaSerializationSchema.serialize(Object, Long)
and thus suitable for one time setup work.
The provided SerializationSchema.InitializationContext
can be used to access
additional features such as e.g. registering user metrics.
open
in interface KafkaSerializationSchema<T>
context
- Contextual information that can be used during initialization.Exception
public org.apache.kafka.clients.producer.ProducerRecord<byte[],byte[]> serialize(T element, @Nullable Long timestamp)
KafkaSerializationSchema
ProducerRecord
.serialize
in interface KafkaSerializationSchema<T>
element
- element to be serializedtimestamp
- timestamp (can be null)ProducerRecord
public String getTargetTopic(T element)
KafkaContextAware
ProducerRecord
that
is returned from KafkaSerializationSchema.serialize(Object, Long)
, it is only used
for getting the available partitions that are presented to KafkaContextAware.setPartitions(int[])
.getTargetTopic
in interface KafkaContextAware<T>
public void setPartitions(int[] partitions)
KafkaContextAware
KafkaContextAware.getTargetTopic(Object)
.setPartitions
in interface KafkaContextAware<T>
public void setParallelInstanceId(int parallelInstanceId)
KafkaContextAware
KafkaContextAware.setNumParallelInstances(int)
).setParallelInstanceId
in interface KafkaContextAware<T>
public void setNumParallelInstances(int numParallelInstances)
KafkaContextAware
setNumParallelInstances
in interface KafkaContextAware<T>
public void setWriteTimestamp(boolean writeTimestamp)
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.