简体   繁体   English

在 Spring Boot 你如何配置一些监听器使用自动确认和其他使用手动确认

[英]In Spring Boot How do you configure some listeners to use automatic Acknowledgment and others to use manual acknowledgment

I have a simple Spring Boot app with multiple methods annotated with @KafkaListener.我有一个简单的 Spring Boot 应用程序,其中有多种方法,并用 @KafkaListener 注释。 I would like some of them to use automatic acknowledgment while others use manual acknowledgment.我希望他们中的一些人使用自动确认,而其他人使用手动确认。 Is it possible to achieve this using Spring Boot configuration with out manually setting up container factories?是否可以使用 Spring 引导配置来实现这一点,而无需手动设置容器工厂? According to the documentation Using a @KafkaListener requires code like根据文档使用 @KafkaListener 需要类似的代码

@KafkaListener(id = "cat", topics = "myTopic",
          containerFactory = "kafkaManualAckListenerContainerFactory")
public void listen(String data, Acknowledgment ack) {
    ...
    ack.acknowledge();
}

Does this mean I need to create two container factory's, one for automatic acknowledgement and one for manual acknowledgement and configure all listeners to reference the correct factory?这是否意味着我需要创建两个容器工厂,一个用于自动确认,一个用于手动确认并配置所有侦听器以引用正确的工厂?

Does this mean I need to create two container factory's, one for automatic acknowledgement and one for manual acknowledgement and configure all listeners to reference the correct factory?这是否意味着我需要创建两个容器工厂,一个用于自动确认,一个用于手动确认并配置所有侦听器以引用正确的工厂?

The assumption is correct.假设是正确的。 You just provide one ListenerContainerFactory bean with one set of ContainerProperties and another one with different set.您只需为一个ListenerContainerFactory bean 提供一组ContainerProperties和另一个具有不同集的 bean。 See this JavaDocs for more info in the AbstractKafkaListenerContainerFactory :有关AbstractKafkaListenerContainerFactory的更多信息,请参阅此 JavaDocs:

/**
 * Obtain the properties template for this factory - set properties as needed
 * and they will be copied to a final properties instance for the endpoint.
 * @return the properties.
 */
public ContainerProperties getContainerProperties()

You may consider to rely on the conventional bean name for that containerFactory property for one of the ack mode and set of listeners:您可以考虑依赖该containerFactory属性的常规 bean 名称来获取其中一个 ack 模式和一组侦听器:

/**
 * The bean name of the {@link org.springframework.kafka.config.KafkaListenerContainerFactory}
 * to use to create the message listener container responsible to serve this endpoint.
 * <p>
 * If not specified, the default container factory is used, if any. If a SpEL
 * expression is provided ({@code #{...}}), the expression can either evaluate to a
 * container factory instance or a bean name.
 * @return the container factory bean name.
 */
String containerFactory() default "";

Where default one is KafkaListenerAnnotationBeanPostProcessor.DEFAULT_KAFKA_LISTENER_CONTAINER_FACTORY_BEAN_NAME - kafkaListenerContainerFactory .默认值是KafkaListenerAnnotationBeanPostProcessor.DEFAULT_KAFKA_LISTENER_CONTAINER_FACTORY_BEAN_NAME - kafkaListenerContainerFactory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对使用Spring AMQP发布的确认 - Acknowledgment on Publish with Spring AMQP Spring Kafka 确认设置 - Spring Kafka acknowledgment settings 将确认传递给 spring KafkaListener 消费者方法 - Passing Acknowledgment to a spring KafkaListener consumer method 你如何使用 Spring 引导执行器,仅在非 Web 上使用 JMX spring 引导应用程序 - How do you use Spring Boot Actuator using JMX only on a non-web spring boot app 具有Spring Security的Spring Boot Java配置:如何配置为使用FilterBasedLdapUserSearch和BindAuthenticator? - Spring Boot Java config with Spring Security: How do I configure to use FilterBasedLdapUserSearch and BindAuthenticator? 如何配置 spring boot 2 默认返回 xml? - How do you configure spring boot 2 to return xml by default? 如何配置两个实例mongodb使用spring引导和spring数据 - How to configure two instance mongodb use spring boot and spring data Spring Batch:如何在步骤侦听器中使用占位符? - Spring Batch: How do I use placeholders in step listeners? 如何配置带有身份验证的嵌入式MongoDB,以用于Spring Boot集成测试? - How do I configure embedded MongoDB with authentication for use in spring boot integration tests? 如何使用配置类在 Spring Boot 中为我的应用程序配置属性? - How do I use a configuration class to configure properties for my application in Spring Boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM