2016-10-27 5 views
1

Ich möchte meine XML-Konfiguration zu Java dsl konvertieren, aber ich kann kein Beispiel für int-ip:udp-inbound-channel-adapter in Java dsl finden. Es gibt TcpNetServerConnectionFactory für TCP, aber nichts für UDP. Nur diese Klasse bildet eine Unterklasse AbstractServerConnectionFactory. Die XML-Konfiguration für die Federintegration ist unten aufgeführt.XML zu Java DSL für die Frühjahrsintegration einschließlich UDP-Kanaladapter

<int-ip:udp-inbound-channel-adapter 
     id="receiverChannel" channel="udpReceivedChannel" port="1206" multicast="false" 
     check-length="false" lookup-host="false" pool-size="20"/> 

    <int:transformer id="convertTransformer" input-channel="convertChannel" 
     output-channel="toProcessChannel" ref="transformer" method="transform"> 
    </int:transformer> 

    <int:service-activator id="accumulateActivator" input-channel="udpReceivedChannel" 
          output-channel="convertChannel" 
          ref="accumulator" method="accumulate"> 
    </int:service-activator> 

    <int:service-activator id="cssenderAcivator" input-channel="sendToCMSChannel" 
          ref="cssender" method="sendToCS"> 
    </int:service-activator> 

    <int:service-activator id="jackpotRaiseActivator" input-channel="toProcessChannel" 
          ref="jackpotraise" method="raise" > 
    </int:service-activator> 

    <int:service-activator id="jackpotScreenActivator" input-channel="jackpotScreenChannel" 
          ref="jackpotscreen" method="updateJackpotsOnDisplay" > 
    </int:service-activator> 

    <int:channel id="udpReceivedChannel"> 
     <int:dispatcher task-executor="accumulateExecutor"/> 
     <!--<int:queue message-store="redisMessageStore"/>--> <!-- ovo nam ne treba bez da nesto externo trpa u redis--> 
    </int:channel> 

    <int:channel id="toProcessChannel"> 
     <int:dispatcher task-executor="jackpotRaiseExecutor"/> 
     <int:interceptors> 
      <int:wire-tap channel="sendToCMSChannel"/> 
     </int:interceptors> 
    </int:channel> 

    <int:channel id="convertChannel"> 
     <int:dispatcher task-executor="transformerExecutor"/> 
    </int:channel> 

    <int:channel id="sendToCMS"> 
     <int:dispatcher task-executor="cmsSenderExecutor"/> 
    </int:channel> 

    <int:channel id="jackpotScreenChannel"> 
     <int:dispatcher task-executor="jackpotScreenExecutor"/> 
    </int:channel> 

    <task:executor id="accumulateExecutor" pool-size="20" keep-alive="120" /> 

    <task:executor id="jackpotRaiseExecutor" pool-size="20" keep-alive="120" /> 

    <task:executor id="transformerExecutor" pool-size="20" keep-alive="120" /> 

    <task:executor id="cmsSenderExecutor" pool-size="20" keep-alive="120" /> 

    <task:executor id="jackpotScreenExecutor" pool-size="400" keep-alive="500" /> 

Antwort

2

Hier ist eine schnelle Boot-Anwendung, die einen Adapter erstellt und sendet ein Paket an es ...

@SpringBootApplication 
public class So40286815Application { 

    public static void main(String[] args) throws Exception { 
     ConfigurableApplicationContext context = SpringApplication.run(So40286815Application.class, args); 
     DatagramSocket socket = new DatagramSocket(); 
     DatagramPacket packet = new DatagramPacket("foo".getBytes(), 3); 
     packet.setAddress(InetAddress.getLocalHost()); 
     packet.setPort(1206); 
     socket.send(packet); 
     Thread.sleep(10000); 
     socket.close(); 
     context.close(); 
    } 

    @Bean 
    public UnicastReceivingChannelAdapter inbound() { 
     UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(1206); 
     adapter.setOutputChannelName("foo"); 
     return adapter; 
    } 

    @ServiceActivator(inputChannel = "foo") 
    public void handle(byte[] bytes) { 
     System.out.println(new String(bytes)); 
    } 

} 

und mit dem DSL ...

@Bean 
public UnicastReceivingChannelAdapter inbound() { 
    return new UnicastReceivingChannelAdapter(1206); 
} 

@Bean 
public IntegrationFlow flow() { 
    return IntegrationFlows.from(inbound()) 
      .handle(System.out::println) 
      .get(); 
} 

oder einfach. ..

@Bean 
public IntegrationFlow flow() { 
    return IntegrationFlows.from(new UnicastReceivingChannelAdapter(1206)) 
      .transform(new ObjectToStringTransformer()) 
      .handle(m -> System.out.println(m.getPayload())) 
      .get(); 
} 
+0

Ich habe auch ein DSL-Beispiel hinzugefügt. –

+0

danke, das war schnell. –