49
49
import org .apache .pulsar .io .core .annotations .IOType ;
50
50
51
51
/**
52
- * Kafka Source that transfers the data from Kafka to Pulsar and sets the Schema type properly.
53
- * We use the key and the value deserializer in order to decide the type of Schema to be set on the topic on Pulsar.
54
- * In case of KafkaAvroDeserializer we use the Schema Registry to download the schema and apply it to the topic.
55
- * Please refer to {@link #getSchemaFromDeserializerAndAdaptConfiguration(String, Properties, boolean)} for the list
56
- * of supported Deserializers.
57
- * If you set StringDeserializer for the key then we use the raw key as key for the Pulsar message.
58
- * If you set another Deserializer for the key we use the KeyValue schema type in Pulsar with the SEPARATED encoding.
59
- * This way the Key is stored in the Pulsar key, encoded as base64 string and with a Schema, the Value of the message
60
- * is stored in the Pulsar value with a Schema.
61
- * This way there is a one-to-one mapping between Kafka key/value pair and the Pulsar data model.
52
+ * Kafka Source that transfers the data from Kafka to Pulsar and sets the Schema type properly.
53
+ * We use the key and the value deserializer in order to decide the type of Schema to be set on the topic on Pulsar.
54
+ * In case of KafkaAvroDeserializer we use the Schema Registry to download the schema and apply it to the topic.
55
+ * Please refer to {@link #getSchemaFromDeserializerAndAdaptConfiguration(String, Properties, boolean)} for the list
56
+ * of supported Deserializers.
57
+ * If you set StringDeserializer for the key then we use the raw key as key for the Pulsar message.
58
+ * If you set another Deserializer for the key we use the KeyValue schema type in Pulsar with the SEPARATED encoding.
59
+ * This way the Key is stored in the Pulsar key, encoded as base64 string and with a Schema, the Value of the message
60
+ * is stored in the Pulsar value with a Schema.
61
+ * This way there is a one-to-one mapping between Kafka key/value pair and the Pulsar data model.
62
62
*/
63
63
@ Connector (
64
- name = "kafka" ,
65
- type = IOType .SOURCE ,
66
- help = "Transfer data from Kafka to Pulsar." ,
67
- configClass = KafkaSourceConfig .class
64
+ name = "kafka" ,
65
+ type = IOType .SOURCE ,
66
+ help = "Transfer data from Kafka to Pulsar." ,
67
+ configClass = KafkaSourceConfig .class
68
68
)
69
69
@ Slf4j
70
70
public class KafkaBytesSource extends KafkaAbstractSource <ByteBuffer > {
@@ -78,15 +78,15 @@ public class KafkaBytesSource extends KafkaAbstractSource<ByteBuffer> {
78
78
protected Properties beforeCreateConsumer (Properties props ) {
79
79
props .putIfAbsent (ConsumerConfig .KEY_DESERIALIZER_CLASS_CONFIG , StringDeserializer .class .getName ());
80
80
props .putIfAbsent (ConsumerConfig .VALUE_DESERIALIZER_CLASS_CONFIG , ByteArrayDeserializer .class .getName ());
81
- log .info ("Created kafka consumer config : {}" , props );
81
+ log .info ("Created kafka consumer on : {}" , props . getOrDefault ( ConsumerConfig . BOOTSTRAP_SERVERS_CONFIG , "" ) );
82
82
83
83
keySchema = getSchemaFromDeserializerAndAdaptConfiguration (ConsumerConfig .KEY_DESERIALIZER_CLASS_CONFIG ,
84
84
props , true );
85
85
valueSchema = getSchemaFromDeserializerAndAdaptConfiguration (ConsumerConfig .VALUE_DESERIALIZER_CLASS_CONFIG ,
86
86
props , false );
87
87
88
88
boolean needsSchemaCache = keySchema == DeferredSchemaPlaceholder .INSTANCE
89
- || valueSchema == DeferredSchemaPlaceholder .INSTANCE ;
89
+ || valueSchema == DeferredSchemaPlaceholder .INSTANCE ;
90
90
91
91
if (needsSchemaCache ) {
92
92
initSchemaCache (props );
@@ -174,8 +174,8 @@ private static Schema<ByteBuffer> getSchemaFromDeserializerAndAdaptConfiguration
174
174
175
175
Schema <?> result ;
176
176
if (ByteArrayDeserializer .class .getName ().equals (kafkaDeserializerClass )
177
- || ByteBufferDeserializer .class .getName ().equals (kafkaDeserializerClass )
178
- || BytesDeserializer .class .getName ().equals (kafkaDeserializerClass )) {
177
+ || ByteBufferDeserializer .class .getName ().equals (kafkaDeserializerClass )
178
+ || BytesDeserializer .class .getName ().equals (kafkaDeserializerClass )) {
179
179
result = Schema .BYTEBUFFER ;
180
180
} else if (StringDeserializer .class .getName ().equals (kafkaDeserializerClass )) {
181
181
if (isKey ) {
@@ -193,7 +193,7 @@ private static Schema<ByteBuffer> getSchemaFromDeserializerAndAdaptConfiguration
193
193
result = Schema .INT64 ;
194
194
} else if (ShortDeserializer .class .getName ().equals (kafkaDeserializerClass )) {
195
195
result = Schema .INT16 ;
196
- } else if (KafkaAvroDeserializer .class .getName ().equals (kafkaDeserializerClass )){
196
+ } else if (KafkaAvroDeserializer .class .getName ().equals (kafkaDeserializerClass )) {
197
197
// in this case we have to inject our custom deserializer
198
198
// that extracts Avro schema information
199
199
props .put (key , ExtractKafkaAvroSchemaDeserializer .class .getName ());
@@ -238,7 +238,7 @@ public BytesWithKafkaSchema deserialize(String topic, byte[] payload) {
238
238
}
239
239
}
240
240
241
- static final class DeferredSchemaPlaceholder extends ByteBufferSchemaWrapper {
241
+ static final class DeferredSchemaPlaceholder extends ByteBufferSchemaWrapper {
242
242
DeferredSchemaPlaceholder () {
243
243
super (SchemaInfoImpl
244
244
.builder ()
@@ -247,6 +247,7 @@ static final class DeferredSchemaPlaceholder extends ByteBufferSchemaWrapper {
247
247
.schema (new byte [0 ])
248
248
.build ());
249
249
}
250
+
250
251
static final DeferredSchemaPlaceholder INSTANCE = new DeferredSchemaPlaceholder ();
251
252
}
252
253
0 commit comments