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

时间:2015-06-02 21:00:20

标签: 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>         

1 个答案:

答案 0 :(得分:5)

    @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())