I hit this scenario which appears strange to me:
So basically I have defined two @KafkaListener
in one class:
It's because consumerFactory
is a singleton @Bean
and the arguments are ignored on the second call.
Add @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
to the factory get a new bean each time.
However, you don't need any of this, you can simply set the groupId
property on the annotations and avoid all this extra definition.
You can also control autoStartup
on the annotation (since 2.2).
EDIT
To answer the question in the comment below...
groupId = "#{'${group.id}' + T(java.time.Instant).now().toEpochMilli()}"
however, if you want a unique group id; this is more reliable...
groupId = "#{'${group.id}' + T(java.util.UUID).randomUUID()}"