Skip to content

Latest commit

 

History

History
32 lines (28 loc) · 723 Bytes

high-level-producer.md

File metadata and controls

32 lines (28 loc) · 723 Bytes
var Kafka = require('../');

var producer = new Kafka.HighLevelProducer({
  'metadata.broker.list': 'localhost:9092',
});

// Throw away the keys
producer.setKeySerializer(function(v) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(null);
    }, 20);
  });
});

// Take the message field
producer.setValueSerializer(function(v) {
  return Buffer.from(v.message);
});

producer.connect(null, function() {
  producer.produce('test', null, {
    message: 'alliance4ever',
  }, null, Date.now(), function(err, offset) {
    // The offset if our acknowledgement level allows us to receive delivery offsets
    setImmediate(function() {
      producer.disconnect();
    });
  });
});