Reputation: 2570
I know that it is possible to define client.id
for each @KafkaListener
.
Is it possible to define client.id
for each KafkaTemplate
?
It is easier to read the kafka-logs, if I can define the client.id
per KafkaTemplate
instead of relying on Spring assigning a suffix to each producer.
Upvotes: 1
Views: 2831
Reputation: 121560
Spring Kafka doesn't assign any client.id
into the Producer
it creates:
protected Producer<K, V> createKafkaProducer() {
return new KafkaProducer<K, V>(this.configs, this.keySerializer, this.valueSerializer);
}
Unless you provide one via ProducerConfig.CLIENT_ID_CONFIG
into those mentioned configs
.
So, for each your KafkaTemplate
you need to declare a separate DefaultKafkaProducerFactory
and share common properties via Map<String, Object> configs
, but use unique ProducerConfig.CLIENT_ID_CONFIG
for each instance.
Alternatively you can implement your own ProducerFactory
to populate a unique ProducerConfig.CLIENT_ID_CONFIG
each time its createProducer()
is called.
Upvotes: 2