-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sarama and kafkajs drivers (#1690)
- Loading branch information
Showing
10 changed files
with
272 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::path::Path; | ||
|
||
pub async fn run_node_smoke_test(address: &str) { | ||
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/connection/kafka/node"); | ||
let config = format!( | ||
r#"({{ | ||
clientId: 'nodejs-client', | ||
brokers: ["{address}"], | ||
}})"# | ||
); | ||
run_command(&dir, "npm", &["install"]).await; | ||
run_command(&dir, "npm", &["start", &config]).await; | ||
} | ||
|
||
pub async fn run_node_smoke_test_scram(address: &str, user: &str, password: &str) { | ||
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/connection/kafka/node"); | ||
let config = format!( | ||
r#"({{ | ||
clientId: 'nodejs-client', | ||
brokers: ["{address}"], | ||
sasl: {{ | ||
mechanism: 'scram-sha-256', | ||
username: '{user}', | ||
password: '{password}' | ||
}} | ||
}})"# | ||
); | ||
run_command(&dir, "npm", &["install"]).await; | ||
run_command(&dir, "npm", &["start", &config]).await; | ||
} | ||
|
||
async fn run_command(current_dir: &Path, command: &str, args: &[&str]) -> String { | ||
let output = tokio::process::Command::new(command) | ||
.args(args) | ||
.current_dir(current_dir) | ||
.output() | ||
.await | ||
.unwrap(); | ||
|
||
let stdout = String::from_utf8(output.stdout).unwrap(); | ||
let stderr = String::from_utf8(output.stderr).unwrap(); | ||
if !output.status.success() { | ||
panic!("command {command} {args:?} failed:\nstdout:\n{stdout}\nstderr:\n{stderr}") | ||
} | ||
stdout | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const { Kafka } = require('kafkajs') | ||
const fs = require('fs') | ||
const assert = require('assert') | ||
|
||
function delay(time) { | ||
return new Promise(resolve => setTimeout(resolve, time)); | ||
} | ||
|
||
const run = async () => { | ||
const args = process.argv.slice(2); | ||
const config = args[0]; | ||
|
||
const kafka = new Kafka(eval(config)) | ||
|
||
// Producing | ||
const producer = kafka.producer() | ||
await producer.connect() | ||
await producer.send({ | ||
topic: 'test', | ||
messages: [ | ||
{ value: 'foo' }, | ||
], | ||
}) | ||
await producer.send({ | ||
topic: 'test', | ||
messages: [ | ||
{ value: 'a longer string' }, | ||
], | ||
}) | ||
await producer.disconnect() | ||
|
||
// Consuming | ||
const consumer = kafka.consumer({ groupId: 'test-group' }) | ||
await consumer.connect() | ||
await consumer.subscribe({ topic: 'test', fromBeginning: true }) | ||
|
||
messages = [] | ||
await consumer.run({ | ||
eachMessage: async ({ topic, partition, message }) => { | ||
messages.push({ | ||
topic, | ||
partition, | ||
offset: message.offset, | ||
value: message.value.toString(), | ||
}) | ||
}, | ||
}) | ||
|
||
// Use a very primitive sleep loop since nodejs doesnt seem to have any kind of mpsc or channel functionality :/ | ||
while (messages.length < 2) { | ||
await delay(10); | ||
} | ||
assert.deepStrictEqual(messages, [ | ||
{ | ||
topic: 'test', | ||
partition: 0, | ||
offset: '0', | ||
value: 'foo', | ||
}, | ||
{ | ||
topic: 'test', | ||
partition: 0, | ||
offset: '1', | ||
value: 'a longer string', | ||
} | ||
]) | ||
await consumer.disconnect() | ||
} | ||
|
||
run() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "kafkajs_wrapper", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"description": "", | ||
"dependencies": { | ||
"kafkajs": "^2.2.4" | ||
} | ||
} |