如何将 Spring 集成 XML 转换为 errorChannel 的 Java DSL

How to convert Spring Integration XML to Java DSL for errorChannel

我的应用程序中有以下 xml 配置,我想将其转换为 Java DSL。

因此,在此参考中,我明确定义了错误通道的名称。主要是出于示例原因。有了这个参考,我期望发生的事情是当下游进程抛出异常时,它应该通过错误通道将有效负载路由回。 Java 代码会是什么样子?

<int-jms:message-driven-channel-adapter
        id="notification" 
        connection-factory="connectionFactory"
        destination="otificationQueue" 
        channel="notificationChannel"
        error-channel="error"       
         />

<int:chain id="chainError" input-channel="error">
        <int:transformer id="transformerError" ref="errorTransformer" />
        <int-jms:outbound-channel-adapter 
            id="error"
            connection-factory="connectionFactory" 
            destination="errorQueue" />
    </int:chain>         
    @Bean
    public IntegrationFlow jmsMessageDrivenFlow() {
        return IntegrationFlows
                .from(Jms.messageDriverChannelAdapter(this.jmsConnectionFactory)
                        .id("notification")
                        .destination(this.notificationQueue)
                        .errorChannel(this.errorChannel))

                ...

                .get();
    }

    @Bean
    public IntegrationFlow ErrorFlow() {
        return IntegrationFlows
                .from(this.errorChannel)
                .transform(errorTransformer())
                .handle(Jms.outboundAdapter(this.jmsConnectionFactory)
                        .destination(this.errorQueue), e -> e.id("error"))
                .get();
    }

编辑:

    @Bean
    public MessageChannel errorChannel() {
        return new DirectChannel();
    }

并自动装配它,或将其引用为

.errorChannel(errorChannel())