0

I configured a TCP Client with the Java DSL of Spring Integration. It looks like this

    @Bean
    public TcpSendingMessageHandler tcpClient()
    {
        return Tcp
            .outboundAdapter(
                Tcp.nioClient("localhost", 9060)
                   .deserializer(new ByteArrayLfSerializer())
                   .soKeepAlive(false)
                   .leaveOpen(false)
                   .taskExecutor(Executors.newSingleThreadExecutor())
                   .get()
            )
            .clientMode(false)
            .get();
    }

And I am using it in a Service to send messages to the TCP socket the client is connected to:

    @Slf4j
    @Service
    public class TcpClientConnectionService
    {
        private final TcpSendingMessageHandler messageHandler;

        @Autowired
        public TcpClientConnectionService(final TcpSendingMessageHandler messageHandler)
        {
            this.messageHandler = messageHandler;
            this.messageHandler.start();
        }

        public void sendMessage(final String message)
        {
            messageHandler.handleMessage(new GenericMessage<>(message));

            log.debug("Message: " + message + " send");
        }
    }

But in production I am getting the follwing warning rather regulary and I do not know what the issue is and how to fix it.

o.s.i.i.tcp.connection.TcpNioConnection : No publisher available to publish TcpConnectionOpenEvent o.s.i.i.tcp.connection.TcpNioConnection : No publisher available to publish TcpConnectionCloseEvent

It would be great if somebody could help me out since I was not able to find anything by googling.

Sebastian
  • 858
  • 7
  • 21

1 Answers1

1

The nested factory is not initialized properly because you are incorrectly calling .get() on the spec, which subverts Spring initialization.

I configured a TCP Client with the Java DSL of Spring Integration. It looks like this

@Bean
public TcpSendingMessageHandler tcpClient()
{
    return Tcp
        .outboundAdapter(
            Tcp.nioClient("localhost", 9060)
               .deserializer(new ByteArrayLfSerializer())
               .soKeepAlive(false)
               .leaveOpen(false)
               .taskExecutor(Executors.newSingleThreadExecutor()))
        .clientMode(false)
        .get();
}

Or move the factory definition to a top level @Bean.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thank you for the quick help. I will try it out right now. Another quick question: Is there a benefit to use `clientMode` in this use case? – Sebastian May 26 '20 at 07:01
  • The configuration you provided somehow resulted in the same warnings but moving the ConnectionFactory to a top level `@Bean` fixed it for me. – Sebastian May 26 '20 at 12:35
  • Don't ask supplemental questions in comments; it's unusual to use client mode here. – Gary Russell May 26 '20 at 14:25