use of kafka.serializer.StringDecoder in project open-kilda by telstra.
the class SimpleKafkaTest method buildConsumer.
private ConsumerIterator<String, String> buildConsumer(String topic) {
Properties props = consumerProperties();
Map<String, Integer> topicCountMap = new HashMap<>();
topicCountMap.put(topic, 1);
ConsumerConfig consumerConfig = new ConsumerConfig(props);
consumerConnector = Consumer.createJavaConsumerConnector(consumerConfig);
Map<String, List<KafkaStream<String, String>>> consumers = consumerConnector.createMessageStreams(topicCountMap, new StringDecoder(null), new StringDecoder(null));
KafkaStream<String, String> stream = consumers.get(topic).get(0);
return stream.iterator();
}
use of kafka.serializer.StringDecoder in project microservices by pwillhan.
the class App method start.
private void start(String topic) {
consumer = Consumer.createJavaConsumerConnector(config);
/* We tell Kafka how many threads will read each topic. We have one topic and one thread */
Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
topicCountMap.put(topic, new Integer(1));
/* We will use a decoder to get Kafka to convert messages to Strings
* valid property will be deserializer.encoding with the charset to use.
* default is UTF8 which works for us */
StringDecoder decoder = new StringDecoder(new VerifiableProperties());
/* Kafka will give us a list of streams of messages for each topic.
In this case, its just one topic with a list of a single stream */
stream = consumer.createMessageStreams(topicCountMap, decoder, decoder).get(topic).get(0);
}
use of kafka.serializer.StringDecoder in project jeesuite-libs by vakinge.
the class OldApiTopicConsumer method start.
@Override
public void start() {
// 重置offset
if (consumerContext.getOffsetLogHanlder() != null) {
resetCorrectOffsets();
}
Map<String, Integer> topicCountMap = new HashMap<String, Integer>();
for (String topicName : consumerContext.getMessageHandlers().keySet()) {
int nThreads = 1;
topicCountMap.put(topicName, nThreads);
logger.info("topic[{}] assign fetch Threads {}", topicName, nThreads);
}
StringDecoder keyDecoder = new StringDecoder(new VerifiableProperties());
MessageDecoder valueDecoder = new MessageDecoder(deserializer);
Map<String, List<KafkaStream<String, Object>>> consumerMap = this.connector.createMessageStreams(topicCountMap, keyDecoder, valueDecoder);
for (String topicName : consumerContext.getMessageHandlers().keySet()) {
final List<KafkaStream<String, Object>> streams = consumerMap.get(topicName);
for (final KafkaStream<String, Object> stream : streams) {
MessageProcessor processer = new MessageProcessor(topicName, stream);
this.fetchExecutor.execute(processer);
}
}
//
runing.set(true);
}
use of kafka.serializer.StringDecoder in project thingsboard by thingsboard.
the class KafkaDemoClient method buildConsumer.
private static ConsumerIterator<String, String> buildConsumer(String topic) {
Map<String, Integer> topicCountMap = new HashMap<>();
topicCountMap.put(topic, 1);
ConsumerConfig consumerConfig = new ConsumerConfig(consumerProperties());
ConsumerConnector consumerConnector = Consumer.createJavaConsumerConnector(consumerConfig);
Map<String, List<KafkaStream<String, String>>> consumers = consumerConnector.createMessageStreams(topicCountMap, new StringDecoder(null), new StringDecoder(null));
KafkaStream<String, String> stream = consumers.get(topic).get(0);
return stream.iterator();
}
use of kafka.serializer.StringDecoder in project open-kilda by telstra.
the class Original method buildConsumer.
private ConsumerIterator<String, String> buildConsumer(String topic) {
Properties props = consumerProperties();
Map<String, Integer> topicCountMap = new HashMap<>();
topicCountMap.put(topic, 1);
ConsumerConfig consumerConfig = new ConsumerConfig(props);
consumerConnector = Consumer.createJavaConsumerConnector(consumerConfig);
Map<String, List<KafkaStream<String, String>>> consumers = consumerConnector.createMessageStreams(topicCountMap, new StringDecoder(null), new StringDecoder(null));
KafkaStream<String, String> stream = consumers.get(topic).get(0);
return stream.iterator();
}
Aggregations