Skip to content

Sync/blizzard #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
submodules: recursive
- uses: actions/setup-node@v3
with:
node-version: 18
node-version: 20
registry-url: https://registry.npmjs.org/
cache: "npm"
- run: npm ci
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
build:
strategy:
matrix:
node: [10, 12, 14, 16, 18, 20]
node: [16, 18, 20, 21]
os: [ubuntu-22.04]
include:
# single mac test due to minute multipliers
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions
- node: 20
os: macos-12
os: macos-14
# single windows test due to node.js 14 node-gyp / vs 2022 issues
- node: 20
os: windows-2022
Expand All @@ -39,5 +39,5 @@ jobs:
run: npm ci
# skipping on windows for now due to Make / mocha exit code issues
- name: Test
if: runner.os != 'Windows' && matrix.node != 10
if: runner.os != 'Windows'
run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ deps/*
.DS_Store

.vscode
.idea
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ so if you feel something is missing feel free to send a pull request.
* [Contributor Agreement](#contributor-agreement)

[How Can I Contribute?](#how-can-i-contribute)
* [Setting up the repository](#setting-up-the-repository)
* [Reporting Bugs](#reporting-bugs)
* [Suggesting Enhancements](#suggesting-enhancements)
* [Pull Requests](#pull-requests)
Expand All @@ -37,6 +38,14 @@ Not currently required.

## How can I contribute?

### Setting up the repository

To set up the library locally, do the following:

1) Clone this repository.
2) Install librdkafka with `git submodule update --init --recursive`
3) Install the dependencies `npm install`

### Reporting Bugs

Please use __Github Issues__ to report bugs. When filling out an issue report,
Expand Down Expand Up @@ -215,7 +224,7 @@ Steps to update:
```
Note: This is ran automatically during CI flows but it's good to run it during the version upgrade pull request.

1. Run `npm install --lockfile-version 2` to build with the new version and fix any build errors that occur.
1. Run `npm install` to build with the new version and fix any build errors that occur.

1. Run unit tests: `npm run test`

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ I am looking for *your* help to make this project even better! If you're interes

The `node-rdkafka` library is a high-performance NodeJS client for [Apache Kafka](http://kafka.apache.org/) that wraps the native [librdkafka](https://github.com/edenhill/librdkafka) library. All the complexity of balancing writes across partitions and managing (possibly ever-changing) brokers should be encapsulated in the library.

__This library currently uses `librdkafka` version `2.3.0`.__
__This library currently uses `librdkafka` version `2.6.0`.__

## Reference Docs

Expand All @@ -39,7 +39,7 @@ Play nice; Play fair.
## Requirements

* Apache Kafka >=0.9
* Node.js >=4
* Node.js >=16
* Linux/Mac
* Windows?! See below
* OpenSSL
Expand All @@ -65,7 +65,7 @@ Using Alpine Linux? Check out the [docs](https://github.com/Blizzard/node-rdkafk

### Windows

Windows build **is not** compiled from `librdkafka` source but it is rather linked against the appropriate version of [NuGet librdkafka.redist](https://www.nuget.org/packages/librdkafka.redist/) static binary that gets downloaded from `https://globalcdn.nuget.org/packages/librdkafka.redist.2.3.0.nupkg` during installation. This download link can be changed using the environment variable `NODE_RDKAFKA_NUGET_BASE_URL` that defaults to `https://globalcdn.nuget.org/packages/` when it's no set.
Windows build **is not** compiled from `librdkafka` source but it is rather linked against the appropriate version of [NuGet librdkafka.redist](https://www.nuget.org/packages/librdkafka.redist/) static binary that gets downloaded from `https://globalcdn.nuget.org/packages/librdkafka.redist.2.6.0.nupkg` during installation. This download link can be changed using the environment variable `NODE_RDKAFKA_NUGET_BASE_URL` that defaults to `https://globalcdn.nuget.org/packages/` when it's no set.

Requirements:
* [node-gyp for Windows](https://github.com/nodejs/node-gyp#on-windows)
Expand Down Expand Up @@ -102,7 +102,7 @@ const Kafka = require('node-rdkafka');

## Configuration

You can pass many configuration options to `librdkafka`. A full list can be found in `librdkafka`'s [Configuration.md](https://github.com/edenhill/librdkafka/blob/v2.3.0/CONFIGURATION.md)
You can pass many configuration options to `librdkafka`. A full list can be found in `librdkafka`'s [Configuration.md](https://github.com/edenhill/librdkafka/blob/v2.6.0/CONFIGURATION.md)

Configuration keys that have the suffix `_cb` are designated as callbacks. Some
of these keys are informational and you can choose to opt-in (for example, `dr_cb`). Others are callbacks designed to
Expand Down Expand Up @@ -137,7 +137,7 @@ You can also get the version of `librdkafka`
const Kafka = require('node-rdkafka');
console.log(Kafka.librdkafkaVersion);

// #=> 2.3.0
// #=> 2.6.0
```

## Sending Messages
Expand All @@ -150,7 +150,7 @@ const producer = new Kafka.Producer({
});
```

A `Producer` requires only `metadata.broker.list` (the Kafka brokers) to be created. The values in this list are separated by commas. For other configuration options, see the [Configuration.md](https://github.com/edenhill/librdkafka/blob/v2.3.0/CONFIGURATION.md) file described previously.
A `Producer` requires only `metadata.broker.list` (the Kafka brokers) to be created. The values in this list are separated by commas. For other configuration options, see the [Configuration.md](https://github.com/edenhill/librdkafka/blob/v2.6.0/CONFIGURATION.md) file described previously.

The following example illustrates a list with several `librdkafka` options set.

Expand Down Expand Up @@ -516,6 +516,7 @@ The following table lists events for this API.
|`data` | When using the Standard API consumed messages are emitted in this event. |
|`partition.eof` | When using Standard API and the configuration option `enable.partition.eof` is set, `partition.eof` events are emitted in this event. The event contains `topic`, `partition` and `offset` properties. |
|`warning` | The event is emitted in case of `UNKNOWN_TOPIC_OR_PART` or `TOPIC_AUTHORIZATION_FAILED` errors when consuming in *Flowing mode*. Since the consumer will continue working if the error is still happening, the warning event should reappear after the next metadata refresh. To control the metadata refresh rate set `topic.metadata.refresh.interval.ms` property. Once you resolve the error, you can manually call `getMetadata` to speed up consumer recovery. |
|`rebalance` | The `rebalance` event is emitted when the consumer group is rebalanced. <br><br>This event is only emitted if the `rebalance_cb` configuration is set to a function or set to `true` |
|`disconnected` | The `disconnected` event is emitted when the broker disconnects. <br><br>This event is only emitted when `.disconnect` is called. The wrapper will always try to reconnect otherwise. |
|`ready` | The `ready` event is emitted when the `Consumer` is ready to read messages. |
|`event` | The `event` event is emitted when `librdkafka` reports an event (if you opted in via the `event_cb` option).|
Expand Down
53 changes: 36 additions & 17 deletions config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ====== Generated from librdkafka 2.3.0 file CONFIGURATION.md ======
// ====== Generated from librdkafka 2.6.0 file CONFIGURATION.md ======
// Code that generated this is a derivative work of the code from Nam Nguyen
// https://gist.github.com/ntgn81/066c2c8ec5b4238f85d1e9168a04e3fb

Expand Down Expand Up @@ -620,12 +620,33 @@ export interface GlobalConfig {
"client.rack"?: string;

/**
* Controls how the client uses DNS lookups. By default, when the lookup returns multiple IP addresses for a hostname, they will all be attempted for connection before the connection is considered failed. This applies to both bootstrap and advertised servers. If the value is set to `resolve_canonical_bootstrap_servers_only`, each entry will be resolved and expanded into a list of canonical names. NOTE: Default here is different from the Java client's default behavior, which connects only to the first IP address returned for a hostname.
* The backoff time in milliseconds before retrying a protocol request, this is the first backoff time, and will be backed off exponentially until number of retries is exhausted, and it's capped by retry.backoff.max.ms.
*
* @default 100
*/
"retry.backoff.ms"?: number;

/**
* The max backoff time in milliseconds before retrying a protocol request, this is the atmost backoff allowed for exponentially backed off requests.
*
* @default 1000
*/
"retry.backoff.max.ms"?: number;

/**
* Controls how the client uses DNS lookups. By default, when the lookup returns multiple IP addresses for a hostname, they will all be attempted for connection before the connection is considered failed. This applies to both bootstrap and advertised servers. If the value is set to `resolve_canonical_bootstrap_servers_only`, each entry will be resolved and expanded into a list of canonical names. **WARNING**: `resolve_canonical_bootstrap_servers_only` must only be used with `GSSAPI` (Kerberos) as `sasl.mechanism`, as it's the only purpose of this configuration value. **NOTE**: Default here is different from the Java client's default behavior, which connects only to the first IP address returned for a hostname.
*
* @default use_all_dns_ips
*/
"client.dns.lookup"?: 'use_all_dns_ips' | 'resolve_canonical_bootstrap_servers_only';

/**
* Whether to enable pushing of client metrics to the cluster, if the cluster has a client metrics subscription which matches this client
*
* @default true
*/
"enable.metrics.push"?: boolean;

/**
* Enables or disables `event.*` emitting.
*
Expand Down Expand Up @@ -703,20 +724,6 @@ export interface ProducerGlobalConfig extends GlobalConfig {
*/
"retries"?: number;

/**
* The backoff time in milliseconds before retrying a protocol request, this is the first backoff time, and will be backed off exponentially until number of retries is exhausted, and it's capped by retry.backoff.max.ms.
*
* @default 100
*/
"retry.backoff.ms"?: number;

/**
* The max backoff time in milliseconds before retrying a protocol request, this is the atmost backoff allowed for exponentially backed off requests.
*
* @default 1000
*/
"retry.backoff.max.ms"?: number;

/**
* The threshold of outstanding not yet transmitted broker requests needed to backpressure the producer's message accumulator. If the number of not yet transmitted requests equals or exceeds this number, produce request creation that would have otherwise been triggered (for example, in accordance with linger.ms) will be delayed. A lower number yields larger and more effective batches. A higher value can improve latency when using compression on slow machines.
*
Expand Down Expand Up @@ -810,12 +817,24 @@ export interface ConsumerGlobalConfig extends GlobalConfig {
"heartbeat.interval.ms"?: number;

/**
* Group protocol type. NOTE: Currently, the only supported group protocol type is `consumer`.
* Group protocol type for the `classic` group protocol. NOTE: Currently, the only supported group protocol type is `consumer`.
*
* @default consumer
*/
"group.protocol.type"?: string;

/**
* Group protocol to use. Use `classic` for the original protocol and `consumer` for the new protocol introduced in KIP-848. Available protocols: classic or consumer. Default is `classic`, but will change to `consumer` in next releases.
*
* @default classic
*/
"group.protocol"?: 'classic' | 'consumer';

/**
* Server side assignor to use. Keep it null to make server select a suitable assignor for the group. Available assignors: uniform or range. Default is null
*/
"group.remote.assignor"?: string;

/**
* How often to query for the current client group coordinator. If the currently assigned coordinator is down the configured query interval will be divided by ten to more quickly recover in case of coordinator reassignment.
*
Expand Down
59 changes: 59 additions & 0 deletions e2e/both.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,65 @@ describe('Consumer/Producer', function() {
});
});

describe('Cooperative sticky', function() {
var consumer;

beforeEach(function(done) {
var grp = 'kafka-mocha-grp-' + crypto.randomBytes(20).toString('hex');

var consumerOpts = {
'metadata.broker.list': kafkaBrokerList,
'group.id': grp,
'fetch.wait.max.ms': 1000,
'session.timeout.ms': 10000,
'enable.auto.commit': false,
'debug': 'all',
'partition.assignment.strategy': 'cooperative-sticky'
};

consumer = new Kafka.KafkaConsumer(consumerOpts, {
'auto.offset.reset': 'largest',
});

consumer.connect({}, function(err, d) {
t.ifError(err);
t.equal(typeof d, 'object', 'metadata should be returned');
done();
});

eventListener(consumer);
});

afterEach(function(done) {
consumer.disconnect(function() {
done();
});
});

it('should be able to produce and consume messages', function (done) {
var key = 'key';

crypto.randomBytes(4096, function(ex, buffer) {
producer.setPollInterval(10);

consumer.on('data', function(message) {
t.equal(buffer.toString(), message.value.toString(), 'invalid message value');
t.equal(key, message.key, 'invalid message key');
t.equal(topic, message.topic, 'invalid message topic');
t.ok(message.offset >= 0, 'invalid message offset');
done();
});

consumer.subscribe([topic]);
consumer.consume();

setTimeout(function() {
producer.produce(topic, null, buffer, key);
}, 2000);
});
});
});

function assert_headers_match(expectedHeaders, messageHeaders) {
t.equal(expectedHeaders.length, messageHeaders.length, 'Headers length does not match expected length');
for (var i = 0; i < expectedHeaders.length; i++) {
Expand Down
39 changes: 39 additions & 0 deletions e2e/consumer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,43 @@ describe('Consumer', function() {
});

});

describe('rebalance protocol', function () {
var strategies = {
'undefined': 'EAGER',
'range': 'EAGER',
'roundrobin': 'EAGER',
'cooperative-sticky': 'COOPERATIVE',
};

Object.keys(strategies).forEach(function (strategy) {
it('should return ' + strategies[strategy] + ' for ' + strategy, function(done) {
var consumer = new KafkaConsumer({
...gcfg,
...(strategy !== 'undefined' && { 'partition.assignment.strategy': strategy })
}, {});

t.equal(consumer.rebalanceProtocol(), 'NONE');

consumer.connect({ timeout: 2000 }, function(err) {
t.ifError(err);

consumer.subscribe([topic]);

consumer.on('rebalance', function (err) {
if (err.code === -175) {
t.equal(consumer.rebalanceProtocol(), strategies[strategy]);
consumer.disconnect(done);
}
});

consumer.consume(1, function(err) {
t.ifError(err);
});
});

eventListener(consumer);
});
});
});
});
Loading
Loading