2016-01-21 31 views
2

我必須在流程定義中丟失一些非常基本的東西。收到此錯誤Spring DSL:將錯誤消息發送到JMS隊列。獲取'單向'MessageHandler'錯誤,並且不適合配置'outputChannel''

is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow. 

我的理論是,由於適配器是單向的成分,也沒有在流動的手柄一步生成的輸出。這就是爲什麼這會導致運行時錯誤。但是,不知道如何定義這個簡單的流程。

代碼:

@Autowired 
private JmsMessagingTemplate jmsMessagingTemplate; 

@Bean 
public Queue errorQueue() { 
    return new ActiveMQQueue(fatalQueue); 
} 
@Bean 
public DirectChannel errorChannel() { 
    return new DirectChannel(); 
} 
@Bean 
public IntegrationFlow handleErrors() { 
    return IntegrationFlows 
      .from(errorChannel()) 
      .handle(x -> System.out.println("error handling invoked.x="+x)) 
      .handle(Jms.outboundAdapter(jmsMessagingTemplate.getConnectionFactory()).destination(fatalQueue)) 
      .get(); 
} 

而且,堆棧跟蹤說:

Caused by: org.springframework.beans.factory.BeanCreationException: The 'currentComponent' (MessageReceiver$$Lambda$1/[email protected]) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow. 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.registerOutputChannelIfCan(IntegrationFlowDefinition.java:2630) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na] 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.register(IntegrationFlowDefinition.java:2554) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na] 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:1136) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na] 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:1116) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na] 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:863) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na] 

回答

4

你的問題就在這裏:關於究竟

.handle(x -> System.out.println("error handling invoked.x="+x)) 

堆棧跟蹤會談。

這並不意外。你的Lambda就是這樣的impl:

.handle(new MessageHandler() { 

     public void handleMessage(Message<?> message) throws MessagingException { 
       System.out.println("error handling invoked.x="+x); 
     } 
}) 

請注意void返回類型。所以,下游沒有任何東西可以通過。

要解決它,你應該這樣做的事情:

.handle((p, h) -> { 
     System.out.println("error handling invoked.x=" + new MutableMessage(p, h)); 
     return p; 
}) 

如果它是一個GenericHandler實現。

您的.handle(Jms.outboundAdapter())在這裏很不錯。這真的是流程的結束。