【问题标题】:Spring DSL: Sending error message to JMS queue. Get an error 'one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel''Spring DSL:向 JMS 队列发送错误消息。得到一个错误'单向'MessageHandler'并且不适合配置'outputChannel''
【发布时间】:2016-01-21 16:44:08
【问题描述】:

我必须在流程定义中遗漏一些非常基本的东西。收到此错误

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/1495414981@76c52298) 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]

【问题讨论】:

    标签: java spring spring-integration


    【解决方案1】:

    您的问题在这里:

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

    StackTrace 正好谈到了这一点。

    这并不奇怪。你的 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()) 在这里很好。这真的是流程的尽头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 2020-04-05
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      • 2013-05-22
      • 2018-10-25
      相关资源
      最近更新 更多