2015-06-02 81 views
2

我的应用程序中有以下xml配置,我想将其转换为Java DSL。如何将Spring Integration XML转换为Java DSL for errorChannel

所以在这篇文章中我明确地定义了错误通道的名称。主要是例如原因。有了这个引用,我期望发生的情况是下游进程抛出异常,并且它应该通过错误通道将有效负载路由回去。 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>   

回答

4
@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(); 
    } 

和自动装配,或引用它作为

我知道,但this.errorChannel是如何定义的
.errorChannel(errorChannel()) 
+1

愚蠢的问题?你能否更新这个例子来反映这个? – zachariahyoung

+1

经过更新以显示errroChannel定义 –

+1

xml配置中的Gary我不必为errorChannel定义消息通道。 DSL能否以相同的方式行事?我认为messageDriverChannelAdapter上的.outputChannel也可以以同样的方式工作。 – zachariahyoung

相关问题