How can I effectively bind my @KafkaListener to ConcurrentKafkaListenerContainerFactory?

后端 未结 1 445
庸人自扰
庸人自扰 2021-01-27 13:29

I hit this scenario which appears strange to me:

So basically I have defined two @KafkaListener in one class:



        
相关标签:
1条回答
  • 2021-01-27 13:59

    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()}"
    
    0 讨论(0)
提交回复
热议问题