hi there,
I'm writing a RPC client using netty4. When the first message is pushed to the RPC client, the client chooses a server based on load balance logic and calls bootstrap.connect(host, port) and then calls channel.write(). The flush() method is called in the listener of the connect future. And once the channel is active, the future messages will trigger channel.writeAndFlush(). I made it this way as I don't want to maintain a queue myself as I know netty has outbound buffer to store the writes before flush.
The problem is that sometimes the first message's write operation is failed:
2016-01-04 14:42:58 DEBUG com.qq.gdt.rpc.netty.Connection$2.operationComplete(Connection.java:144) Send failed to 127.0.0.1, 59262, cause: java.lang.UnsupportedOperationException: unsupported message type: DefaultFullHttpRequest (expected: ByteBuf, FileRegion)
In my ChannelInitializer<SocketChannel> I have:
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new HttpClientCodec());
ch.pipeline().addLast(new NettyHttpRpcHandler());
}
So I think the problem is that the channel is not registered when I call write().
Am I right?
Should I use netty this way or should I use a queue on my own? Thanks.