2015-06-02 104 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

相關問題