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

标签 java spring-boot spring-integration

我必须在一个 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/

相关文章:

spring - 预授权不适用于 Controller

java - hibernate中具有相同主键的一对一单向映射

mysql - 字段列表中未知表 'hibernate_sequence'

tcp - 如何在不使用终止符或固定长度消息的情况下接收 TCP 数据包

spring-integration - 无法使用 Spring Boot 注册 HttpRequestHandlerServlet

java - 对两个 Eclipse 项目使用相同的 keystore ,但在同一系统上进行调试时它们无法通信

java - 更改 ListView 行 xml 中 TextView 的属性

java - 使用 LWJGL 在屏幕上书写文本

java - Spring Integration 轮询器在一段时间后挂起或停止

java - 更新 jTable - 将 jTable 作为参数传递