我必须在一个通道中接收UDP,然后将其传送到2个订阅通道。为此,我有2个具有相同输入通道的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 {
  ---
}


我的问题是,我需要像这样设置频道adapter.setOutputChannel(channel)吗?还是UnicastReceivingChannelAdapter默认情况下根据需要提供发布订阅频道?

最佳答案

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

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

10-01 18:20