java 处理程序xxxx未生成回复,其“requiresReply”属性设置为true

epfja78i  于 2022-12-21  发布在  Java
关注(0)|答案(1)|浏览(167)

在分散收集模式中,特别是在分布变体中,我尝试通过传递如下的标题属性在gatherer元素中使用“correlation-strategy-expression”,我得到“处理程序xxxx没有产生回复,其“requireReply”属性设置为true。

<scatter-gather input-channel="inputDistribution" output-channel="output" gather-channel="gatherChannel">
    <scatterer>
        <recipient channel="distribution1Channel"/>
        <recipient channel="distribution2Channel"/>
        <recipient channel="distribution3Channel"/>
    </scatterer>
    <gatherer correlation-strategy-expression="headers[CorrelationId]'/>
</scatter-gather>

其中,在测试代码中,我显式地将报头属性设置为如下:MessageBuilder.writhPayload(“foo”).setHeader(MessageHeaders.REPLY_CHANEL,输出).setHeader(“相关ID”,“foo”).build()。
注意:如果我使用apply-sequene=true作为scatterer属性,它可以正常工作。
你能建议一下配置中的错误吗?我们需要定义任何bean吗?
尝试使用correlation-strategry-expression,但出现错误

lp0sw83n

lp0sw83n1#

不幸的是,你的担心仍然不清楚。我相信你只是没有给我们所有的相关代码,导致该错误。
以下是配置:

<channel id="output">
    <queue/>
</channel>

<!--Distribution scenario-->
<scatter-gather input-channel="inputDistribution" output-channel="output" gather-channel="gatherChannel">
    <scatterer>
        <recipient channel="distribution1Channel"/>
        <recipient channel="distribution2Channel"/>
        <recipient channel="distribution3Channel"/>
    </scatterer>
    <gatherer release-strategy-expression="messages.^[payload gt 5] != null or size() == 3"
              correlation-strategy-expression="headers[CorrelationId]"/>
</scatter-gather>

<channel id="gatherChannel">
    <queue/>
</channel>

<bridge input-channel="distribution1Channel" output-channel="serviceChannel2"/>

<bridge input-channel="distribution2Channel" output-channel="serviceChannel2"/>

<bridge input-channel="distribution3Channel" output-channel="serviceChannel2"/>

<service-activator input-channel="serviceChannel2" output-channel="gatherChannel"
                   expression="T(java.lang.Math).random() * 10"/>

下面是单元测试的代码:

@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class ScatterGatherTests {

    @Autowired
    private PollableChannel output;

    @Autowired
    private MessageChannel inputDistribution;

    @Test
    public void testDistribution() {
        this.inputDistribution.send(MessageBuilder.withPayload("foo").setHeader("CorrelationId", "foo").build());
        Message<?> bestQuoteMessage = this.output.receive(10000);
        assertThat(bestQuoteMessage)
                .isNotNull()
                .extracting(Message::getPayload)
                .isInstanceOf(List.class)
                .asList()
                .hasSizeGreaterThanOrEqualTo(1);
    }

}

相关问题