2017-05-10 59 views
0

發送響應我試圖與發送的消息:無法爲UDP消息

netcat -u localhost 11111abcd 

我只需要在客戶端得到答案:OK據得到的消息,並嘗試用OK來回答。 但是它寫入這個無限到應用程序日誌:

消息:GenericMessage [有效載荷=字節[2],標題= {ip_packetAddress = 127.0.0.1/127.0.0.1:49489,IP_ADDRESS = 127.0.0.1,ID = 8db6aa3b-b56b-6dce-9554-c7b0ce050142,ip_port = 49489,ip_hostname = 127.0.0.1,時間戳= 1494442285767}]

消息有效負荷:OK

配置:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" 
    xmlns:int-ip="http://www.springframework.org/schema/integration/ip" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd 
     http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd"> 

    <int:channel id="sendUdp"/> 

    <int-ip:udp-outbound-channel-adapter id="udpOut" host="localhost" port="11111" 
            multicast="false" check-length="false" 
            channel="sendUdp" /> 

    <int-ip:udp-inbound-channel-adapter id="udpIn" port="11111" receive-buffer-size="500" 
            multicast="false" check-length="false" 
            channel="receiveUdp"/> 

    <int:service-activator id="updHandler" input-channel="receiveUdp" output-channel="sendUdp" ref="listener"/> 

</beans> 

@ServiceActivator 
public String handle(Message<?> message) { 
    System.out.println("*** Message: " + message); 
    String command = new String((byte[]) message.getPayload()); 
    System.out.println("*** Message Payload: " 
      + command); 
    String response = "OK"; 

    return response; 
} 
+0

這是否意味着您爲出站通道適配器向其發送消息的端口創建了具有入站通道適配器的循環? –

回答

1

您的出站適配器正在將郵件發送到入站適配器。如果您要回複數據包,則需要配置套接字和目標表達式。請參閱the documentation

<int-ip:udp-inbound-channel-adapter id="inbound" port="11111" channel="in" /> 

<int:channel id="in" /> 

<int:transformer expression="new String(payload).toUpperCase()" 
         input-channel="in" output-channel="out"/> 

<int:channel id="out" /> 

<int-ip:udp-outbound-channel-adapter id="outbound" 
         socket-expression="@inbound.socket" 
         destination-expression="headers['ip_packetAddress']" 
         channel="out" />