Spring 集成 RecipientListRouter 不会创建多个有效负载



请任何人帮助我解决这个问题,我按照文档建议配置了我的接收列表路由器:

@Bean
public IntegrationFlow routerFlow() {
return IntegrationFlows.from(CHANNEL_INPUT)
.routeToRecipients(r -> r
.applySequence(true)
.ignoreSendFailures(true)
.recipient(CHANNEL_OUTPUT_1)
.recipient(CHANNEL_OUTPUT_2)
.sendTimeout(1_234L))
.get();
} 
@ServiceActivator(inputChannel = CHANNEL_OUTPUT_1, outputChannel = CHANNEL_END)
public Object foo(Message<?> message) {
message.gePayload();
//  processing1() ...
}
@ServiceActivator(inputChannel = CHANNEL_OUTPUT_2, outputChannel = CHANNEL_END)
public Object bar(Message<?> message) {
message.gePayload();
//  processing2() ...
}

我希望得到这个工作流程:

CHANNEL_INPUT(payload-1) |----> CHANNEL_OUTPUT_1(payload-2) 
|----> CHANNEL_OUTPUT_2(payload-3)

其中 foo 激活器输入上的有效载荷 2 等于有效载荷-1,柱线激活器输入上的有效载荷 3 等于有效载荷-1

但实际的工作流程是:

FOO 激活器输入上的有效载荷 2 等于有效载荷1,但柱线激活器输入上的有效载荷 3 等于Foo 激活器输出的有效载荷-2 消息


it seems like this is the actual workflow
CHANNEL_INPUT(payload-1)----> CHANNEL_OUTPUT_1(payload-2)----> CHANNEL_OUTPUT_2(payload-3)

调试后,我注意到message.getHeader((并不相同(它实际上包含"sequenceNumber"和"sequenceSize"(,但对于message.getPayload如上所述

虽然消息是不可变的,但有效负载不是(除非它是不可变的对象,如字符串(。

如果您在服务1中更改有效负载,则在服务2中将看到该突变。

如果您不希望 service2 看到突变,则需要在更改之前克隆/复制有效负载。

相关内容

最新更新