netty深入学习之中的一个: 入门篇

netty深入学习之中的一个: 入门篇

本文代码下载:

http://download.csdn.net/detail/cheungmine/8497549

1)Netty是什么

Netty是Java NIO之上的网络库(API)。Netty 提供异步的、事件驱动的网络应用程序框架和工具,用以高速开发高性能、高可靠性的网络服务器和客户端程序。

2)Netty的特性

统一的API。适用于不同的协议(堵塞和非堵塞)。基于灵活、可扩展的事件驱动模型。高度可定制的线程模型。可靠的无连接数据Socket支持(UDP)性能。更好的吞吐量,低延迟。更省资源,尽量降低不必要的内存拷贝。完整的SSL/ TLS和STARTTLS的支持。能在Applet和Android的限制环境运行良好。健壮性:不再因过快、过慢或超负载连接导致OutOfMemoryError。不再有在高速网络环境下NIO读写频率丌一致的问题。易用:完好的Java doc,用户指南和样例,简洁简单。仅依赖于JDK1.5。

3)Netty高速上手

俗话说。万事开头难,因此我构建了一个Netty项目模板:avro-channel。目的是结合Netty和Avro实现异步传输数据和RPC(远程过程调用)。avro-channel最初的目的是为了实现一套RPC服务。发现了Netty功能如此强大之后,就想使用Netty构建整个后端体系。因此,本文的样例代码提供了一个简单的Netty入门:HelloWorldServer和HelloWorldClient。

构建项目非常easy。第一步。手工安装依赖jar到你的机器上,进入项目pom.xml所在文件夹:

$ python ./mvn-install-lib.py

上面这个命令把lib/下的jar包安装到你的机器上。然后运行以下的命令构建:

$ mvn clean compile package assembly:assembly

最后打开2个终端a,b。分别运行以下的服务器和客户端:

a 启动服务器:
        $ java -jar ./target/avro-channel-1.0-PRE.jar

        $ java -cp ./target/avro-channel-1.0-PRE.jar avro.channel.server.netty.HelloWorldServer
b 启动客户端:
        $ java -cp ./target/avro-channel-1.0-PRE.jar avro.channel.client.netty.HelloWorldClient

4)样例工程结构

avro-channel是标准的maven(3.05)工程,文件夹结构例如以下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAAHsCAIAAADXXkGeAAAWtklEQVR4nO2d25MU133H+0+xivLGhZ+g4KGfI1fKSZlKqVLrXUsgJXJv4kpiq6TckAoJGVit4lKvKy8prMRJbINQgoWsYSwhQIDAEmBAIBA7MCywYmFvw2W5CAuOevMwMz19OT19ds453X369/3UeVh6eqaH/dA9A/uZHxYDxLA2bh/HIrWs+fseFqllzd31sEgta/aOp3bdmd1xb8q9O/na7cuvzl8cmR9/9WZ9+Ma5DY2x9bOfrZse+8nM5H7lB8USX9bMbU/p+ure1GsPv/jNVw9n7s5uvn7plQvH1z64t+erBx8215d3f3v19CuqD4q1iGVN3/bUrntTrz28v/Ph/Z0LC2xhgV3+/Q8+++ilL268xb7c9/D+7gd33508/qzyg2KJL+vavKd2+cof3t+5sLAwfvj7p/b/y9VPX35w990vb//m/s3tnx97RvlBe13VJyz75U+yOdDQr/L//XrX5j3r6i1P7bp3LaicnT/05MkP/uHKJ+vu39x+r7HlzszPJ47+UPlBe13VJyx7/YlsDjT0y/x/v97VW5515aandt25+q9N31/ee9v76u7Y/u+d2PPDiWP/dGfm57ev/vutz3966cjfKj9or6v6uGWvP5HNgYZ+kf/v17ty07Mmbng9rzff+WD4lZHIxttXRpq+78//L3swfWZv//Fdf3P5yDO3Pv/pjYuvNs7/+PNjP7p0dqvMcdWt6vcs+6Xj2Rxo6L/z//16Ezc869J1r7e15e09fd/45iNL+iLbb13e2PR9t/HLL+Y/+vT9x37/27+8+NEPGud/PDv2/PTp566d/PsLv3MSH/nY6HKrxeCb3qXr9RdXWss31Zu37t9kWytH91+vv7jSGnyzOmhZ1srR/de9S9erg5bP0H8lPu3Obss31S9drw5a9oubhlqbnqwmPAcvsmf7+XA3xo/S3NLlWWW6rPGG18P61Y49X//GNwcGBh5Z0he56cbFl5u+b0293pj4t5PvrjryzuMXPny6KXvy+FCj0agffDrhkevr1ox+0Px625BlDf1n84uVzY31dSutwW2tL1q3NrzxRnXQspZvrI9H7hhd4d3aW6w11fGGN350dLllrzua8Bz4eyZtbH4RfMLVQf5TymFZ9TlvsesXb7V8Dw4OPrKkL3Jro77O9z1df/XEzj89vOMvzu97YvL40JWjT018/Hij0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B5eSAcnJAOTmgnBxQTo7/B65ivu5n7vs4AAAAAElFTkSuQmCC" alt="" />

lib/netty包括jboss.netty和io.netty二个版本号系列。最后让我们看看完整的pom.xml:

<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <description>avro-channel is a java framework for data transport and rpc. created by zhangliang</description> <!--
build all:
$ mvn clean compile package assembly:assembly
-->
<groupId>avro.channel</groupId>
<artifactId>avro-channel</artifactId>
<packaging>jar</packaging>
<version>1.0-PRE</version> <name>avro-channel</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler-plugin.version>2.3.2</compiler-plugin.version>
<avro.version>1.7.7</avro.version>
<slf4j.version>1.7.10</slf4j.version>
<jackson.version>1.9.13</jackson.version>
<jboss.netty.version>3.2.10.Final</jboss.netty.version>
<io.netty.version>5.0.0.Alpha2</io.netty.version>
<!-- test server class: HelloWorldServer -->
<!-- test client class: HelloWorldClient -->
<main.class>avro.channel.server.netty.HelloWorldServer</main.class>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency> <dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>${jboss.netty.version}</version>
</dependency> <dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${io.netty.version}</version>
</dependency> <dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>${avro.version}</version>
</dependency> <dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-ipc</artifactId>
<version>${avro.version}</version>
</dependency> <dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson.version}</version>
</dependency> <dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version> <executions>
<execution>
<id>schemas</id>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
<goal>protocol</goal>
<goal>idl-protocol</goal>
</goals> <configuration>
<sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> <!--
1) Build project jar and copy all dependencies into lib/:
$ mvn clean compile
$ mvn package 2) Start Server:
$ java -jar ./target/avro-channel-1.0-PRE.jar
or
$ java -cp ./target/avro-channel-1.0-PRE.jar avro.channel.server.netty.HelloWorldServer 3) Start Client:
$ java -cp ./target/avro-channel-1.0-PRE.jar avro.channel.client.netty.HelloWorldClient
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> <!--
1) Package all jars in one: ${name}-jar-with-dependencies.jar
$ mvn assembly:assembly 2) Run server:
$ java -jar ./target/avro-channel-1.0-PRE-jar-with-dependencies.jar
or
$ java -cp ./target/avro-channel-1.0-PRE-jar-with-dependencies.jar avro.channel.server.netty.HelloWorldServer 3) Run client:
$ java -cp ./target/avro-channel-1.0-PRE-jar-with-dependencies.jar avro.channel.client.netty.HelloWorldClient
-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin> </plugins>
</build>
</project>
上一篇:Java学习——Ubuntu下jdk的安装以及Java环境的配置


下一篇:HBase的安装部署以及简单使用