2023-08-29 14:34:04 +03:00
|
|
|
{ pkgs, config, ... }: {
|
|
|
|
services.zookeeper."z1".enable = true;
|
2023-09-06 17:24:51 +03:00
|
|
|
# To avoid conflicting with `zookeeper_test.nix` in case the tests are run in parallel
|
|
|
|
services.zookeeper."z1".port = 2182;
|
2024-01-16 12:05:05 +03:00
|
|
|
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";
|
2023-08-29 14:34:04 +03:00
|
|
|
settings.processes.test =
|
|
|
|
{
|
|
|
|
command = pkgs.writeShellApplication {
|
2023-09-06 17:24:51 +03:00
|
|
|
runtimeInputs = [ pkgs.bash config.services.apache-kafka.k1.package ];
|
2023-08-29 14:34:04 +03:00
|
|
|
text = ''
|
2024-01-16 12:05:05 +03:00
|
|
|
# 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"
|
2023-08-29 14:34:04 +03:00
|
|
|
'';
|
|
|
|
name = "kafka-test";
|
|
|
|
};
|
|
|
|
depends_on."k1".condition = "process_healthy";
|
|
|
|
};
|
|
|
|
}
|