-
Notifications
You must be signed in to change notification settings - Fork 20
/
apache-kafka_test.nix
36 lines (34 loc) · 1.28 KB
/
apache-kafka_test.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{ pkgs, config, ... }: {
services.zookeeper."z1".enable = true;
# To avoid conflicting with `zookeeper_test.nix` in case the tests are run in parallel
services.zookeeper."z1".port = 2182;
services.apache-kafka."k1" = {
enable = true;
port = 9094;
settings = {
# Since the available brokers are only 1
"offsets.topic.replication.factor" = 1;
"zookeeper.connect" = [ "localhost:2182" ];
};
};
# kafka should start only after zookeeper is healthy
settings.processes.k1.depends_on."z1".condition = "process_healthy";
settings.processes.test =
{
command = pkgs.writeShellApplication {
runtimeInputs = [ pkgs.bash config.services.apache-kafka.k1.package ];
text = ''
# Create a topic
kafka-topics.sh --create --bootstrap-server localhost:9094 --partitions 1 \
--replication-factor 1 --topic testtopic
# Producer
echo 'test 1' | kafka-console-producer.sh --broker-list localhost:9094 --topic testtopic
# Consumer
kafka-console-consumer.sh --bootstrap-server localhost:9094 --topic testtopic \
--from-beginning --max-messages 1 | grep -q "test 1"
'';
name = "kafka-test";
};
depends_on."k1".condition = "process_healthy";
};
}