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/Hij0Tj/4V91efw9G23/fP2POa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o7/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>

netty深入学习之中的一个: 入门篇的更多相关文章

  1. 【浅墨Unity3D Shader编程】之中的一个 夏威夷篇:游戏场景的创建 &amp; 第一个Shader的书写

    本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨)  ...

  2. 学习笔记-CCS-MSP430F5529[快速入门篇一]

    由于最近竞赛需要使用TI公司的MSP430系列芯片,本人在最近两天匆忙的学习了一下MSP430F5529(下文统一称作5529)的使用.写下本文是为了将这两天学习内容做一个复习,并且将学习过程中遇到的 ...

  3. cocos2dx 3.1从零学习(一)——入门篇(一天学会打飞机)

    没办法,浏览这么高,为啥没人投票呢?朋友们,我这篇文章參加了csdn博文大赛.喜欢的来点个赞吧!点击:http://vote.blog.csdn.net/Article/Details?article ...

  4. 从零开始学习jQuery (一) 开天辟地入门篇

    一.摘要 本系列文章将带您进入jQuery的精彩世界, 其中有很多作者具体的使用经验和解决方案,  即使你会使用jQuery也能在阅读中发现些许秘籍. 本篇文章是入门第一篇, 主要是简单介绍jQuer ...

  5. Web 前端开发学习之路(入门篇)

    字数1374 阅读4622 评论0 喜欢49 以前学习过一段时间的web前端开发,整理了一些我看过的/我认为比较好的学习资料(网站.书籍).不要问我为啥没有进阶版,我只是一条产品汪而已,求轻喷.== ...

  6. 学习笔记-CCS-MSP430F5529[快速入门篇二]

    由于2021的全国电赛延期了,从今天开始打算好好整理一下使用CCS编程的经验,本篇笔记会好好整理一下我备赛期间用CCS写的程序,包括外部中断,定时器部分的定时中断,定时器输入捕获,PWM波输出,UAR ...

  7. Python 学习之中的一个:在Mac OS X下基于Sublime Text搭建开发平台包括numpy,scipy

    1 前言 Python有许多IDE能够用,官方自己也带了一个,Eclipse也能够. 但我在使用各种IDE之后,发现用Sublime Text是最好用的一个.因此.我都是用Sublime Text来编 ...

  8. Java并发学习之中的一个——线程的创建

    本文是学习网络上的文章时的总结,感谢大家无私的分享. 1.与每一个Java语言中的元素一样,线程是对象.在Java中,我们有两种方式创建线程: a.通过直接继承thread类,然后覆盖run方法. b ...

  9. Vue 学习笔记之快速入门篇

    Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层,不仅易于上手,还便于与 ...

随机推荐

  1. 算法笔记_173:历届试题 斐波那契(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 斐波那契数列大家都非常熟悉.它的定义是: f(x) = 1 .... (x=1,2) f(x) = f(x-1) + f(x-2) ... ...

  2. Spring Tool Suite 使用自带maven速度慢---修改settings.xml更新mirror方法

    (1)打开sts,windows --> preference,找到maven,并设置如下. (2)修改该文件,如下 <mirror> <id>nexus-aliyun& ...

  3. 项目中用到的ext及js细节

    1.js中无replaceAll方法,但能够用replace(regex," "),第一个參数是正則表達式,第二个參数是string,eg:str.replace(/\r\n/g, ...

  4. JSON path

    https://github.com/itguang/gitbook-smile/blob/master/springboot-fastjson/fastjson%E4%B9%8BJSONPath%E ...

  5. jsp&html页面知识点集锦

      CreateTime--2016年12月16日16:08:03Author:Marydonjsp&html页面知识点集锦1.标签的class属性 标签同时拥有多个class时,要写在同一个 ...

  6. 如何从maven资源库下载jar包

      如何从maven资源库下载jar包 CreationTime--2018年6月7日09点00分 Author:Marydon 一.前提 需要安装并配置maven环境 二.准备工作 1.在桌面创建一 ...

  7. 以__name__进行单元测试

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #以__name__进行单元测试 #何为单元测试? #单元测试(模块测试)是开发者编写的一小段代码,用于检测被 ...

  8. nmon与nmonanalyser系统性能分析

    nmon与nmonanalyser系统性能分析(图表) - [系统架构] 2011-05-15 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://www.blogbus.c ...

  9. C#多线程之 ManualResetEvent和AutoResetEvent

    初次体验 ManualResetEvent和AutoResetEvent主要负责多线程编程中的线程同步:以下一段是引述网上和MSDN的解析: 在.Net多线程编程中,AutoResetEvent和Ma ...

  10. pip简单配置

    pip安装Python模块的工具,等价于Redhat中的yum! 01.下载 百度云盘:http://pan.baidu.com/s/1eRHGBfk             ###相关的 Linux ...