2016-12-02 6 views
1

私はこのSOF質問を読んでおり、補足的な質問があります。多くのプロデューサとスプリング統合フローを作成する方法

私はこの今日のように動作します春の統合の流れがあります。

@Bean 
public IntegrationFlow udpSource1() { 
    return IntegrationFlows.from(new MulticastReceivingChannelAdapter("224.0.0.1", 2000)). 
      transform(new ObjectToStringTransformer("utf8")).channel("stringified").get(); 

} 
@Bean 
public IntegrationFlow udpSource2() { 
    return IntegrationFlows.from(new MulticastReceivingChannelAdapter("224.0.0.1", 2001)). 
      transform(new ObjectToStringTransformer("utf8")).channel("stringified").get(); 

} 

そして、私はseverals(10)UDPソースを持っています。

すべてのUDPソースを使用して1つのフローを作成したいと思います。それらのすべてが「ストリンジェライズ」チャンネルにデータをプッシュします。

私は、その後、ArrayListのからすべての私のUDPポートを取得、このリストを反復処理し、UDPソースを作成したいと思い

...

それは可能ですか?

答えて

1

はい、IntegrationFlowRegistrationhttps://spring.io/blog/2016/09/27/java-dsl-for-spring-integration-1-2-release-candidate-1-is-availableとなります。

同様の解決策はDynamic TCP Sampleを参照してください。ここで

private MessageChannel createNewSubflow(Message<?> message) { 
     String host = (String) message.getHeaders().get("host"); 
     Integer port = (Integer) message.getHeaders().get("port"); 
     Assert.state(host != null && port != null, "host and/or port header missing"); 
     String hostPort = host + port; 

     TcpNetClientConnectionFactory cf = new TcpNetClientConnectionFactory(host, port); 
     TcpSendingMessageHandler handler = new TcpSendingMessageHandler(); 
     handler.setConnectionFactory(cf); 
     IntegrationFlow flow = f -> f.handle(handler); 
     IntegrationFlowRegistration flowRegistration = 
       this.flowContext.registration(flow) 
         .addBean(cf) 
         .id(hostPort + ".flow") 
         .register(); 
     MessageChannel inputChannel = flowRegistration.getInputChannel(); 
     this.subFlows.put(hostPort, inputChannel); 
     return inputChannel; 
    } 
0

が、私は私の問題を解決するためのアルテムによって与えられたヒントを使用する方法である:

キーコードは次のようです。

@Configuration 
public class UdpSources { 
    @Value("#{'${udp.nmea.listeningports}'.split(',')}") 
    List<Integer> allUDPPorts; 

    public static final String outChannel = "stringified"; 

    @Autowired 
    private IntegrationFlowContext flowContext; 

    @PostConstruct 
    public void createAllUDPEndPoints(){ 
     for(int port : allUDPPorts){ 
      flowContext.registration(getUdpChannel(port)).autoStartup(false).id("udpSource"+port).register(); 
     } 
    } 

    private IntegrationFlow getUdpChannel(int port){ 
     return IntegrationFlows.from(new MulticastReceivingChannelAdapter("224.0.0.1", port)). 
       transform(new ObjectToStringTransformer("UTF-8")).channel(outChannel).get(); 
    } 
} 
関連する問題