How snuk87/keycloak-kafka works
Project Type and Purpose
• This is an open-source Keycloak SPI (Service Provider Interface) module written in Java. Its sole purpose is to capture Keycloak user/admin events and forward them to an Apache Kafka cluster.
High-Level Components
a. Keycloak Server Core
• Loads SPI providers from the providers folder (your fat-jar).
• Emits internal events (EventListenerProvider).
b. Keycloak Kafka Module (SPI Provider)
• KafkaEventListenerProviderFactory registers the provider.
• KafkaEventListenerProvider implements the SPI interface to receive events.
• KafkaProducerConfig reads environment/CLI settings.
• KafkaProducerFactory (and StandardProducerFactory) create/configure Kafka producers.
c. Kafka Cluster (External Service)
• One or more brokers listening on bootstrapServers.
• One or two topics: topicEvents and optional topicAdminEvents.
d. (Optional) Downstream Consumer
• E.g., a Spring Boot app using @KafkaListener to consume events.
Relationships and Data Flow
• On user/admin actions Keycloak generates an Event → Keycloak Core invokes KafkaEventListenerProvider::onEvent() → provider serializes the event → sends it via a KafkaProducer created by KafkaProducerFactory → Kafka Broker → optional downstream consumers.
• Configuration flows from environment variables or CLI flags into KafkaProducerConfig.
Architectural Patterns and Design Principles
• SPI/Plugin Architecture: decouples module from Keycloak core.
• Factory Pattern: KafkaProducerFactory hides producer instantiation.
• Configuration by Convention: environment variables / CLI flags drive both SPI and Kafka client configs.
• Single Responsibility: each class has a focused role (provider, factory, config).
Essential Details
• Configuration parameters (e.g., KAFKA_BOOTSTRAP_SERVERS, KAFKA_TOPIC).
• That the module is a “fat jar” built by Maven (pom.xml, assembly plugin).
• Test suite side-by-side (for completeness) or omit if focusing strictly on runtime architecture.