[英]Unexpected behavior of minimal flow in Spring Integration
I'm creating a new flow and started from almost empty definition 我正在创建一个新流程,并从几乎空的定义开始
@Bean
public IntegrationFlow routerFlow() {
return IntegrationFlows
.from(routerInputChannel())
.channel(routerOutputChannel())
.get();
}
So far so good. 到现在为止还挺好。 But if I add simple wireTap line 但是如果我添加简单的wireTap行
@Bean
public IntegrationFlow routerFlow() {
return IntegrationFlows
.from(routerInputChannel())
.wireTap(m -> System.out.println(m))
.channel(routerOutputChannel())
.get();
}
I received exception 我收到例外
Caused by: org.springframework.beans.factory.BeanCreationException: The 'IntegrationFlow' can't consist of only one 'MessageChannel'. Add at lest '.bridge()' EIP-method before the end of flow.
at org.springframework.integration.dsl.IntegrationFlowDefinition.get(IntegrationFlowDefinition.java:2670)
at org.springframework.integration.dsl.IntegrationFlowBuilder.get(IntegrationFlowBuilder.java:26)
at org.springframework.integration.dsl.IntegrationFlowDefinition.wireTap(IntegrationFlowDefinition.java:329)
at org.springframework.integration.dsl.IntegrationFlowDefinition.wireTap(IntegrationFlowDefinition.java:263)
at com.xxx.xxx.xxx.xxx.config.RootConfiguration.routerFlow(RootConfiguration.java:29)
What is the reason of such exception? 这种例外的原因是什么?
I use Spring Integration 4.3.7.RELEASE and Spring Integration Java DSL 1.1.4.RELEASE 我使用Spring Integration 4.3.7.RELEASE和Spring Integration Java DSL 1.1.4.RELEASE
Well, that is indeed unexpected. 好吧,那确实是出乎意料的。
The wireTap()
has signature: wireTap()
具有签名:
public B wireTap(IntegrationFlow flow) {
Where IntegrationFlow
is functional interface and therefore can be specified by the Lambda. 其中IntegrationFlow
是功能接口,因此可以由Lambda指定。 At the same time the argument of that Lambda can really be sent to the System.out.println()
. 同时,该Lambda的参数实际上可以发送到System.out.println()
。 If we convert your Lambda to the interface implementation we'll see: 如果将您的Lambda转换为接口实现,我们将看到:
.wireTap(new IntegrationFlow() {
@Override
public void configure(IntegrationFlowDefinition<?> x) {
System.out.println(x);
}
})
As you see there is really no anything about the message you would expect with your Lambda for .handle()
. 如您所见,对于Lambda对于.handle()
的消息确实没有任何要求。
And you should see something like this in your logs: 而且您应该在日志中看到类似以下内容的内容:
org.springframework.integration.dsl.IntegrationFlowBuilder@6995bf68
That is exactly SOUT of the System.out.println(IntegrationFlowDefinition)
... 那就是System.out.println(IntegrationFlowDefinition)
SOUT ...
So, to fix your problem we should have something like this: 因此,要解决您的问题,我们应该有以下内容:
.wireTap(flow -> flow.handle(System.out::println))
I don't know what we can do from the Framework perspective. 从框架的角度来看,我不知道该怎么办。 I'm pretty sure any @FunctionalInterface
-based construction suffers the same problem if we provide a Lambda with the Object.toString()
signature. 我非常确定,如果我们为Lambda提供Object.toString()
签名,则任何基于@FunctionalInterface
的构造都会遇到相同的问题。 That is just some nasty side-effect of the syntax sugar IMO :-). 那只是语法糖IMO :-)的一些讨厌的副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.