Spring Integration - sending TCP messages to IoT devices

17 May 2018
@Bean
public MessageChannel inboundChannel() {
  return new DirectChannel();
}

@Bean
public MessageChannel outboundChannel() {
  return new DirectChannel();
}

@Bean
public AbstractServerConnectionFactory serverConnectionFactory() {
  TcpNetServerConnectionFactory factory = new TcpNetServerConnectionFactory(port);
  factory.setSoKeepAlive(true);
  factory.setSingleUse(false);
  return factory;
}

@Bean
public TcpReceivingChannelAdapter inboundChannelAdapter() {
  TcpReceivingChannelAdapter receivingChannelAdapter = new TcpReceivingChannelAdapter();
  receivingChannelAdapter.setConnectionFactory(serverConnectionFactory());
  receivingChannelAdapter.setOutputChannel(inboundChannel());
  return receivingChannelAdapter;
}


@Bean
@ServiceActivator(inputChannel = "outboundChannel")
public MessageHandler outboundClient() {
  TcpSendingMessageHandler sendingMessageHandler = new TcpSendingMessageHandler();
  sendingMessageHandler.setConnectionFactory(serverConnectionFactory());
  return sendingMessageHandler;
}
Jakub Pomykała Web Developer

Jakub Pomykała, Freelancer, Entrepreneur, Aspiring Digital Nomad.
Spring Framework & ReactJS developer.
Founder of VendingMetrics.com and PlaceFlare.com.

"Spring Integration - sending TCP messages to IoT devices"

Share
Create
Post