Yunus Einsteinium
Yunus Einsteinium

Reputation: 1180

TCP server With Spring Integration Fails

Using spring boot 2 and spring integration to develop a non-blocking TCP for stream-oriented listening sockets/server with following code.

@Bean
public TcpNetServerConnectionFactory cf() {
    TcpNetServerConnectionFactory cf = new TcpNetServerConnectionFactory(8595);
    cf.setSerializer(new ByteArrayCrLfSerializer());
    cf.setDeserializer(new ByteArrayCrLfSerializer());
    return cf;
}

@Bean
public TcpReceivingChannelAdapter inbound(AbstractServerConnectionFactory cf) {
    TcpReceivingChannelAdapter adapter = new TcpReceivingChannelAdapter();
    adapter.setConnectionFactory(cf);
    adapter.setOutputChannel(tcpIn());
    return adapter;
}

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

@Transformer(inputChannel = "tcpIn", outputChannel = "serviceChannel")
@Bean
public ObjectToStringTransformer transformer() {
    return new ObjectToStringTransformer();
}

@ServiceActivator(inputChannel = "serviceChannel")
public void service(String jsonInString) {
    System.out.println(jsonInString);
}

The app starts indicating tcp port is listening as expected, but after a few minutes following exception is thrown:

2018-03-09 13:21:51.168  WARN 1202 --- [-worker-ELG-3-2] i.n.c.AbstractChannelHandlerContext      : Failed to mark a promise as failure because it has succeeded already: DefaultChannelPromise@331a9712(success)

java.lang.NoSuchMethodError: io.netty.handler.codec.http2.Http2ConnectionEncoder.writePing(Lio/netty/channel/ChannelHandlerContext;ZLio/netty/buffer/ByteBuf;Lio/netty/channel/ChannelPromise;)Lio/netty/channel/ChannelFuture;
    at io.grpc.netty.NettyClientHandler.sendPingFrame(NettyClientHandler.java:568) ~[grpc-netty-1.9.0.jar!/:1.9.0]
    at io.grpc.netty.NettyClientHandler.write(NettyClientHandler.java:287) ~[grpc-netty-1.9.0.jar!/:1.9.0]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) [netty-transport-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:730) [netty-transport-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:816) [netty-transport-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:723) [netty-transport-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:1041) [netty-transport-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.channel.AbstractChannel.write(AbstractChannel.java:295) [netty-transport-4.1.22.Final.jar!/:4.1.22.Final]
    at io.grpc.netty.WriteQueue$AbstractQueuedCommand.run(WriteQueue.java:186) [grpc-netty-1.9.0.jar!/:1.9.0]
    at io.grpc.netty.WriteQueue.flush(WriteQueue.java:124) [grpc-netty-1.9.0.jar!/:1.9.0]
    at io.grpc.netty.WriteQueue.access$000(WriteQueue.java:32) [grpc-netty-1.9.0.jar!/:1.9.0]
    at io.grpc.netty.WriteQueue$1.run(WriteQueue.java:44) [grpc-netty-1.9.0.jar!/:1.9.0]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) [netty-common-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) [netty-common-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463) [netty-transport-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) [netty-common-4.1.22.Final.jar!/:4.1.22.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.22.Final.jar!/:4.1.22.Final]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161]

Upvotes: 1

Views: 752

Answers (1)

royalghost
royalghost

Reputation: 2808

Upon looking at the API for writePing method[1], it looks like you are missing the second parameter as it expects four parameters as show below :

(ChannelHandlerContext ctx,
 boolean ack,
 long data,
 ChannelPromise promise)

From your stacktrace, I can see that you are passing only 3 parameters:

java.lang.NoSuchMethodError: io.netty.handler.codec.http2.Http2ConnectionEncoder.writePing(Lio/netty/channel/ChannelHandlerContext;ZLio/netty/buffer/ByteBuf;Lio/netty/channel/ChannelPromise;)

Can you try adding a second parameter, boolean ack ?

[1]https://netty.io/4.1/api/io/netty/handler/codec/http2/Http2FrameWriter.html#writePing-io.netty.channel.ChannelHandlerContext-boolean-long-io.netty.channel.ChannelPromise-

Upvotes: 1

Related Questions