Netty in Action
Norman Maurer and Marvin Allen Wolfthal
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact
Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email:
orders@manning.com2016 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.
| Manning Publications Co.20 Baldwin RoadPO Box 761Shelter Island, NY 11964 | Development editors: Jeff Bleiel, Jennifer StoutTechnical development editor: Mark ElstonCopyeditor: Andy CarrollProofreader: Elizabeth MartinTechnical proofreaders: David Dossot, Neil RutherfordTypesetter: Dennis DalinnikCover designer: Marija Tudor |
ISBN: 9781617291470
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 EBM 20 19 18 17 16 15
Brief Table of Contents
Table of Contents
Foreword
There was a day when people believed that web application servers would let us forget about how we write HTTP or RPC servers. Unfortunately, this daydream did not last long. The amount of load and the pace of the functional changes we are dealing with continue to increase beyond the extent that a traditional three-tier architecture can afford, and we are being forced to split our application into many pieces and distribute them into a large cluster of machines.
Running such a large distributed system leads to two interesting problemsthe cost of operation and latency. How many machines could we save if we improved the performance of a single node by 30%, or by more than 100%? How could we achieve minimal latency when a query from a web browser triggers dozens of internal remote procedure calls across many different machines?
In Netty in Action, the first-ever book about the Netty project, Norman Maurer, one of the key contributors to Netty, gives you the definitive answers to such questions by showing you how to build a high-performance and low-latency network application in Netty. By the time you get to the end of this book, youll be able to build every imaginable network application, from a lightweight HTTP server to a highly customized RPC server.
Whats impressive about Netty in Action is not only that it is written by the key contributor who knows every single bit of Netty, but that it also contains case studies from several companiesTwitter, Facebook, and Firebase to name a fewthat use Netty in their production systems. Im confident that these case studies will inspire you by showing you how the companies that use them were able to unleash the power of their Netty-based applications.
You might be astonished to learn that Netty started as my personal project back in 2001 when I was an undergraduate student (http://t.motd.kr/ko/archives/1930), and that the project is still alive and kicking today, thanks to enthusiastic contributors like Norman, who spent many sleepless nights devoted to the project, (http://netty.io/community.html). I hope this book opens up another aspect of the project by inspiring its readers to contribute and continue to open the future of network programming.
T RUSTIN L EE
F OUNDER OF N ETTY
Preface
Looking back, I still cant believe that I did it.
When I started to contribute to Netty in late 2011, I would never have imagined that Id be writing a book about Netty and be one of the core developers of the Framework itself.
It all started when I got involved in 2009 with the Apache James project, a Java-based mail server developed under the Apache Software Foundation.
Apache James, like many applications, required a solid networking abstraction to build upon. While investigating the field of projects that provide networking abstractions, I stumbled upon Netty and immediately fell in love with it. As I became more familiar with Netty from a users perspective, I started to turn my gaze on improvements and giving back to the community.
Despite my first contributions being of limited scope, it became obvious very quickly how beneficial making contributions and the related discussions with the community, especially with Trustin Lee, the founder of the project, were to my personal growth. This experience grabbed hold of me, and I enjoyed spending my free time becoming more engaged in the community. I found myself helping on mailing lists and joining discussions on the IRC channel. Working on Netty began as a hobby but it quickly evolved into a passion.
My passion for Netty eventually led to my employment at Red Hat. This was a dream come true, as Red Hat paid me to work on the project I had come to love. I eventually came to know Claus Ibsen who was working on Apache Camel at the time (and still does). Claus and I came to the realization that Netty had a solid user base and good JavaDocs, but it lacked a higher level of documentation. Claus is the author of Camel in Action (Manning Publications, 2010), and he turned me on to the idea of writing a similar book for Netty. I thought about the idea for a few weeks, and eventually I was sold. This is how Netty in Action got off the ground.
While writing Netty in Action, my involvement in the community continued to grow. I eventually became the second most active contributor (after Trustin Lee) with over 1,000 commits. I found myself speaking about Netty at conferences and technical meetups around the world. Eventually Netty opened another employment opportunity at Apple Inc. where I am currently employed as a Senior Software Engineer on the Cloud Infrastructure Engineering Team. I continue to work on Netty and make regular contributions back to the community, while helping to drive the project.
N ORMAN M AURER
C LOUD I NFRASTRUCTURE E NGINEERING , A PPLE
My work as a Dell Services consultant at Harvard Pilgrim Health Care in Wellesley, MA, has focused primarily on creating reusable infrastructure components. Our goal is to expand the common code base in a way that not only benefits the software process in general, but also relieves application developers of responsibility for plumbing code that can be both pesky and mundane.
At one point it came to my attention that two related projects were working with a third-party claims-processing system that supported only direct TCP/IP communications. One of the projects needed to reimplement in Java a somewhat under-documented legacy COBOL module built on the vendors proprietary delimited format. This module was ultimately replaced by the other project, which would use a more recent XML-based interface to the same claims system (but still using straight sockets, no SOAP!).