profile
viewpoint

Ask questionsMechanism of obtaining consumer settings through the groupId qualifier does not work for groups in the upper snake case pattern.

When defining a groupId in the upper snake case pattern (e.g: MY_GROUP_ID), KafkaConsumerProcessor is unable to obtain my customer's customized settings.

Steps to Reproduce

  1. Up the apache kafka stack, creating a topic named my-products and an groupId MY_GROUP_ID.

  2. Create a micronaut application with a consumer with the groupId MY_GROUP_ID.

    application.yml
    kafka:
      bootstrap:
        servers: localhost:9092
      consumers:
        my-group-id:
          value: io.confluent.kafka.serializers.KafkaJsonDeserializer
    
    ProductConsumer.kt
    import io.micronaut.configuration.kafka.annotation.KafkaKey
    import io.micronaut.configuration.kafka.annotation.KafkaListener
    import io.micronaut.configuration.kafka.annotation.OffsetReset
    import io.micronaut.configuration.kafka.annotation.Topic
    
    @KafkaListener(
        offsetReset = OffsetReset.EARLIEST,
        groupId = "MY_GROUP_ID"
    )
    class ProductConsumer {
        @Topic("my-products")
        fun receive(@KafkaKey brand: String, product: Product) {
            println("Got Product - ${product.name} by $brand")
        }
    }
    
    data class Product(var name: String)
    

Expected Behaviour

Custom consumer settings must be obtained. The consumer does not assume the io.confluent.kafka.serializers.KafkaJsonDeserializer value deserializer.

class: io.micronaut.configuration.kafka.processor.KafkaConsumerProcessor method: public void process(BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method)

The code block below is contained in the class and method specified above. This is the mechanism that fetches the consumer custom configuration bean through the qualifier by name using the groupId. I believe that the error lies in this mechanism.

AbstractKafkaConsumerConfiguration consumerConfigurationDefaults = 
           beanContext.findBean(AbstractKafkaConsumerConfiguration.class, Qualifiers.byName(groupId))
                               .orElse(defaultConsumerConfiguration);

Actual Behaviour

Custom consumer settings are not obtained.

Environment Information

  • Operating System: Ubuntu 20.04
  • Micronaut Version: 2.4.1
  • JDK Version: 11

Example Application

https://github.com/NilMouraa/micronaut-kafka-issue-groupid

micronaut-projects/micronaut-kafka

Answer questions NilMouraa

@graemerocher could you confirm if this is really a bug? Because if it is, I have a suggested solution for that. I can contribute with you.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List