SlideShare a Scribd company logo
Building scalable network applications
with Netty

Jaap ter Woerds
@jaaptw
XMS pin: EBDDFF9A
The trouble with synchronous IO
The trouble with synchronous IO
The trouble with synchronous IO
Creating your custom server
Creating your custom server
Netty?

Unified, asynchronous programming model. All
IO operations return immediately.
Netty?
Channel channel =..
channel.write(myMsg).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if(future.isSuccess()){
// Business as usual
} else{
// Handle failure
}
}
});
Netty?

Networking application framework with a modular
architecture and quite some ready reusable
components.
When should I care about this?

Custom servers / networking applications /
proxies
High concurrency
Netty concepts
Netty concepts

ByteBuf

random accessable sequence of bytes
Abstraction over plain byte arrays and NIO buffers
Netty concepts

ByteBuf

Use: encoding and decoding data
ByteBuf b = .
b.writeInt(3).writeBoolean(true);
Netty concepts

Channel

Link ('connection') to a resource that provides IO operations like read /
write
Netty concepts

Channel

Channel c = ..;
c.write(myMsg).addListener(CLOSE);
Netty concepts

ChannelHandler

IO event listener,handles outbound and / or inbound events.
Netty concepts

ChannelInboundHandler

Defines listener methods for incoming IO events
Netty concepts
ChannelInboundHandler
channelActive(ChannelHandlerContext ctx)
channelRead(ChannelHandlerContext ctx, Object msg)
channelReadComplete(ChannelHandlerContext ctx)
channelInactive(ChannelHandlerContext ctx)
....
Netty concepts

ChannelOutboundHandler

Defines listener methods for outgoing IO events
Netty concepts
ChannelOutboundHandler
write(ChannelHandlerContext ctx, Object msg, ChannelPromise..)
flush(ChannelHandlerContext ctx)
Netty concepts

ChannelPipeline

A List of ChannelHandlers that process incoming and outgoing events
in a specific order
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.
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.
Netty concepts
ChannelInitializer
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Decoders
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(MAX_LENGTH));
pipeline.addLast("stringDecoder", STRING_DECODER);
pipeline.addLast("moderatorHandler", moderatorHandler);
pipeline.addLast("chatServerHandler", chatServerHandler);
// Encoder
pipeline.addLast("stringEncoder", STRING_ENCODER);
}
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();
Netty architecture
Chain of responsibility
Incoming data flow through the ChannelPipeline
- Framing ByteBuf
- Decode frames
- Decode frames in DTOs/POJOs
Netty architecture
Netty components
Out of the box support for:
Streaming compression Zlib
SSL stream encryption
HTTP
WebSockets
ProtocolBuffer
XMS server protocol layer
Example SSE / CORS
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
}
Example SSE / CORS
Thank you!

Example code:
https://github.com/jaapterwoerds/jfall-netty4
Further reading:
https://nettio.io
http://xms.me
http://tech.ebuddy.com

More Related Content

PDF
Netty: asynchronous data transfer
PDF
Asynchronous, Event-driven Network Application Development with Netty
ODP
Building Netty Servers
PPT
Stackless Python In Eve
PDF
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
PPTX
Tutorial 4 adding some details
PDF
Adam Sitnik "State of the .NET Performance"
PDF
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)
Netty: asynchronous data transfer
Asynchronous, Event-driven Network Application Development with Netty
Building Netty Servers
Stackless Python In Eve
Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Tutorial 4 adding some details
Adam Sitnik "State of the .NET Performance"
function* - ES6, generators, and all that (JSRomandie meetup, February 2014)

What's hot (20)

PPT
Mirage: ML kernels in the cloud (ML Workshop 2010)
PDF
JavaScriptCore's DFG JIT (JSConf EU 2012)
PPTX
Mastering advanced concepts in Silverlight
PDF
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
KEY
Non blocking io with netty
PDF
Engineering fast indexes (Deepdive)
PPTX
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
PDF
tokyotalk
PPT
Tcp sockets
PDF
Go and Uber’s time series database m3
ODP
C++ development within OOo
PDF
Automatically Fusing Functions on CuPy
PPTX
The RabbitMQ Message Broker
PDF
MEAN-stack based sensor gateway
PDF
maXbox Starter 39 GEO Maps Tutorial
PDF
Multimaster
PPT
Easy Steps to implement UDP Server and Client Sockets
PDF
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
PDF
Q4.11: Using GCC Auto-Vectorizer
PPTX
Java Messaging with AMQP and RabbitMQ
Mirage: ML kernels in the cloud (ML Workshop 2010)
JavaScriptCore's DFG JIT (JSConf EU 2012)
Mastering advanced concepts in Silverlight
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Non blocking io with netty
Engineering fast indexes (Deepdive)
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
tokyotalk
Tcp sockets
Go and Uber’s time series database m3
C++ development within OOo
Automatically Fusing Functions on CuPy
The RabbitMQ Message Broker
MEAN-stack based sensor gateway
maXbox Starter 39 GEO Maps Tutorial
Multimaster
Easy Steps to implement UDP Server and Client Sockets
ceph::errorator<> throw/catch-free, compile time-checked exceptions for seast...
Q4.11: Using GCC Auto-Vectorizer
Java Messaging with AMQP and RabbitMQ
Ad

Similar to Building scalable network applications with Netty (20)

PDF
"One network to rule them all" - OpenStack Summit Austin 2016
PDF
Introduction to istio
PDF
NodeJS for Beginner
PPT
Qtp not just for gui anymore
PPTX
Vert.x for Microservices Architecture
PDF
M|18 Ingesting Data with the New Bulk Data Adapters
PPTX
Vert.x devoxx london 2013
PDF
KubeCon 2018 - Running VM Workloads Side by Side with Container Workloads
PPTX
Lambdas puzzler - Peter Lawrey
PPTX
Embedded networks
PDF
OSS Japan 2019 service mesh bridging Kubernetes and legacy
DOCX
Azure Service Bus Performance Checklist
PPTX
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
KEY
Is OSGi modularity always worth it?
PDF
16network Programming Servers
PDF
PDF
leewayhertz.com-How to build a dApp on Avalanche blockchain
PDF
Porting a Streaming Pipeline from Scala to Rust
KEY
What is the ServiceStack?
PPT
LECTURE-17(Socket Programming) Detailed.
"One network to rule them all" - OpenStack Summit Austin 2016
Introduction to istio
NodeJS for Beginner
Qtp not just for gui anymore
Vert.x for Microservices Architecture
M|18 Ingesting Data with the New Bulk Data Adapters
Vert.x devoxx london 2013
KubeCon 2018 - Running VM Workloads Side by Side with Container Workloads
Lambdas puzzler - Peter Lawrey
Embedded networks
OSS Japan 2019 service mesh bridging Kubernetes and legacy
Azure Service Bus Performance Checklist
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Is OSGi modularity always worth it?
16network Programming Servers
leewayhertz.com-How to build a dApp on Avalanche blockchain
Porting a Streaming Pipeline from Scala to Rust
What is the ServiceStack?
LECTURE-17(Socket Programming) Detailed.
Ad

More from NLJUG (20)

PPTX
The future of Web-Scale - Johan Tillema, Rene Boere & Chris Quach
PPTX
Speedy perception trumps speedy reception–smart asynchronous interactions - L...
PDF
Decoding the airspace above you with Java and $7 hardware - Bert Jan Schrijver
PPTX
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
PPTX
Kill the mutants and test your tests - Roy van Rijn
PDF
Real-time user interfaces - sosm gewoon makkelijker - Allard Buijze
PPTX
The end of traditional enterprise IT - ING's journey to the next generation I...
PDF
Performance van Java 8 en verder - Jeroen Borgers
PDF
Introduction to Reactive with Play and Akka - Markus Jura
PPTX
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...
PDF
Workshop angular dart presentatie - Atos
PDF
Workshop spring boot presentatie - Atos
PDF
Cultivating the jenkins job jungle with groovy - Patrick van Dissel
PDF
Rethink your architecture - Marten Deinum
PPTX
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopper
PDF
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...
PDF
Apache Wicket: 10 jaar en verder - Martijn Dashorst
PDF
Opening - Bert Ertman
PDF
Returning the right results - Jettro Coenradie
PDF
Reactive programming met Java 8 en Java EE 7 - Martijn Blankestijn
The future of Web-Scale - Johan Tillema, Rene Boere & Chris Quach
Speedy perception trumps speedy reception–smart asynchronous interactions - L...
Decoding the airspace above you with Java and $7 hardware - Bert Jan Schrijver
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
Kill the mutants and test your tests - Roy van Rijn
Real-time user interfaces - sosm gewoon makkelijker - Allard Buijze
The end of traditional enterprise IT - ING's journey to the next generation I...
Performance van Java 8 en verder - Jeroen Borgers
Introduction to Reactive with Play and Akka - Markus Jura
Web-scale op basis van Hadoop en Akka Reactive Streams - Johan Tillema, Rene ...
Workshop angular dart presentatie - Atos
Workshop spring boot presentatie - Atos
Cultivating the jenkins job jungle with groovy - Patrick van Dissel
Rethink your architecture - Marten Deinum
Evolutionary Algorithms: the key to solving complex Java puzzles! - Bas knopper
Modularity and Domain Driven Design; a killer Combination? - Tom de Wolf & St...
Apache Wicket: 10 jaar en verder - Martijn Dashorst
Opening - Bert Ertman
Returning the right results - Jettro Coenradie
Reactive programming met Java 8 en Java EE 7 - Martijn Blankestijn

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Empathic Computing: Creating Shared Understanding
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Approach and Philosophy of On baking technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Empathic Computing: Creating Shared Understanding
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
Approach and Philosophy of On baking technology
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf

Building scalable network applications with Netty