如何将Spring Integration XML转换为Java DSL for errorChannel

zac*_*ung 3 spring-integration

我在我的应用程序中有以下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>         
Run Code Online (Sandbox Code Playgroud)

Gar*_*ell 6

    @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();
    }
Run Code Online (Sandbox Code Playgroud)

编辑:

    @Bean
    public MessageChannel errorChannel() {
        return new DirectChannel();
    }
Run Code Online (Sandbox Code Playgroud)

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

.errorChannel(errorChannel())
Run Code Online (Sandbox Code Playgroud)