22. Netty concepts
ChannelInitializer
Configures the pipeline for a Channel. In fact, a special case of
ChannelInboundHandler which creates the handlers for a channel
whenerver a new channel is registered.
23. Netty concepts
ChannelInitializer
Configures the pipeline for a Channel. In fact, a special case of
ChannelInboundHandler which creates the handlers for a channel
whenerver a new channel is registered.
25. Netty concepts
Bootstrap
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, BACKLOG)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(channelInitializer);
ChannelFuture f = b.bind(port).sync();
f.channel().closeFuture().sync();
26. Netty architecture
Chain of responsibility
Incoming data flow through the ChannelPipeline
- Framing ByteBuf
- Decode frames
- Decode frames in DTOs/POJOs
31. Example SSE / CORS
In the last handler we deal with normal POJO and handle an
incoming request without actually caring about the connection layer!
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
IncomingMessagePojo m = (IncomingMessagePojo) msg;
handle(m);// Login / Send a text message/ Handle create group
}