获取数据报spring-integration的ip地址

时间:2017-11-10 13:35:30

标签: java spring udp spring-integration

我使用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
  }

1 个答案:

答案 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()服务方式中查看这些标题。