diff --git a/infrastructure/docker/docker-compose.yml b/infrastructure/docker/docker-compose.yml index 42bc1fea..699d8325 100644 --- a/infrastructure/docker/docker-compose.yml +++ b/infrastructure/docker/docker-compose.yml @@ -71,6 +71,7 @@ services: - habit-db environment: DB_HOST: habit-db + KAFKA_BOOTSTRAP_SERVERS: kafka:11001 networks: - habitcentric-net habit-db: @@ -124,8 +125,8 @@ services: - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:11001,EXTERNAL://localhost:11003 - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:11002 - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER - - KAFKA_CLIENT_USERS=track,kafka-ui - - KAFKA_CLIENT_PASSWORDS=track,kafka-ui + - KAFKA_CLIENT_USERS=habit,track,kafka-ui + - KAFKA_CLIENT_PASSWORDS=habit,track,kafka-ui networks: - habitcentric-net kafka-ui: diff --git a/infrastructure/istio/config/23-mtls-authz-policies.yaml b/infrastructure/istio/config/23-mtls-authz-policies.yaml index 9c85bb02..a7706072 100644 --- a/infrastructure/istio/config/23-mtls-authz-policies.yaml +++ b/infrastructure/istio/config/23-mtls-authz-policies.yaml @@ -64,6 +64,7 @@ spec: - from: - source: principals: + - cluster.local/ns/hc-habit/sa/habit - cluster.local/ns/hc-track/sa/track --- apiVersion: security.istio.io/v1beta1 diff --git a/infrastructure/kubernetes/helmfile.d/values/habit-values.yaml.gotmpl b/infrastructure/kubernetes/helmfile.d/values/habit-values.yaml.gotmpl index 624706c5..0bb9729f 100644 --- a/infrastructure/kubernetes/helmfile.d/values/habit-values.yaml.gotmpl +++ b/infrastructure/kubernetes/helmfile.d/values/habit-values.yaml.gotmpl @@ -18,8 +18,10 @@ image: ## habitcentric habit service configuration -{{- if (eq .Environment.Name "traefik-mesh") }} extraEnv: + - name: KAFKA_BOOTSTRAP_SERVERS + value: kafka.hc-kafka.svc.cluster.local:9092 +{{- if (eq .Environment.Name "traefik-mesh") }} - name: MANAGEMENT_ZIPKIN_TRACING_ENDPOINT value: http://jaeger-collector.traefik-mesh.svc.cluster.local:9411 {{- end }} diff --git a/infrastructure/kubernetes/helmfile.d/values/kafka-values.yaml.gotmpl b/infrastructure/kubernetes/helmfile.d/values/kafka-values.yaml.gotmpl index 3834ccdb..bbf8bb82 100644 --- a/infrastructure/kubernetes/helmfile.d/values/kafka-values.yaml.gotmpl +++ b/infrastructure/kubernetes/helmfile.d/values/kafka-values.yaml.gotmpl @@ -10,8 +10,10 @@ sasl: password: "kafka" client: users: + - "habit" - "track" passwords: + - "habit" - "track" externalAccess: diff --git a/services/habit/docker-compose.yml b/services/habit/docker-compose.yml index 61428a4a..11ba1522 100644 --- a/services/habit/docker-compose.yml +++ b/services/habit/docker-compose.yml @@ -8,3 +8,31 @@ services: environment: POSTGRESQL_PASSWORD: postgres POSTGRESQL_PORT_NUMBER: 10001 + + kafka: + image: 'bitnami/kafka:latest' + ports: + - "11003:11003" + environment: + - KAFKA_CFG_NODE_ID=0 + - KAFKA_CFG_PROCESS_ROLES=controller,broker + - KAFKA_CFG_LISTENERS=PLAINTEXT://:11001,CONTROLLER://:11002,EXTERNAL://:11003 + - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT + - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:11001,EXTERNAL://localhost:11003 + - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:11002 + - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER + - KAFKA_CLIENT_USERS=habit,kafka-ui + - KAFKA_CLIENT_PASSWORDS=habit,kafka-ui + + kafka-ui: + container_name: kafka-ui + image: provectuslabs/kafka-ui:latest + ports: + - "11004:11004" + environment: + SERVER_PORT: 11004 + DYNAMIC_CONFIG_ENABLED: 'true' + KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:11001 + KAFKA_CLUSTERS_0_PROPERTIES_SECURITY_PROTOCOL: SASL_PLAINTEXT + KAFKA_CLUSTERS_0_PROPERTIES_SASL_MECHANISM: PLAIN + KAFKA_CLUSTERS_0_PROPERTIES_SASL_JAAS_CONFIG: 'org.apache.kafka.common.security.plain.PlainLoginModule required username="kafka-ui" password="kafka-ui";' diff --git a/services/habit/src/main/java/de/codecentric/hc/habit/habits/Habit.java b/services/habit/src/main/java/de/codecentric/hc/habit/habits/Habit.java index 9aa0eecd..7df6b058 100644 --- a/services/habit/src/main/java/de/codecentric/hc/habit/habits/Habit.java +++ b/services/habit/src/main/java/de/codecentric/hc/habit/habits/Habit.java @@ -21,6 +21,7 @@ import lombok.Setter; import lombok.ToString; import org.springframework.data.domain.AbstractAggregateRoot; +import org.springframework.modulith.events.Externalized; @Entity @Builder @@ -116,12 +117,14 @@ public static class ModificationRequest { @NotNull @Valid private Schedule schedule; } + @Externalized("habit-events::#{#this.habitId}") public record HabitCreated( - UUID habitId, String userId, String name, Schedule.Frequency frequency, Integer repetitions) { - public String getId() { - return habitId.toString(); - } - } + UUID habitId, + String userId, + String name, + Schedule.Frequency frequency, + Integer repetitions) {} + @Externalized("habit-events::#{#this.habitId}") public record HabitDeleted(UUID habitId) {} } diff --git a/services/habit/src/main/resources/application.yml b/services/habit/src/main/resources/application.yml index d1a7d91f..982c0374 100644 --- a/services/habit/src/main/resources/application.yml +++ b/services/habit/src/main/resources/application.yml @@ -24,6 +24,17 @@ spring: liquibase: change-log: db/changelog/db.changelog-master.yaml default-schema: hc_habit + + kafka: + client-id: habit + bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:localhost:11003} + properties: + "security.protocol": SASL_PLAINTEXT + "sasl.mechanism": PLAIN + "sasl.jaas.config": 'org.apache.kafka.common.security.plain.PlainLoginModule required username="${KAFKA_USER:habit}" password="${KAFKA_PASSWORD:habit}";' + producer: + properties: + "spring.json.type.mapping": "habit-created:de.codecentric.hc.habit.habits.Habit.HabitCreated,habit-deleted:de.codecentric.hc.habit.habits.Habit.HabitDeleted" logging: level: liquibase.executor: WARN