Support for Multiple Kafka Clusters
Introduction
jEAP Messaging supports connecting to more than one Kafka cluster since version 6. This feature is primarily intended to support hybrid cloud use cases. See jEAP Messaging Library — Configuration for a reference of all available configuration properties and more code examples.
Also, the jme-messaging-examples repository contains a multi-cluster example,
jme-messaging-multicluster-service — the module path referenced in the original documentation could not be
verified against the current jme-messaging-example
repository on GitHub (see migration notes in the summary).
Example
For example, a Spring Boot service might connect to two different Kafka clusters and schema registries:
For the configuration, the bean-injection pattern per cluster and the Lombok caveat, see jeap-messaging — Configuration reference: Clusters.
Spring Kafka Bean Autoconfiguration in jeap-messaging
When the dependency jeap-messaging-infrastructure is on the classpath, it will activate the Spring autoconfiguration support for jEAP Messaging.
- The autoconfiguration class KafkaConfiguration in jeap-messaging will activate the import bean registrar JeapKafkaBeanRegistrar.
- JeapKafkaBeanRegistrar
iterates over each cluster configured under
jeap.messaging.kafka.cluster.<clustername>. - If a cluster is marked with
default-cluster=true, this will be the default cluster. Otherwise, the first cluster in the YAML configuration will be the designated default cluster. - For each configured cluster, beans will be registered:
- Default cluster: bean names will not be prefixed (for example,
kafkaTemplate). The registered beans will be marked as@Primary. Spring will prefer primary beans at injection points without a qualifier.- The following beans are marked
@Primaryfor a cluster other than the default cluster ifdefault-producer-cluster-override=true(supported from jEAP Messaging 7.10.0) is set for a specific cluster:KafkaTemplateKafkaProducerFactorySenderOptionsReactiveKafkaProducerTemplateTransactionalOutbox(+ internal outbox beans)
- The following beans are marked
- Other clusters: bean names will be prefixed with the cluster name (for example,
awsKafkaTemplate). The registered beans will be marked as@Qualifier("clusterName"). Spring will inject these beans at injection points when a matching qualifier is annotated.
- Default cluster: bean names will not be prefixed (for example,
This graph shows the most relevant Spring beans that are relevant for cluster-specific producers and consumers:
See also
- jEAP Messaging Library — the parent topic, including the full configuration reference.
- Signing Messages and Checking Signatures Without jEAP