consumerMessage.ts 644 Bytes
Newer Older
chinguyen's avatar
chinguyen committed
1 2 3 4 5
import * as kafka from 'kafka-node';
//import {getConsumer} from './message'



6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
export function receiveMessage(): any {
  const _that = this;
  let topicName = 'message-chinguyen';
  let produceTopic = topicName;
  let kafkaConsumer = kafka.Consumer;
  let Client = kafka.KafkaClient;
  let client = new Client({ kafkaHost: 'localhost:9092' })

  let consumer = new kafkaConsumer(client, [{ topic: produceTopic }], { autoCommit: false, fetchMaxWaitMs: 1000, fetchMaxBytes: 1024 * 1024 })

  consumer.on('message', function(message) {
    console.log(message);
  });
  consumer.on('error', function(err) {
    console.log('error', err);
  });
}