gpt4 book ai didi

java - 使用 spring 集成注释将多个 channel 发送到单个 channel

转载 作者:行者123 更新时间:2023-11-30 03:01:50 25 4
gpt4 key购买 nike

如何在不使用 XML 的情况下通过 Spring 集成将 2 个 channel 输出到单个 channel 。类似下面的问题Multiple channel's message comes into single channel

我的上下文中有 2 个 PollableChannel bean,我希望将消息从两个(非聚合)路由到单个 @ServiceActivator,即完成如下所示的操作:

@Bean("Channel1") PollableChannel c1() {...}
@Bean("Channel2") PollableChannel c2() {...}

?? How to interleave/combine Channel1 and Channel2 into a single channel

...
@ServiceActivator(inputChannel = "Channel1and2")
void handle(msg: MyMessage) {...}

最佳答案

@Bean("Channel1") 
@BridgeTo("Channel1and2")
PollableChannel c1() {...}

@Bean("Channel2")
@BridgeTo("Channel1and2")
PollableChannel c2() {...}

注意@BridgeTo注释。来自其 JavaDocs:

* Messaging Annotation to mark a {@link org.springframework.context.annotation.Bean}
* method for a {@link org.springframework.messaging.MessageChannel} to produce a
* {@link org.springframework.integration.handler.BridgeHandler} and Consumer Endpoint.
* <p>
* The {@link org.springframework.messaging.MessageChannel} {@link org.springframework.context.annotation.Bean}
* marked with this annotation is used as the {@code inputChannel} for the
* {@link org.springframework.integration.endpoint.AbstractEndpoint}
* and determines the type of endpoint -
* {@link org.springframework.integration.endpoint.EventDrivenConsumer} or
* {@link org.springframework.integration.endpoint.PollingConsumer}.

您还可以考虑在 @BridgeTo 上使用 @Poller,因为您的输入 channel 是 PollableChannel

有关此事的引用手册:http://docs.spring.io/spring-integration/docs/latest-ga/reference/html/configuration.html#_creating_a_bridge_with_annotations

关于java - 使用 spring 集成注释将多个 channel 发送到单个 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35759350/

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