|
10 | 10 | import org.apache.kafka.common.serialization.Deserializer;
|
11 | 11 | import org.slf4j.Logger;
|
12 | 12 | import org.slf4j.LoggerFactory;
|
| 13 | +import scala.Option; |
13 | 14 |
|
14 | 15 | import java.io.Closeable;
|
15 | 16 | import java.io.IOException;
|
16 |
| -import java.util.ArrayList; |
17 |
| -import java.util.Collections; |
18 |
| -import java.util.List; |
| 17 | +import java.util.*; |
19 | 18 | import java.util.concurrent.Future;
|
20 | 19 |
|
21 | 20 | /**
|
@@ -50,10 +49,31 @@ public KmqClient(KmqConfig config, KafkaClients clients,
|
50 | 49 | this.msgPollTimeout = msgPollTimeout;
|
51 | 50 |
|
52 | 51 | this.msgConsumer = clients.createConsumer(config.getMsgConsumerGroupId(), keyDeserializer, valueDeserializer);
|
53 |
| - // Using the custom partitioner, each offset-partition will contain markers only from a single queue-partition. |
54 | 52 | this.markerProducer = clients.createProducer(
|
55 |
| - MarkerKey.MarkerKeySerializer.class, MarkerValue.MarkerValueSerializer.class, |
56 |
| - Collections.singletonMap(ProducerConfig.PARTITIONER_CLASS_CONFIG, ParititionFromMarkerKey.class)); |
| 53 | + MarkerKey.MarkerKeySerializer.class, MarkerValue.MarkerValueSerializer.class, |
| 54 | + Collections.singletonMap(ProducerConfig.PARTITIONER_CLASS_CONFIG, ParititionFromMarkerKey.class)); |
| 55 | + |
| 56 | + LOG.info(String.format("Subscribing to topic: %s, using group id: %s", config.getMsgTopic(), config.getMsgConsumerGroupId())); |
| 57 | + msgConsumer.subscribe(Collections.singletonList(config.getMsgTopic())); |
| 58 | + } |
| 59 | + |
| 60 | + public KmqClient(KmqConfig config, KafkaClients clients, |
| 61 | + Class<? extends Deserializer<K>> keyDeserializer, |
| 62 | + Class<? extends Deserializer<V>> valueDeserializer, |
| 63 | + long msgPollTimeout, Map<String, Object> extraConfig) { |
| 64 | + |
| 65 | + this.config = config; |
| 66 | + this.msgPollTimeout = msgPollTimeout; |
| 67 | + |
| 68 | + // Using the custom partitioner, each offset-partition will contain markers only from a single queue-partition. |
| 69 | + // Adding the PARTITIONER_CLASS_CONFIG in extraConfig map, if extraConfig is not empty |
| 70 | + this.msgConsumer = clients.createConsumer(config.getMsgConsumerGroupId(), keyDeserializer, valueDeserializer, extraConfig); |
| 71 | + extraConfig.put(ProducerConfig.PARTITIONER_CLASS_CONFIG, ParititionFromMarkerKey.class); |
| 72 | + this.markerProducer = clients.createProducer( |
| 73 | + MarkerKey.MarkerKeySerializer.class, MarkerValue.MarkerValueSerializer.class, |
| 74 | + extraConfig); |
| 75 | + |
| 76 | + |
57 | 77 |
|
58 | 78 | LOG.info(String.format("Subscribing to topic: %s, using group id: %s", config.getMsgTopic(), config.getMsgConsumerGroupId()));
|
59 | 79 | msgConsumer.subscribe(Collections.singletonList(config.getMsgTopic()));
|
|
0 commit comments