简体   繁体   中英

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());
        }
    };
}

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 BatchErrorHandler s will be removed in a future release.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM