Spring 云流生产者错误处理程序不起作用

Spring cloud stream Producer error handler not works

我正在使用 spring 云流版本 3.1.4,这是我的制作人

@Component
public class Producer {    
    @Autowired
    private StreamBridge streamBridge;

    public void produce(int messageId, Object message) {
        Message<Object> msg= MessageBuilder
                .withPayload(message)
                .setHeader("partitionKey", messageId)
                .build();

        streamBridge.send("outputchannel-out-0", msg);
    }

    @ServiceActivator(inputChannel = "errorchannel.errors")
    public void errorHandler(ErrorMessage em) {
        log.info("Error: {}", em);
    }
}

进入application.yaml我设置了errorChannelEnabled

spring:
  cloud:
    stream:
      bindings:
        #Channel name
        outputchannel-out-0:
          destination: my-topic
          contentType: application/json
          producer:
            partitionKeyExpression: headers['partitionKey']
            partitionCount: 1
            errorChannelEnabled: true

现在,如果我以这种方式更改 produce() 方法,以测试错误处理程序

public void produce(int messageId, Object message) {
    throw new RuntimeException("Producer error");
}

没有任何反应。 不触发错误处理程序。 我不确定在 spring 云流 3.1.4.

中设置错误处理程序是否正确

你能帮帮我吗?

errorchannel.errors 不存在。

有两个错误通道errorChannel是全局错误通道;特定于绑定的错误通道被命名为 <destination>.<group>.errors。您目前没有群组。