gpt4 book ai didi

java - Spring DSL : Sending error message to JMS queue. 报错 'one-way ' MessageHandler' 不适合配置 'outputChannel' '

转载 作者:行者123 更新时间:2023-11-30 06:55:49 34 4
gpt4 key购买 nike

我一定是在流定义中遗漏了一些非常基本的东西。得到这个错误

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]

最佳答案

您的问题在这里:

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

StackTrace 恰恰谈到了这一点。

这并不奇怪。你的 Lambda 是这样的:

.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()) 在这里很好。这真的是流程的结束。

关于java - Spring DSL : Sending error message to JMS queue. 报错 'one-way ' MessageHandler' 不适合配置 'outputChannel' ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34929476/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com