# talent-aio **Repository Path**: nanfang/talent-aio ## Basic Information - **Project Name**: talent-aio - **Description**: No description available - **Primary Language**: Unknown - **License**: LGPL-2.1 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-06-12 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

talent-aio: 让天下没有难开发的即时通讯

关于talent-aio

  1. talent-aio是什么:talent-aio是基于java aio实现的即时通讯框架,功能类似netty和mina,但极易掌握,不需要各种学习才能入门,只需要花上半天学习helloworld就能比较好地掌握并实现一个性能极好的即时应用,并且天生不会有粘包问题;talent-aio性能极好:可同时支持10万级tcp长连接,彻底甩开当年的c10K问题每秒可收发处理138万以上条消息,每秒收发的消息大小可达137M以上,收发200万条消息,只需要1440毫秒
  2. 应用场景:即时通讯场景皆可,常见有如下一些场景
  3. 性能:请参考见下方的测试数据及截图
  4. 如何驾驭本框架:本项目提供了一个helloworld版的例子(位置见下图),如果已有bytebuffer知识基础,30分钟就可以上手使用,两天就能驾驭。后文有talent-aio快速上手指南,请参考

talent-aio产生的背景

  1. 2011年笔者参与了中兴某刀片的网管系统开发,虽然入职才3个月,但大领导还是亲点让笔者来改造原来的实时通讯模块,而且不允许使用mina。在这样的背景下,开始学习nio,改造后的系统,可管理上千个节点,消息收发速度极快,最近有和还在职的中兴同事了解过,核心代码仍然在运行,足见其稳定性,这就是后来talent-nio的雏形
  2. 后来担任热波间(一个直播平台)的平台端架构师,持续优化和封装了talent-nio,使之可以支持4万TCP长连接,每秒可以收发10万条消息,当年甚至扛住了自杀式的2000人同时无限点赞场景
  3. 因为热波间架构师的角色,认识了不少业界朋友,部分朋友表达希望开源talent-nio, 以便参考借鉴,但是talent-nio在易用性方面做得还不是很理想,开源出来的话要么无人问津要么就要消耗大量的咨询时间
  4. 几番考虑之后,写了talent-aio,线程池部分和部分思想来源于并优化于talent-nio,在性能大步提升的基础上,易用性得到根本性解决,其中锁的优化和API的重新设计耗费了不少脑细胞(有类似经历的的朋友知道,有些东西如何取舍很矛盾很纠结)。

talent-aio功能和入门简介

  1. 框架层面已经解决粘包问题,所以困扰很多用户的粘包问题将不会再存在
  2. 在框架层面为tcp client提供定时发心跳功能,用户只需要提供一个心跳包给框架----实现:com.talent.aio.client.intf.ClientAioHandler.heartbeatPacket()
  3. 可以方便地将链路和用户绑定,方便实际业务操作,譬如聊天、权限等
  4. 可以方便地将链路和群组绑定,方便实际业务操作,譬如群聊、类似频道需求等
  5. 除了启动性的API,其它开放给使用者的api,几乎都在com.talent.aio.common.Aio中,并且以static方法提供,方便使用
  6. 启动server请参见com.talent.aio.examples.helloworld.server.HelloServerStarter
    public class HelloServerStarter
    {
    	static ServerGroupContext serverGroupContext = null;
    	static AioServer aioServer = null; //可以为空
    	static ServerAioHandler aioHandler = null;
    	static ServerAioListener aioListener = null;
    	static String ip = null;
    	static int port = com.talent.aio.examples.helloworld.common.Const.PORT;
    
    	public static void main(String[] args) throws IOException
    	{
    		aioHandler = new HelloServerAioHandler();
    		aioListener = null; //可以为空
    		serverGroupContext = new ServerGroupContext<>(ip, port, aioHandler, aioListener);
    		aioServer = new AioServer<>(serverGroupContext);
    		aioServer.start();
    	}
    }
    		
  7. 启动client请参见com.talent.aio.examples.helloworld.client.HelloClientStarter
    public class HelloClientStarter
    {
    	private static String serverIp = null; //服务器的IP地址
    	private static int serverPort = 0; //服务器的PORT
    	private static AioClient aioClient;
    	private static ClientGroupContext clientGroupContext = null;
    	private static ClientAioHandler aioClientHandler = null;
    	private static ClientAioListener aioListener = null;
    
    	public static String SERVER_IP = "127.0.0.1"; //服务器的IP地址
    	public static int SERVER_PORT = 9321; //服务器的PORT
    
    	public static void main(String[] args) throws Exception
    	{
    		serverIp = "127.0.0.1";
    		serverPort = com.talent.aio.examples.helloworld.common.Const.PORT;
    		aioClientHandler = new HelloClientAioHandler();
    		aioListener = null;
    		clientGroupContext = new ClientGroupContext<>(serverIp, serverPort, aioClientHandler, aioListener);
    		aioClient = new AioClient<>(clientGroupContext);
    
    		String bindIp = null;
    		int bindPort = 0;
    		boolean autoReconnect = false; //暂时不支持自动重连,需要业务自己实现,后续版本会支持此属性为true
    		ClientChannelContext clientChannelContext = aioClient.connect(bindIp, bindPort, autoReconnect);
    
    		
    		//以下内容不是启动的过程,而是属于发消息的过程
    		HelloPacket packet = new HelloPacket();
    		packet.setBody("hello world".getBytes(HelloPacket.CHARSET));
    		Aio.send(clientChannelContext, packet);
    	}
    }
    		

talent-aio快速上手指南

本项目已经提供了一个helloworld版的例子,虽然有3个maven工程,6个java文件,但是有效代码只有区区100多行,结构清晰极易上手,位于:example\helloworld目录,可按如下步骤上手
  1. 先运行install.bat,用来安装本项目所有代码
  2. 运行com.talent.aio.examples.helloworld.server.HelloServerStarter
  3. 运行com.talent.aio.examples.helloworld.client.HelloClientStarter
  4. 顺藤摸瓜,花20分钟仔细阅读这个例子的100多行代码
  5. 恭喜您,你已经顺利上手了

参与talent-aio将得到什么福利

  1. java aio的驾驭需要有扎实的多线程基础,并且需要掌握很多多线程技巧,而talent-aio是将多线程技巧运用到极致的框架,所以一旦您参与到本项目,你将会从本项目中学到很多关于多线程的技巧。
  2. 本项目会陆续提供一些业界案例作为例子供大家参考,譬如融云的IM
  3. 本项目会提供一个技术交流群,与大家一起分解工作中遇到的困难

与项目一起成长

  1. 通过以下方式之一,加入talent-aio技术群
  2. 提交Issue 给项目提出有意义的新需求,或是帮项目发现BUG,或是上传你本地测试的一些数据让作者参考以便进一步优化。
  3. 点击右上方的 Star 以便随时掌握本项目的动态