我使用spring集成通过UDP whit Real Time OS进行通信。我想从消息中找回IP地址。
@Bean
public MessageChannel udpIn()
{
return new DirectChannel();
}
@Bean
public UnicastReceivingChannelAdapter udpInboundAdapter()
{
UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(8888);
adapter.setOutputChannel(udpIn());
adapter.setListening(true);
adapter.setPoolSize(7);
adapter.start();
return adapter;
}
@ServiceActivator(inputChannel = "udpIn")
public void msgConsumer(Message<byte[]> message)
{
System.out.println("Message Received! Payload:" + Arrays.toString(message.getPayload()));
// HERE I want to get IP address
}
答案 0 :(得分:0)
UnicastReceivingChannelAdapter
生成Message
之类的内容:
message = getMessageBuilderFactory().withPayload(payload)
.setHeader(IpHeaders.HOSTNAME, hostName)
.setHeader(IpHeaders.IP_ADDRESS, hostAddress)
.setHeader(IpHeaders.PORT, port)
.setHeader(IpHeaders.PACKET_ADDRESS, packet.getSocketAddress())
.build();
在msgConsumer()
服务方式中查看这些标题。