public class KafkaProducerInterceptorWrapper<K,V> extends Object implements org.apache.pulsar.client.api.ProducerInterceptor<byte[]>
ProducerInterceptor to make pulsar support
Kafka ProducerInterceptor. It holds an instance of ProducerInterceptor
and it'll delegate all invocation to that instance.
Extend ProducerInterceptor as all Pulsar Message created by
PulsarKafkaProducer is of type byte[].
| 构造器和说明 |
|---|
KafkaProducerInterceptorWrapper(org.apache.kafka.clients.producer.ProducerInterceptor<K,V> kafkaProducerInterceptor,
org.apache.kafka.common.serialization.Serializer<K> keySerializer,
org.apache.kafka.common.serialization.Serializer<V> valueSerializer,
String topic)
Create a wrapper of type
ProducerInterceptor that will delegate all work to underlying Kafka's interceptor. |
| 限定符和类型 | 方法和说明 |
|---|---|
org.apache.pulsar.client.api.Message<byte[]> |
beforeSend(org.apache.pulsar.client.api.Producer<byte[]> producer,
org.apache.pulsar.client.api.Message<byte[]> message)
It tries to convert a Pulsar
Message to a KafkaProducerRecord, pass it to underlying
ProducerInterceptor.onSend(ProducerRecord) then convert the output
back to Pulsar Message. |
void |
close()
Called when interceptor is closed.
|
void |
onSendAcknowledgement(org.apache.pulsar.client.api.Producer<byte[]> producer,
org.apache.pulsar.client.api.Message<byte[]> message,
org.apache.pulsar.client.api.MessageId msgId,
Throwable exception)
Delegate work to
ProducerInterceptor.onAcknowledgement(org.apache.kafka.clients.producer.RecordMetadata, java.lang.Exception) |
public KafkaProducerInterceptorWrapper(org.apache.kafka.clients.producer.ProducerInterceptor<K,V> kafkaProducerInterceptor, org.apache.kafka.common.serialization.Serializer<K> keySerializer, org.apache.kafka.common.serialization.Serializer<V> valueSerializer, String topic)
ProducerInterceptor that will delegate all work to underlying Kafka's interceptor.kafkaProducerInterceptor - Underlying instance of org.apache.kafka.clients.producer.ProducerInterceptor
that this wrapper will delegate work to.keySerializer - Serializer used to serialize Kafka ProducerRecord.key.valueSerializer - Serializer used to serialize Kafka ProducerRecord.value.topic - Topic this ProducerInterceptor will be associated to.public void close()
ProducerInterceptor.close()close 在接口中 AutoCloseableclose 在接口中 org.apache.pulsar.client.api.ProducerInterceptor<byte[]>public org.apache.pulsar.client.api.Message<byte[]> beforeSend(org.apache.pulsar.client.api.Producer<byte[]> producer,
org.apache.pulsar.client.api.Message<byte[]> message)
Message to a KafkaProducerRecord, pass it to underlying
ProducerInterceptor.onSend(ProducerRecord) then convert the output
back to Pulsar Message.
When build a Pulsar Message at PulsarKafkaProducer.buildMessage(org.apache.pulsar.client.api.TypedMessageBuilder<byte[]>, org.apache.kafka.clients.producer.ProducerRecord<K, V>)
schema, eventtime, partitionID, key and value are set. All this information will be preserved during the conversion.
beforeSend 在接口中 org.apache.pulsar.client.api.ProducerInterceptor<byte[]>producer - the producer which contains the interceptor, will be ignored as Kafka
ProducerInterceptor doesn't use it.message - message to sendpublic void onSendAcknowledgement(org.apache.pulsar.client.api.Producer<byte[]> producer,
org.apache.pulsar.client.api.Message<byte[]> message,
org.apache.pulsar.client.api.MessageId msgId,
Throwable exception)
ProducerInterceptor.onAcknowledgement(org.apache.kafka.clients.producer.RecordMetadata, java.lang.Exception)onSendAcknowledgement 在接口中 org.apache.pulsar.client.api.ProducerInterceptor<byte[]>producer - the producer which contains the interceptor.message - the message that application sendsmsgId - the message id that assigned by the broker; null if send failed.exception - the exception on sending messages, null indicates send has succeed.Copyright © 2017–2019 Apache Software Foundation. All rights reserved.