'Spring Kafka, identify if container is batch mode or not

commandProcessors-in-0:
  destination: internal-command-processor
  consumer:
    max-attempts: 1
  group: command-processor-group
retrieveCohort-in-0:
  destination: internal-retrieve-cohort
  consumer:
    max-attempts: 1
    batch-mode: true
  group: retrieve-cohort-group

I have input with different consumer-like configurations one might have batch-mode to true and the other isn't.

In my ListenerContainerCustomizer I have would like to know if they have batch mode set to true is it possible.

@Bean
ListenerContainerCustomizer<AbstractMessageListenerContainer<?, ?>> customizer( ){
    return (container, dest, group) -> {
        if (dest.equals("internal-generate-stop-reason")) {
            container.setBatchErrorHandler(new RetryingBatchErrorHandler(new FixedBackOff(5000L, 2L),
                    new DeadLetterPublishingRecoverer(kafkaTemplate(),
                            (rec, ex) -> new TopicPartition("error-dlq", rec.partition()))));
        } else {
            System.out.println(dest+" => "+container.getAssignmentsByClientId());
        }
    };
}


Solution 1:[1]

There is no way to know that; except by using the group/dest properties.

However, with version 3.2.x (cloud 2021.0.x, Spring for Apache Kafka 2.8.x) there is now a CommonErrorHandler that can handle both batch and record listeners; the ErrorHandler and BatchErrorHandlers will be removed in a future release.

https://docs.spring.io/spring-kafka/docs/current/reference/html/#eh-summary

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1