feat: Start kafka as a service

This commit is contained in:
Alexander Kobjolke 2024-11-09 23:00:15 +01:00
parent 805d018187
commit 8e9179d319
2 changed files with 286 additions and 11 deletions

View file

@ -7,12 +7,13 @@
}:
{
imports = [ ];
imports = [ ./nix/kafka.nix ];
# https://devenv.sh/packages/
packages = [
pkgs.git
pkgs.jetbrains.idea-community-bin
pkgs.yaml-language-server
];
languages.java.enable = true;
@ -22,11 +23,83 @@
# https://devenv.sh/processes/
# processes.cargo-watch.exec = "cargo-watch";
processes.flexinale-monolith.exec = ''
java -Dspring.datasource.url=jdbc:postgresql://localhost:5432/monolith -jar flex-training-flexinale/flexinale-monolith/target/flexinale-monolith-2024.3.0-spring-boot-fat-jar.jar
'';
scripts =
let
datasource = "-Dspring.datasource.url=jdbc:postgresql://${config.services.postgres.listen_addresses}:5432";
startFlexinale = name: db: ''
java ${datasource}/${db} -jar flex-training-flexinale/flexinale-${name}/target/flexinale-${name}-2024.3.0-spring-boot-fat-jar.jar
'';
in
{
"monolith-run".exec = startFlexinale "monolith" "monolith";
"modulith-1-run".exec = startFlexinale "modulith-1-onion" "modulith-1";
"modulith-2-run".exec = startFlexinale "modulith-2-components" "modulith-2";
"monolith-init".exec = ''
cd ${config.env.DEVENV_ROOT}/flex-training-flexinale
mvn test -Dtest=testdata.TestDataLoader -pl flexinale-monolith -am
'';
"modulith-1-init".exec = ''
cd ${config.env.DEVENV_ROOT}/flex-training-flexinale
mvn test -Dtest=testdata.TestDataLoader -pl flexinale-modulith-1-onion -am
'';
"modulith-2-init".exec = ''
cd ${config.env.DEVENV_ROOT}/flex-training-flexinale
mvn test -Dtest=testdata.AllTestDataLoader -pl flexinale-modulith-2-components -am
'';
"distributed-init".exec = ''
cd ${config.env.DEVENV_ROOT}/flex-training-flexinale
mvn test -Dtest=testdata.AllTestDataLoader -pl flexinale-distributed -am
'';
"distributed-portal".exec = ''
java ${datasource}/distributed-besucherportal \
-Dbootstrap.servers=localhost:29092 \
-Dspring.kafka.consumer.bootstrap-servers=localhost:29092 \
-Dspring.kafka.producer.bootstrap-servers=localhost:29092 \
-jar flex-training-flexinale/flexinale-distributed/flexinale-distributed-besucherportal/target/flexinale-distributed-besucherportal-2024.3.0-spring-boot-fat-jar.jar
'';
"distributed-backoffice".exec = ''
java ${datasource}/distributed-backoffice \
-Dbootstrap.servers=localhost:29092 \
-Dspring.kafka.consumer.bootstrap-servers=localhost:29092 \
-Dspring.kafka.producer.bootstrap-servers=localhost:29092 \
-jar flex-training-flexinale/flexinale-distributed/flexinale-distributed-backoffice/target/flexinale-distributed-backoffice-2024.3.0-spring-boot-fat-jar.jar
'';
"distributed-ticketing".exec = ''
java ${datasource}/distributed-ticketing \
-Dbootstrap.servers=localhost:29092 \
-Dspring.kafka.consumer.bootstrap-servers=localhost:29092 \
-Dspring.kafka.producer.bootstrap-servers=localhost:29092 \
-jar flex-training-flexinale/flexinale-distributed/flexinale-distributed-ticketing/target/flexinale-distributed-ticketing-2024.3.0-spring-boot-fat-jar.jar
'';
};
services.apache-kafka = {
enable = true;
clusterId = "foobar";
settings = {
"broker.id" = 1;
"node.id" = 1;
"process.roles" = [
"broker"
"controller"
];
"listeners" = [
"PLAINTEXT://:9092"
"FLEXINALE://:29092"
"CONTROLLER://:9093"
];
"listener.security.protocol.map" = [
"PLAINTEXT:PLAINTEXT"
"FLEXINALE:PLAINTEXT"
"CONTROLLER:PLAINTEXT"
];
"controller.quorum.voters" = [
"1@localhost:9093"
];
"controller.listener.names" = [ "CONTROLLER" ];
};
};
# https://devenv.sh/services/
services.postgres = {
enable = true;
listen_addresses = "127.0.0.1";
@ -51,12 +124,6 @@
]);
};
# https://devenv.sh/scripts/
scripts.monolith-load.exec = ''
cd ${config.env.DEVENV_ROOT}/flex-training-flexinale
mvn test -Dtest=testdata.TestDataLoader -pl flexinale-monolith -am
'';
# https://devenv.sh/tests/
enterTest = ''
echo "Running tests"