I need to make my websocket to close gracefully. Firstly send all messages that are waiting in buffer then close.
The trick you can use is to writeAndFlush an empty buffer, then attach a listener to that call. Unpooled.EMPTY_BUFFER can make this pretty easy.
channel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(... channel.close(); )};