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

时间:2019-01-16 19:58:25

标签: java spring-boot spring-integration

我必须在一个通道中接收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根据需要默认提供一个发布订阅频道?

1 个答案:

答案 0 :(得分:3)

在您的配置中,import React from 'react' import ReactDOM from 'react-dom' import {ApolloProvider} from 'react-apollo' import { ApolloClient } from "apollo-client"; import { createHttpLink } from "apollo-link-http"; import { setContext } from "apollo-link-context"; import { InMemoryCache } from "apollo-cache-inmemory"; import './index.css' import App from './App' import registerServiceWorker from './registerServiceWorker' const httpLink = createHttpLink({ uri: "https://api.yelp.com/v3/graphql", fetchOptions: { mode: "no-cors" } }); const authLink = setContext((_, { headers }) => { const token = process.env.yelpApiKey; return { headers: { ...headers, authorization: token ? `Bearer ${token}` : "", "Content-Type": "application/graphql" } }; }); const client = new ApolloClient({ link: authLink.concat(httpLink), cache: new InMemoryCache() }); ReactDOM.render( <ApolloProvider client={client}> <App/> </ApolloProvider> , document.getElementById('root')); registerServiceWorker(); 是DirectChannel。如果要使其成为PubSub通道,只需声明一个新bean

udpInboundChannel