gpt4 book ai didi

java - 使用 UnicastReceivingChannelAdapter 进行 UDP 处理以创建发布-订阅 channel

转载 作者:行者123 更新时间:2023-12-01 19:44:02 25 4
gpt4 key购买 nike

我必须在一个 channel 中接收 UDP 并通过管道传输到 2 个订阅 channel 。为此,我有 2 个具有相同输入 channel 的 Serviceactivator 功能。

@Autowired
private PublishSubscribeChannel channel;

@Bean
public UnicastReceivingChannelAdapter udpIn() {
final UnicastReceivingChannelAdapter adapter = new
UnicastReceivingChannelAdapter(<port>);
adapter.setPoolSize(6);
adapter.setOutputChannel(channel); //Is it required?
adapter.setOutputChannelName("udpInboundChannel");
adapter.stop();
return adapter;
}

@ServiceActivator(inputChannel = "udpInboundChannel")
public void handleMessage(Message<?> message) throws MessagingException {
----
}

@ServiceActivator(inputChannel = "udpInboundChannel")
public void handleMessageDifferently(Message<?> message) throws MessagingException {
---
}

我的问题,我需要像这样设置 channel adapter.setOutputChannel(channel)吗?或者 UnicastReceivingChannelAdapter 根据我的需要默认提供一个发布-订阅 channel ?

最佳答案

在您的配置中,udpInboundChannel 是 DirectChannel。如果您希望它成为 PubSub channel ,只需声明一个新 bean

 @Bean
public MessageChannel udpInboundChannel() {
return new PublishSubscribeChannel();
}

关于java - 使用 UnicastReceivingChannelAdapter 进行 UDP 处理以创建发布-订阅 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54224448/

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