【问题标题】:Error channel for Spring Cloud Stream Service-Bus BinderSpring Cloud Stream Service-Bus Binder的错误通道
【发布时间】:2020-04-22 14:05:38
【问题描述】:

我正在尝试为Spring Cloud Azure Service Bus Queue Stream Binder 配置错误通道,但没有成功。我已经通过

启用了错误通道
spring:
  cloud:
    stream:
      function:
        definition: produce
      bindings:
        produce-out-0:
          destination: service-bus-q-a
          producer:
            error-channel-enabled: true

并尝试定义@ServiceActivator:

@ServiceActivator(inputChannel = "service-bus-q-a.errors")
public void errors(ErrorMessage receiveMsg) {
    System.err.println("receive error msg: " + receiveMsg);
}

我也试过inputChannel = "errorChannel" 和inputChannel = "service-bus-q-a.$Default.errors"。显然我在这里遗漏了一些东西,但我找不到一个可行的例子。

编辑:我正在使用以下供应商 bean:

@Bean
Supplier<String> produce() {
    return () -> {
        String msg = "a message to produce";
        LOG.info("Producing message: " + msg);
        return msg;
    };
}

根据binding naming conventions,绑定的名称将是produce-out-0。我可以看到消息确实发送到service-bus-q-a(我在另一边有一个消费者)。

编辑和解决方案:

所以看来我的环境有问题,在重建它之后,一切都按预期工作,就像Garry Russell's answer shows。很抱歉浪费了时间。 对于后代来说,这正是对我有用的:

声明绑定时

spring:
  cloud:
    stream:
      bindings:
        produce-out-0:
          destination: service-bus-q-a
          producer:
            error-channel-enabled: true

将创建的错误通道将命名为{destination}.errors,在本例中为service-bus-q-a.errors。此外,您还有全局错误通道errorChannel,如果发生错误,也会调用该通道。所以你可以使用任何一个

@ServiceActivator(inputChannel = "service-bus-q-a.errors")
public void errors(ErrorMessage receiveMsg) {
    System.err.println("receive error msg: " + receiveMsg);
}

接收来自service-bus-q-a 的错误或

@ServiceActivator(inputChannel = "errorChannel")
public void errors(ErrorMessage receiveMsg) {
    System.err.println("receive error msg: " + receiveMsg);
}

从全局错误通道接收错误。

【问题讨论】:

  • 看起来他们最近才添加了对此的支持:github.com/microsoft/spring-cloud-azure/commits/master/…。哦 - 看起来那只是在消费者方面。
  • 那么有没有办法从生产者发送超时中恢复?
  • 对不起;我不知道;我不熟悉那个活页夹。
  • 您是否有机会知道是否有非绑定器特定的方法来处理生产者错误?
  • 嗯——我刚刚查看了他们的代码,他们确实将errorChannel 注入到处理程序(github.com/microsoft/spring-cloud-azure/blob/…)中,所以如果error-channel-enabled 是true,它应该可以工作。尝试使用调试器。

标签: java azureservicebus spring-cloud-stream


【解决方案1】:

我刚刚用这个 yaml 测试了它,属性是true,正如预期的那样。

spring:
  cloud:
    stream:
      bindings:
        output:
          producer:
            error-channel-enabled: true
    azure:
      servicebus:
        connectionString: Endpoint=sb://foo.bar

您确定您的制作人姓名 (produce-out-0) 正确吗?

【讨论】:

  • 我已经用我正在使用的供应商 bean 编辑了我的答案,我可以看到该消息已发送到 service-bus-q-a。如果您输入错误通道@ServiceActivator,它会在生产者发送超时时调用吗?另外,您使用的是什么spring-cloud-azure-servicebus-queue-stream-binder 版本?我正在使用1.2.3
  • 我使用的是 1.2.3;但我没有真实的环境;我使用了一个虚拟连接字符串,只是为了测试布尔值是否设置正确。 isErrorChannelEnabled() 仍然正确,并且错误通道不为空,对我来说,当我将测试更改为使用您的供应商 bean 并以 produce-out-0 作为绑定名称时。因此,如果您仍然在调试器中看到 null 错误通道,那么您的 YAML 似乎没有被读取。
  • 你是对的,这是我的环境有问题。我已经用完整的解决方案更新了我的问题,并将您的答案标记为正确。感谢并为浪费的时间感到抱歉。
猜你喜欢
  • 2019-10-03
  • 1970-01-01
  • 2019-04-19
  • 1970-01-01
  • 1970-01-01
  • 2021-04-20
  • 1970-01-01
  • 2020-03-23
  • 1970-01-01
相关资源
最近更新 更多