Search in sources :

Example 1 with MessageDecoder

use of com.jeesuite.kafka.serializer.MessageDecoder 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);
}
Also used : HashMap(java.util.HashMap) VerifiableProperties(kafka.utils.VerifiableProperties) StringDecoder(kafka.serializer.StringDecoder) KafkaStream(kafka.consumer.KafkaStream) MessageDecoder(com.jeesuite.kafka.serializer.MessageDecoder) List(java.util.List)

Aggregations

MessageDecoder (com.jeesuite.kafka.serializer.MessageDecoder)1 HashMap (java.util.HashMap)1 List (java.util.List)1 KafkaStream (kafka.consumer.KafkaStream)1 StringDecoder (kafka.serializer.StringDecoder)1 VerifiableProperties (kafka.utils.VerifiableProperties)1