【问题标题】:Spring Cloud Stream Error Handling using external destination使用外部目的地的 Spring Cloud Stream 错误处理
【发布时间】:2018-07-06 03:50:33
【问题描述】:

我一直在阅读 spring-cloud-stream 文档,特别是error handling

@StreamListener(Sink.INPUT) // destination name 'input.myGroup'
public void handle(Person value) {
    throw new RuntimeException("BOOM!");
}

@ServiceActivator(inputChannel = Processor.INPUT + ".myGroup.errors") //channel name 'input.myGroup.errors'
public void error(Message<?> message) {
    System.out.println("Handling ERROR: " + message);
}

关于文档的内容,当您想要捕获错误时,您可能想要使用@ServiceActivator。这没有关联的外部目的地。

@StreamListener 注解的使用专门用于 定义桥接内部渠道和外部渠道的绑定 目的地。鉴于目标特定的错误通道确实 没有关联的外部目的地,这样的通道是 Spring Integration (SI) 的特权。这意味着处理程序 对于此类目的地,必须使用 SI 处理程序之一定义 注释(即@ServiceActivator、@Transformer 等)。

我还关注了关于error channel creation 的整个帖子,它确认拥有@ServiceActivator 注释不会创建外部目标来传播错误。

我有一个用例,外部侦听器进程将使用发布到特定 Kafka 错误主题的错误。基于此,我有以下问题,

  1. @ServiceActivator 的具体用途是什么,或者这个特定注释提供的功能是什么?
  2. 将错误传播到外部目标的好方法是什么? (例如,一个 Kafka 主题)。
  3. 是否将错误发布到外部目标以便以后以良好的模式使用?

【问题讨论】:

    标签: spring spring-integration spring-cloud spring-cloud-stream spring-cloud-dataflow


    【解决方案1】:

    @ServiceActivator 将专门用于内部错误处理(即,由同一应用程序)。对于您希望将错误发送到 Kafka 主题以便外部消费者使用它们的情况,您应该使用 DLQ。你可以在这里找到更多细节https://docs.spring.io/spring-cloud-stream/docs/Elmhurst.RELEASE/reference/htmlsingle/#kafka-dlq-processing

    如果您还有其他问题,请告诉我们

    【讨论】:

      猜你喜欢
      • 2021-08-03
      • 1970-01-01
      • 2019-10-03
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多