A wrapper that combine node-rdkafka and avsc packages together in an easy to reason about API.
npm install @kaluza/kafka-node-avro
As this ultimately uses rdkafka, a C library, your system needs to be set up to build that library.
For the library to work on mac os you will need to add 2 flags to your ~/.bash_profile see installation instructions from node-rdkafka:
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/libMake sure Python point to a version 2.. and openssl is installed correcly on the machine.
It should just work, but if not make sure the following are installed:
For Windows, run npm install -g windows-build-tools first, then install kafka-node-avro.
If you have multiple python versions installed, you need to make sure that python in your PATH resolves to a Python 2 version, otherwise the build of rdkafka will fail
const { consumer } = await createClients({
  host: kafka.host,
  schemaRegistry: kafka.schemaRegistry,
  ca,
  cert,
  key
});
await consumer.subscribe(
  ['OUTPUT_TEST_TOPIC'],
  { groupId: 'kafka-node-example-consuming-group' },
  (message) => {
    console.log(message);
  },
  (err) => {
    console.error(err);
  }
);
// Will stop listening to topic
consumer.unsubscribe();const { producer } = await createClients({
  host: kafka.host,
  schemaRegistry: kafka.schemaRegistry,
  ca,
  cert,
  key
});
await producer.registerSchema('TEST_OUTPUT_TOPIC', [
  {
    default: null,
    name: 'name',
    type: ['null', 'string']
  }
]);
const response = await producer.sendMessage({
  topic: 'TEST_OUTPUT_TOPIC',
  messages: {
    name: 'Bender Bending Rodriguez'
  }
});
console.log(response);Install dependencies:
yarnRun build:
yarn buildRun tests:
yarn testRun examples:
example/certificates with the following files ca.pem, service.key, service.certconfig.json file with the following content:{
  "kafka": {
    "host": "HOST_NAME_HERE",
    "schemaRegistry": "SCHEMA_REGISTRY_HERE",
    "queues": [
      {
        "topic": "TOPIC_NAME",
        "partition": 0,
        "offset": 0
      }
    ],
    "queuesGroup": ["TOPIC_NAME"]
  }
}cd example && node produce-message-to-topic.js for exampleGenerated using TypeDoc