kafka-console 1.4.50 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -19
- package/build/cli.js +0 -0
- package/build/commands/config.js +1 -1
- package/build/commands/consume.js +5 -5
- package/build/commands/createTopic.js +1 -1
- package/build/commands/deleteTopic.js +1 -1
- package/build/commands/fetchTopicOffsets.js +1 -1
- package/build/commands/list.js +1 -1
- package/build/commands/metadata.js +1 -1
- package/build/commands/produce.js +4 -4
- package/build/index.js +12 -11
- package/build/utils/formatters.js +2 -2
- package/build/utils/kafka.js +29 -11
- package/build/utils/pool.js +2 -2
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ npm install -g kafka-console
|
|
|
41
41
|
-b, --brokers <brokers> bootstrap server host (default: "localhost:9092")
|
|
42
42
|
-l, --log-level <logLevel> log level
|
|
43
43
|
-t, --timeout <timeout> set a timeout of operation (default: "0")
|
|
44
|
-
-p, --pretty pretty print
|
|
44
|
+
-p, --pretty pretty print (default: false)
|
|
45
45
|
--ssl enable ssl (default: false)
|
|
46
46
|
--mechanism <mechanism> sasl mechanism
|
|
47
47
|
--username <username> sasl username
|
|
@@ -62,8 +62,9 @@ npm install -g kafka-console
|
|
|
62
62
|
metadata Displays kafka server metadata
|
|
63
63
|
list|ls [options] Lists kafka topics
|
|
64
64
|
config [options] Describes config for specific resource
|
|
65
|
-
create <topic>
|
|
66
|
-
delete <topic>
|
|
65
|
+
topic:create <topic> Creates kafka topic
|
|
66
|
+
topic:delete <topic> Deletes kafka topic
|
|
67
|
+
topic:offsets <topic> [timestamp] Shows kafka topic offsets
|
|
67
68
|
help [command] display help for command
|
|
68
69
|
```
|
|
69
70
|
|
|
@@ -73,13 +74,13 @@ npm install -g kafka-console
|
|
|
73
74
|
|
|
74
75
|
#### Options
|
|
75
76
|
```
|
|
76
|
-
-g, --group <group>
|
|
77
|
-
-
|
|
78
|
-
-o, --output <filename>
|
|
79
|
-
-
|
|
80
|
-
-c, --count <count>
|
|
81
|
-
-s, --skip <skip>
|
|
82
|
-
-h, --help
|
|
77
|
+
-g, --group <group> consumer group name (default: "kafka-console-consumer-TIMESTAMP")
|
|
78
|
+
-d, --data-format <data-format> messages data-format: json, js, raw (default: "json")
|
|
79
|
+
-o, --output <filename> write output to specified filename
|
|
80
|
+
-f, --from <from> read messages from the specific timestamp in milliseconds or ISO 8601 format. Set 0 to read from the beginning
|
|
81
|
+
-c, --count <count> a number of messages to read (default: null)
|
|
82
|
+
-s, --skip <skip> a number of messages to skip (default: 0)
|
|
83
|
+
-h, --help display help for command
|
|
83
84
|
```
|
|
84
85
|
|
|
85
86
|
General usage with authentication
|
|
@@ -87,14 +88,14 @@ General usage with authentication
|
|
|
87
88
|
kcli consume $KAFKA_TOPIC -g $KAFKA_TOPIC_GROUP -b $KAFKA_BROKERS --ssl --mechanism plain --username $KAFKA_USERNAME --password $KAFKA_PASSWORD
|
|
88
89
|
```
|
|
89
90
|
|
|
90
|
-
Stdout `jq` example
|
|
91
|
+
Stdout from timestamp `jq` example
|
|
91
92
|
```sh
|
|
92
|
-
kcli consume $KAFKA_TOPIC | jq .value
|
|
93
|
+
kcli consume $KAFKA_TOPIC --from '1970-01-01T00:00:00.000Z' | jq .value
|
|
93
94
|
```
|
|
94
95
|
|
|
95
96
|
Custom data formatter example
|
|
96
97
|
```sh
|
|
97
|
-
kcli consume $KAFKA_TOPIC --format ./formatter/avro.js | jq
|
|
98
|
+
kcli consume $KAFKA_TOPIC --data-format ./formatter/avro.js | jq
|
|
98
99
|
```
|
|
99
100
|
|
|
100
101
|
### Producer
|
|
@@ -103,11 +104,11 @@ kcli consume $KAFKA_TOPIC --format ./formatter/avro.js | jq
|
|
|
103
104
|
|
|
104
105
|
#### Options
|
|
105
106
|
```
|
|
106
|
-
-
|
|
107
|
-
-i, --input <filename>
|
|
108
|
-
-
|
|
109
|
-
-h, --header <header>
|
|
110
|
-
--help
|
|
107
|
+
-d, --data-format <data-format> messages data-format: json, js, raw (default: "json")
|
|
108
|
+
-i, --input <filename> input filename
|
|
109
|
+
-w, --wait <wait> wait the time in ms after sending a message (default: 0)
|
|
110
|
+
-h, --header <header> set a static header (default: [])
|
|
111
|
+
--help display help for command
|
|
111
112
|
```
|
|
112
113
|
|
|
113
114
|
General usage
|
|
@@ -117,7 +118,7 @@ kcli produce $KAFKA_TOPIC -b $KAFKA_BROKERS --ssl --mechanism plain --username $
|
|
|
117
118
|
|
|
118
119
|
Produce a json data from stdin with custom formatter
|
|
119
120
|
```sh
|
|
120
|
-
cat payload.txt|kcli produce $KAFKA_TOPIC --format ./formatter/avro.js
|
|
121
|
+
cat payload.txt|kcli produce $KAFKA_TOPIC --data-format ./formatter/avro.js
|
|
121
122
|
```
|
|
122
123
|
|
|
123
124
|
Produce a json data from stdin
|
package/build/cli.js
CHANGED
|
File without changes
|
package/build/commands/config.js
CHANGED
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.default = config;
|
|
24
23
|
const kafka_1 = require("../utils/kafka");
|
|
25
24
|
function config(opts_1, _a) {
|
|
26
25
|
return __awaiter(this, arguments, void 0, function* (opts, { parent }) {
|
|
@@ -44,3 +43,4 @@ function config(opts_1, _a) {
|
|
|
44
43
|
yield admin.disconnect();
|
|
45
44
|
});
|
|
46
45
|
}
|
|
46
|
+
exports.default = config;
|
|
@@ -50,25 +50,24 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
50
50
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.default = consume;
|
|
54
53
|
const Fs = __importStar(require("fs"));
|
|
55
54
|
const kafka_1 = require("../utils/kafka");
|
|
56
55
|
const formatters_1 = require("../utils/formatters");
|
|
57
56
|
function consume(topic_1, opts_1, _a) {
|
|
58
57
|
return __awaiter(this, arguments, void 0, function* (topic, opts, { parent }) {
|
|
59
58
|
var _b, e_1, _c, _d;
|
|
60
|
-
const _e = Object.assign(Object.assign({}, parent.opts()), opts), { group,
|
|
59
|
+
const _e = Object.assign(Object.assign({}, parent.opts()), opts), { group, dataFormat, from, count, skip, filename, brokers, logLevel, timeout, ssl, pretty } = _e, saslOptions = __rest(_e, ["group", "dataFormat", "from", "count", "skip", "filename", "brokers", "logLevel", "timeout", "ssl", "pretty"]);
|
|
61
60
|
const sasl = (0, kafka_1.getSASL)(saslOptions);
|
|
62
61
|
const client = (0, kafka_1.createClient)(brokers, ssl, sasl, logLevel);
|
|
63
62
|
const output = filename ? Fs.createWriteStream(filename) : process.stdout;
|
|
64
|
-
const consumer = yield (0, kafka_1.createConsumer)(client, group, topic,
|
|
63
|
+
const consumer = yield (0, kafka_1.createConsumer)(client, group, topic, from, { skip, count, timeout });
|
|
65
64
|
consumer.onDone((timeouted) => {
|
|
66
65
|
if (timeouted) {
|
|
67
|
-
console.
|
|
66
|
+
console.error("TIMEOUT");
|
|
68
67
|
process.exit(1);
|
|
69
68
|
}
|
|
70
69
|
});
|
|
71
|
-
const formatter = (0, formatters_1.getFormatter)(
|
|
70
|
+
const formatter = (0, formatters_1.getFormatter)(dataFormat);
|
|
72
71
|
try {
|
|
73
72
|
for (var _f = true, consumer_1 = __asyncValues(consumer), consumer_1_1; consumer_1_1 = yield consumer_1.next(), _b = consumer_1_1.done, !_b; _f = true) {
|
|
74
73
|
_d = consumer_1_1.value;
|
|
@@ -91,3 +90,4 @@ function consume(topic_1, opts_1, _a) {
|
|
|
91
90
|
}
|
|
92
91
|
});
|
|
93
92
|
}
|
|
93
|
+
exports.default = consume;
|
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.default = createTopic;
|
|
24
23
|
const kafka_1 = require("../utils/kafka");
|
|
25
24
|
function createTopic(topic_1, opts_1, _a) {
|
|
26
25
|
return __awaiter(this, arguments, void 0, function* (topic, opts, { parent }) {
|
|
@@ -36,3 +35,4 @@ function createTopic(topic_1, opts_1, _a) {
|
|
|
36
35
|
yield admin.disconnect();
|
|
37
36
|
});
|
|
38
37
|
}
|
|
38
|
+
exports.default = createTopic;
|
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.default = deleteTopic;
|
|
24
23
|
const kafka_1 = require("../utils/kafka");
|
|
25
24
|
function deleteTopic(topic_1, opts_1, _a) {
|
|
26
25
|
return __awaiter(this, arguments, void 0, function* (topic, opts, { parent }) {
|
|
@@ -34,3 +33,4 @@ function deleteTopic(topic_1, opts_1, _a) {
|
|
|
34
33
|
yield admin.disconnect();
|
|
35
34
|
});
|
|
36
35
|
}
|
|
36
|
+
exports.default = deleteTopic;
|
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.default = fetchTopicOffset;
|
|
24
23
|
const kafka_1 = require("../utils/kafka");
|
|
25
24
|
function fetchTopicOffset(topic_1, timestamp_1, opts_1, _a) {
|
|
26
25
|
return __awaiter(this, arguments, void 0, function* (topic, timestamp, opts, { parent }) {
|
|
@@ -44,3 +43,4 @@ function fetchTopicOffset(topic_1, timestamp_1, opts_1, _a) {
|
|
|
44
43
|
yield admin.disconnect();
|
|
45
44
|
});
|
|
46
45
|
}
|
|
46
|
+
exports.default = fetchTopicOffset;
|
package/build/commands/list.js
CHANGED
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.default = list;
|
|
24
23
|
const kafka_1 = require("../utils/kafka");
|
|
25
24
|
function list(opts_1, _a) {
|
|
26
25
|
return __awaiter(this, arguments, void 0, function* (opts, { parent }) {
|
|
@@ -36,3 +35,4 @@ function list(opts_1, _a) {
|
|
|
36
35
|
yield cluster.disconnect();
|
|
37
36
|
});
|
|
38
37
|
}
|
|
38
|
+
exports.default = list;
|
|
@@ -20,7 +20,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.default = metadata;
|
|
24
23
|
const kafka_1 = require("../utils/kafka");
|
|
25
24
|
function metadata(opts_1, _a) {
|
|
26
25
|
return __awaiter(this, arguments, void 0, function* (opts, { parent }) {
|
|
@@ -34,3 +33,4 @@ function metadata(opts_1, _a) {
|
|
|
34
33
|
yield cluster.disconnect();
|
|
35
34
|
});
|
|
36
35
|
}
|
|
36
|
+
exports.default = metadata;
|
|
@@ -53,7 +53,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
53
53
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
54
54
|
};
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
|
-
exports.default = produce;
|
|
57
56
|
const Fs = __importStar(require("fs"));
|
|
58
57
|
const stream_1 = require("stream");
|
|
59
58
|
const readline_1 = require("readline");
|
|
@@ -85,7 +84,7 @@ function getInput(filename) {
|
|
|
85
84
|
function produce(topic_1, opts_1, _a) {
|
|
86
85
|
return __awaiter(this, arguments, void 0, function* (topic, opts, { parent }) {
|
|
87
86
|
var _b, e_1, _c, _d;
|
|
88
|
-
const _e = Object.assign(Object.assign({}, parent.opts()), opts), {
|
|
87
|
+
const _e = Object.assign(Object.assign({}, parent.opts()), opts), { dataFormat, header, input: filename, wait, brokers, logLevel, ssl } = _e, rest = __rest(_e, ["dataFormat", "header", "input", "wait", "brokers", "logLevel", "ssl"]);
|
|
89
88
|
const sasl = (0, kafka_1.getSASL)(rest);
|
|
90
89
|
const client = (0, kafka_1.createClient)(brokers, ssl, sasl, logLevel);
|
|
91
90
|
const producer = yield (0, kafka_1.createProducer)(client, topic);
|
|
@@ -99,7 +98,7 @@ function produce(topic_1, opts_1, _a) {
|
|
|
99
98
|
}
|
|
100
99
|
return result;
|
|
101
100
|
}, {});
|
|
102
|
-
const formatter = (0, formatters_1.getFormatter)(
|
|
101
|
+
const formatter = (0, formatters_1.getFormatter)(dataFormat);
|
|
103
102
|
const input = yield getInput(filename);
|
|
104
103
|
try {
|
|
105
104
|
for (var _f = true, input_1 = __asyncValues(input), input_1_1; input_1_1 = yield input_1.next(), _b = input_1_1.done, !_b; _f = true) {
|
|
@@ -109,7 +108,7 @@ function produce(topic_1, opts_1, _a) {
|
|
|
109
108
|
const encodedValue = yield formatter.encode(value);
|
|
110
109
|
const message = { key, value: encodedValue, headers: Object.assign(Object.assign({}, staticHeaders), headers) };
|
|
111
110
|
producer.push(message);
|
|
112
|
-
yield new Promise(resolve => setTimeout(resolve,
|
|
111
|
+
yield new Promise(resolve => setTimeout(resolve, wait));
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -122,3 +121,4 @@ function produce(topic_1, opts_1, _a) {
|
|
|
122
121
|
producer.done();
|
|
123
122
|
});
|
|
124
123
|
}
|
|
124
|
+
exports.default = produce;
|
package/build/index.js
CHANGED
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.collect =
|
|
7
|
-
exports.toInt = toInt;
|
|
6
|
+
exports.toInt = exports.collect = void 0;
|
|
8
7
|
const commander_1 = require("commander");
|
|
9
8
|
const kafka_1 = require("./utils/kafka");
|
|
10
9
|
const consume_1 = __importDefault(require("./commands/consume"));
|
|
@@ -19,9 +18,11 @@ const { version } = require('../package.json');
|
|
|
19
18
|
function collect(value, result) {
|
|
20
19
|
return result.concat([value]);
|
|
21
20
|
}
|
|
21
|
+
exports.collect = collect;
|
|
22
22
|
function toInt(value, result) {
|
|
23
23
|
return parseInt(value, 10);
|
|
24
24
|
}
|
|
25
|
+
exports.toInt = toInt;
|
|
25
26
|
const commander = new commander_1.Command();
|
|
26
27
|
commander
|
|
27
28
|
.option('-b, --brokers <brokers>', 'bootstrap server host', process.env.KAFKA_BROKERS || 'localhost:9092')
|
|
@@ -40,19 +41,19 @@ commander
|
|
|
40
41
|
.version(version);
|
|
41
42
|
commander
|
|
42
43
|
.command('consume <topic>')
|
|
43
|
-
.requiredOption('-g, --group <group>', 'consumer group name')
|
|
44
|
-
.option('-
|
|
44
|
+
.requiredOption('-g, --group <group>', 'consumer group name', `kafka-console-consumer-${Date.now()}`)
|
|
45
|
+
.option('-d, --data-format <data-format>', 'messages data-format: json, js, raw', 'json')
|
|
45
46
|
.option('-o, --output <filename>', 'write output to specified filename')
|
|
46
|
-
.option('-
|
|
47
|
+
.option('-f, --from <from>', 'read messages from the specific timestamp in milliseconds or ISO 8601 format. Set 0 to read from the beginning')
|
|
47
48
|
.option('-c, --count <count>', 'a number of messages to read', toInt, Infinity)
|
|
48
49
|
.option('-s, --skip <skip>', 'a number of messages to skip', toInt, 0)
|
|
49
50
|
.description('Consume kafka topic events')
|
|
50
51
|
.action(consume_1.default);
|
|
51
52
|
commander
|
|
52
53
|
.command('produce <topic>')
|
|
53
|
-
.option('-
|
|
54
|
+
.option('-d, --data-format <data-format>', 'messages data-format: json, js, raw', 'json')
|
|
54
55
|
.option('-i, --input <filename>', 'input filename')
|
|
55
|
-
.option('-
|
|
56
|
+
.option('-w, --wait <wait>', 'wait the time in ms after sending a message', toInt, 0)
|
|
56
57
|
.option('-h, --header <header>', 'set a static header', collect, [])
|
|
57
58
|
.description('Produce kafka topic events')
|
|
58
59
|
.action(produce_1.default);
|
|
@@ -90,16 +91,16 @@ commander.on('--help', function () {
|
|
|
90
91
|
'Examples:',
|
|
91
92
|
'',
|
|
92
93
|
' General consumer usage',
|
|
93
|
-
' $
|
|
94
|
+
' $ npx kafka-console -b $KAFKA_BROKERS consume $KAFKA_TOPIC -g $KAFKA_TOPIC_GROUP --ssl --mechanism plain --username $KAFKA_USERNAME --password $KAFKA_PASSWORD',
|
|
94
95
|
'',
|
|
95
96
|
' Extracting consumer output with jq',
|
|
96
|
-
' $
|
|
97
|
+
' $ npx kafka-console consume $KAFKA_TOPIC -g $KAFKA_TOPIC_GROUP --f ./formatter/avro.js | jq .value',
|
|
97
98
|
'',
|
|
98
99
|
' General producer usage',
|
|
99
|
-
' $
|
|
100
|
+
' $ npx kafka-console produce $KAFKA_TOPIC -b $KAFKA_BROKERS --ssl --mechanism plain --username $KAFKA_USERNAME --password $KAFKA_PASSWORD',
|
|
100
101
|
'',
|
|
101
102
|
' Preparing producer payload json data with jq',
|
|
102
|
-
' $ cat payload.json|jq -r -c .[]|
|
|
103
|
+
' $ cat payload.json|jq -r -c .[]|npx kafka-console produce $KAFKA_TOPIC -f ./formatter/avro.js',
|
|
103
104
|
'',
|
|
104
105
|
].forEach(msg => console.log(msg));
|
|
105
106
|
});
|
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.raw = exports.js = exports.json = void 0;
|
|
7
|
-
exports.getFormatter = getFormatter;
|
|
6
|
+
exports.getFormatter = exports.raw = exports.js = exports.json = void 0;
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const vm_1 = require("vm");
|
|
10
9
|
exports.json = {
|
|
@@ -36,3 +35,4 @@ function getFormatter(format) {
|
|
|
36
35
|
return require(modulePath);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
38
|
+
exports.getFormatter = getFormatter;
|
package/build/utils/kafka.js
CHANGED
|
@@ -19,14 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.logLevelParser =
|
|
23
|
-
exports.resourceParser = resourceParser;
|
|
24
|
-
exports.getSASL = getSASL;
|
|
25
|
-
exports.createClient = createClient;
|
|
26
|
-
exports.createCluster = createCluster;
|
|
27
|
-
exports.createAdmin = createAdmin;
|
|
28
|
-
exports.createConsumer = createConsumer;
|
|
29
|
-
exports.createProducer = createProducer;
|
|
22
|
+
exports.createProducer = exports.createConsumer = exports.createAdmin = exports.createCluster = exports.createClient = exports.getSASL = exports.resourceParser = exports.logLevelParser = void 0;
|
|
30
23
|
const kafkajs_1 = require("kafkajs");
|
|
31
24
|
const pool_1 = __importDefault(require("./pool"));
|
|
32
25
|
function logLevelParser(level) {
|
|
@@ -44,6 +37,7 @@ function logLevelParser(level) {
|
|
|
44
37
|
}
|
|
45
38
|
return kafkajs_1.logLevel.NOTHING;
|
|
46
39
|
}
|
|
40
|
+
exports.logLevelParser = logLevelParser;
|
|
47
41
|
function resourceParser(resource) {
|
|
48
42
|
if (/^any$/i.test(resource)) {
|
|
49
43
|
return kafkajs_1.ConfigResourceTypes.UNKNOWN;
|
|
@@ -62,6 +56,7 @@ function resourceParser(resource) {
|
|
|
62
56
|
}
|
|
63
57
|
return kafkajs_1.ConfigResourceTypes.UNKNOWN;
|
|
64
58
|
}
|
|
59
|
+
exports.resourceParser = resourceParser;
|
|
65
60
|
const SASLMap = {
|
|
66
61
|
'plain': (username, password) => ({ username, password }),
|
|
67
62
|
'scram-sha-256': (username, password) => ({ username, password }),
|
|
@@ -80,6 +75,7 @@ function getSASL({ mechanism, username, password, authorizationIdentity, accessK
|
|
|
80
75
|
return { mechanism, oauthBearerProvider };
|
|
81
76
|
}
|
|
82
77
|
}
|
|
78
|
+
exports.getSASL = getSASL;
|
|
83
79
|
function createClient(bootstrapServer, ssl, sasl, level) {
|
|
84
80
|
const options = {
|
|
85
81
|
clientId: 'Kafka CLI',
|
|
@@ -90,6 +86,7 @@ function createClient(bootstrapServer, ssl, sasl, level) {
|
|
|
90
86
|
};
|
|
91
87
|
return new kafkajs_1.Kafka(options);
|
|
92
88
|
}
|
|
89
|
+
exports.createClient = createClient;
|
|
93
90
|
function createCluster(client) {
|
|
94
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
92
|
const createClusterKey = Reflect.ownKeys(client).find(key => /createCluster/.test(key.toString()));
|
|
@@ -99,6 +96,7 @@ function createCluster(client) {
|
|
|
99
96
|
return cluster;
|
|
100
97
|
});
|
|
101
98
|
}
|
|
99
|
+
exports.createCluster = createCluster;
|
|
102
100
|
function createAdmin(client) {
|
|
103
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
104
102
|
const admin = client.admin();
|
|
@@ -106,15 +104,30 @@ function createAdmin(client) {
|
|
|
106
104
|
return admin;
|
|
107
105
|
});
|
|
108
106
|
}
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
exports.createAdmin = createAdmin;
|
|
108
|
+
function createConsumer(client_1, group_1, topic_1, from_1) {
|
|
109
|
+
return __awaiter(this, arguments, void 0, function* (client, group, topic, from, poolOptions = {}) {
|
|
111
110
|
const consumerConfig = {
|
|
112
111
|
groupId: group,
|
|
113
112
|
};
|
|
114
113
|
const consumerOptions = {
|
|
115
114
|
topics: [topic],
|
|
116
|
-
fromBeginning,
|
|
115
|
+
fromBeginning: from === '0',
|
|
117
116
|
};
|
|
117
|
+
const offsets = [];
|
|
118
|
+
if (from && from !== '0') {
|
|
119
|
+
const timestamp = /^\d+$/.test(from)
|
|
120
|
+
? new Date(parseInt(from, 10)).getTime()
|
|
121
|
+
: Date.parse(from);
|
|
122
|
+
if (Number.isNaN(timestamp)) {
|
|
123
|
+
throw new Error(`Invalid timestamp "${from}"`);
|
|
124
|
+
}
|
|
125
|
+
const admin = yield createAdmin(client);
|
|
126
|
+
const partitionOffsets = yield admin.fetchTopicOffsetsByTimestamp(topic, timestamp);
|
|
127
|
+
for (const { partition, offset } of partitionOffsets) {
|
|
128
|
+
offsets.push({ topic, partition, offset });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
118
131
|
const consumer = client.consumer(consumerConfig);
|
|
119
132
|
yield consumer.connect();
|
|
120
133
|
yield consumer.subscribe(consumerOptions);
|
|
@@ -123,6 +136,9 @@ function createConsumer(client_1, group_1, topic_1) {
|
|
|
123
136
|
pool.push(payload);
|
|
124
137
|
}),
|
|
125
138
|
}).catch(e => console.error(e));
|
|
139
|
+
for (const offset of offsets) {
|
|
140
|
+
consumer.seek(offset);
|
|
141
|
+
}
|
|
126
142
|
const pool = new pool_1.default([], poolOptions);
|
|
127
143
|
pool.onDone(() => {
|
|
128
144
|
consumer.disconnect();
|
|
@@ -130,6 +146,7 @@ function createConsumer(client_1, group_1, topic_1) {
|
|
|
130
146
|
return pool;
|
|
131
147
|
});
|
|
132
148
|
}
|
|
149
|
+
exports.createConsumer = createConsumer;
|
|
133
150
|
function createProducer(client, topic) {
|
|
134
151
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
152
|
const producer = client.producer();
|
|
@@ -162,3 +179,4 @@ function createProducer(client, topic) {
|
|
|
162
179
|
return pool;
|
|
163
180
|
});
|
|
164
181
|
}
|
|
182
|
+
exports.createProducer = createProducer;
|
package/build/utils/pool.js
CHANGED
|
@@ -19,8 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.CancelToken = void 0;
|
|
23
|
-
exports.createItem = createItem;
|
|
22
|
+
exports.CancelToken = exports.createItem = void 0;
|
|
24
23
|
const evnty_1 = __importDefault(require("evnty"));
|
|
25
24
|
function createItem() {
|
|
26
25
|
const result = {};
|
|
@@ -30,6 +29,7 @@ function createItem() {
|
|
|
30
29
|
});
|
|
31
30
|
return result;
|
|
32
31
|
}
|
|
32
|
+
exports.createItem = createItem;
|
|
33
33
|
class CancelToken {
|
|
34
34
|
constructor(timeout) {
|
|
35
35
|
this.timeout = timeout;
|
package/package.json
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-console",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Kafka CLI tool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"kcli": "build/cli.js",
|
|
8
8
|
"kafka-console": "build/cli.js"
|
|
9
9
|
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "rm -rf build && tsc",
|
|
12
|
-
"test": "NODE_ENV=test jest",
|
|
13
|
-
"test:cov": "COVERAGE=1 NODE_ENV=test jest",
|
|
14
|
-
"kcli": "ts-node src/index.ts"
|
|
15
|
-
},
|
|
16
10
|
"repository": {
|
|
17
11
|
"type": "git",
|
|
18
12
|
"url": "git+https://github.com/3axap4eHko/kafka-console.git"
|
|
@@ -45,5 +39,11 @@
|
|
|
45
39
|
"commander": "^12.1.0",
|
|
46
40
|
"evnty": "^2.1.106",
|
|
47
41
|
"kafkajs": "^2.2.4"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "rm -rf build && tsc",
|
|
45
|
+
"test": "NODE_ENV=test jest",
|
|
46
|
+
"test:cov": "COVERAGE=1 NODE_ENV=test jest",
|
|
47
|
+
"kcli": "ts-node src/index.ts"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|