【问题标题】:Axon 4.3 - consume message from topic kafkaAxon 4.3 - 使用来自主题 kafka 的消息
【发布时间】:2020-04-29 09:41:44
【问题描述】:

我正在使用 Axon 版本 (4.3),它使用 SpringBoot Main 类中的注释无缝支持 Kafka

@SpringBootApplication(exclude = org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration.class)

在我的情况下,消息已成功存储在主题中,但是这个消费者的问题,我无法从主题中消费消息。

y a-t-il une configuration manquante?

 <dependency>
   <groupId>org.axonframework</groupId>
   <artifactId>axon-spring-boot-starter</artifactId>
   <version>4.3</version>
   <exclusions>
     <exclusion>
        <groupId>org.axonframework</groupId>
        <artifactId>axon-server-connector</artifactId>
     </exclusion>
   </exclusions>
 </dependency>
 <dependency>
   <groupId>org.springframework.kafka</groupId>
   <artifactId>spring-kafka</artifactId>
 </dependency>
 <dependency>
   <groupId>org.axonframework.extensions.kafka</groupId>
   <artifactId>axon-kafka-spring-boot-starter</artifactId>
   <version>4.0-RC3</version>
 </dependency>

application.yml

axon:
  eventhandling:
    processors:
      conventions:
        source: kafkaMessageSource
        mode: tracking
  serializer:
    general: jackson
  kafka:
    client-id: consumer_service
    default-topic: topic_x
    bootstrap-servers:
    - 127.0.0.1:9092

Listener.java

//@Component
@ProcessingGroup(value = "conventions")
public class Listener {

 private static final Logger LOGGER = LoggerFactory.getLogger(GenericListener.class);

 @EventHandler
 void on(ConventionCreatedEvent event) {
  LOGGER.info("got the event {}", event);
 }

}

【问题讨论】:

    标签: apache-kafka event-handling spring-kafka axon


    【解决方案1】:

    我认为这是您配置中的 Kafka 消息源 的名称,这是现在的罪魁祸首 Aymen。

    当使用 Axon 的自动配置和 Axon-Kafka 自动配置时,没有任何关于您想要哪种类型的 Kafka 消息源的详细信息,将创建一个 StreamableKafkaMessageSource。该 bean 的名称将是 streamableKafkaMessageSource。

    但是,在您的application.yml 中,您希望conventions 跟踪事件处理器的source 被称为kafkaMessageSource。

    在此旁边,您可以查看 Axon 的 Kafka 扩展中包含的 example application。也许这会让事情更清楚一些。

    【讨论】:

    • 谢谢 Steven 为您解答。我试图将kafkaMessageSource 更改为streamableKafkaMessageSource,但问题仍然存在。我把我的项目推到了github:github.com/akanzari/axon-kafka
    • 老实说,我会尝试为此组件使用基于代码的配置。虽然本质上它应该可以工作,因为 Axon Kafka Spring Boot 自动配置器创建了一个名为 streamableKafkaMessageSource 的 StreamableKafkaMessageSource bean,但我不能说我已经自己测试过了。尽管我猜您从项目的外观上更喜欢属性文件配置,但这也不是我分享的示例所做的。
    • 你愿意尝试一下它是否有效吗?通常我会试一试您的示例项目,但我将在接下来的三周内休假,还有很多其他工作要做。
    猜你喜欢
    • 2019-11-15
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 2021-03-20
    • 2017-05-29
    • 2020-12-12
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多