Skip to content
Kafka Is FunProgress

SpringSpring Kafka Advanced

How do you configure Spring Kafka consumer groups for multi-tenancy?

Reference answer

For multi-tenant Kafka, each tenant's consumer group should be isolated: group.id = tenant-{tenantId}-{service-name}. Use a routing @KafkaListener that reads a shared topic and routes to tenant-specific processing. Or use separate topics per tenant with dynamic topic subscription: consumer.subscribe(Pattern.compile('tenant-.*-orders')). Spring Kafka supports regex topic subscription via @KafkaListener(topicPattern = 'tenant-.*-orders'). For complete isolation (separate clusters per tenant), use multiple KafkaListenerContainerFactory beans with tenant-specific ProducerFactory/ConsumerFactory configurations.

Expected key concepts: multi-tenancy, group.id, tenant isolation, topicPattern, regex subscription, dynamic subscription, KafkaListenerContainerFactory, ProducerFactory, ConsumerFactory, separate clusters