6.0.1 • Published 1 year ago

@microfleet/plugin-kafka v6.0.1

Weekly downloads
26
License
MIT
Repository
github
Last release
1 year ago

Microfleet Kafka Plugin

Adds Kafka support to microfleet. Provides Stream like API for sending messages to Kafka broker.

For more information please read about node-rdkafka.

Install

yarn add @microfleet/plugin-kafka

Configuration

To make use of the plugin, adjust microfleet configuration in the following way:

exports.plugins = [
  ...,
  'kafka',
  ...
]

exports.kafka = {
  // librdkafka configuration
  // https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md
  debug: 'consumer,cgrp,topic,fetch',
  'metadata.broker.list': 'kafka:9092',
  'group.id': 'test-group',
}

Interface

Microfleet Kafka Plugin extends service interface with the following methods:

async service.kafka.createReadStream({ streamOpts, conf, topic }): Readable

Initializes Kafka Consumer stream using provided params and creates a Readable stream. This is the reimplementation of the node-rdkafka.ConsumerStream stream with some addons. Extra parameters:

const streamOpts = {
  checkTopicExists: boolean, // Check whether consumed topics exist.
  stopOnPartitionsEOF: boolean, // Stop stream when all assigned partitions read.
  offsetQueryTimeout: number, // Milliseconds Timeout for Broker requests.
  offsetCommitTimeout: number, // Milliseconds to wait for offset commits received on stream close.
}

async service.kafka.createWriteStream({ streamOpts, conf, topic }): Writable

Initializes Kafka producer using provided params and creates a Writable stream. Detailed docs here - https://blizzard.github.io/node-rdkafka/current/ProducerStream.html

Parameter description

For information about parameters passed to the interface methods:

Example

producerStream = await service.kafka.createProducerStream({
  streamOptions: { objectMode: true, pollInterval: 10 },
  conf: {'group.id': 'other-group'},
})

consumerStream = await service.kafka.createConsumerStream({
  streamOptions: { topics: topic, streamAsBatch: true, fetchSize: 10 },
  conf: {
    debug: 'consumer',
    'enable.auto.commit': false,
    'client.id': 'someid',
    'group.id': 'other-group',
  },
  topic: {
    'auto.offset.reset': 'earliest', // 'earliest | latest' - earliest will start from las committed offset, latest - will start from last received message.
  }
)

// and then
producerStream.write({
  topic,
  value: Buffer.from(`message at ${Date.now()}`),
}, cb)

// or
producerStream.write(Buffer.from(`message at ${Date.now()}`), cb)

for await (const message of consumer) {
  // process message
}
5.1.4

1 year ago

6.0.1

1 year ago

6.0.0

1 year ago

5.1.3

2 years ago

5.1.2

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

5.0.5

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.3.0

2 years ago

4.2.14

2 years ago

4.2.13

2 years ago

4.2.9

2 years ago

4.2.10

2 years ago

4.2.11

2 years ago

4.2.12

2 years ago

4.2.2

2 years ago

4.2.5

2 years ago

4.2.4

2 years ago

4.2.7

2 years ago

4.2.6

2 years ago

4.2.8

2 years ago

4.0.0

3 years ago

4.2.0

3 years ago

2.31.0

3 years ago

2.33.0

3 years ago

2.29.0

3 years ago

2.29.2

3 years ago

2.27.2

3 years ago

2.25.0

3 years ago

2.27.0

3 years ago

2.23.0

3 years ago

2.19.2

3 years ago

2.19.0

3 years ago

2.15.4

3 years ago

2.17.0

3 years ago

2.15.2

3 years ago

2.21.0

3 years ago

2.15.0

3 years ago

2.13.2

3 years ago

2.13.0

3 years ago

2.11.0

4 years ago

2.11.8

3 years ago

2.11.6

4 years ago

2.11.4

4 years ago

2.11.2

4 years ago

2.11.10

3 years ago

2.11.12

3 years ago

2.11.14

3 years ago

2.9.0

4 years ago

2.8.1

4 years ago

2.8.0

4 years ago

2.8.3

4 years ago

2.8.2

4 years ago

2.7.1

4 years ago

2.7.0

4 years ago

2.6.5-next.57

4 years ago

2.6.5-next.56

4 years ago

2.6.5-next.51

4 years ago

2.6.6

4 years ago

2.6.5-next.49

4 years ago

2.6.5-next.46

4 years ago

2.6.5-next.39

4 years ago

2.6.5-next.35

4 years ago

2.6.5-next.31

4 years ago

2.6.5

4 years ago

2.6.4

5 years ago

2.6.3

5 years ago

2.6.2

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.3.2

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.2.0

6 years ago