温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Spring integration RecipientListRouter doesn't create multiple payloads
integration spring spring-integration

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

发布于 2020-04-24 15:59:57

请有人帮助我解决此问题,我将ReceipientListRouter配置为建议的文档:

@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,而bar激活器的输入上的有效负载3 等于有效负载1

但是实际的工作流程是:

foo激活器的输入上的有效负载2 等于有效负载1,但bar激活器的输入上的有效负载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来说 如上所述。

查看更多

提问者
Achraf Elomari
被浏览
70
Gary Russell 2020-02-07 23:08

虽然消息是不可变的,但有效负载不是(除非它是诸如String之类的不可变对象)。

如果您在service1中更改有效负载,则该更改将在service2中看到。

如果您不希望service2看到此突变,则需要先对其进行克隆/复制,然后再对其进行突变。