2020-11-12 15:25:52 +08:00
|
|
|
|
基于Netty实现Mvc开发模式的框架
|
2020-11-03 14:00:28 +08:00
|
|
|
|
====================
|
|
|
|
|
|
2020-11-12 15:25:52 +08:00
|
|
|
|
## 特性
|
|
|
|
|
* 基于Netty,实现传统的MVC开发方式
|
2020-11-03 14:00:28 +08:00
|
|
|
|
|
2020-11-12 15:25:52 +08:00
|
|
|
|
## 场景
|
|
|
|
|
* TCP协议服务端开发
|
2020-11-03 14:00:28 +08:00
|
|
|
|
|
2020-11-12 15:25:52 +08:00
|
|
|
|
## 代码仓库
|
2021-11-13 11:56:53 +08:00
|
|
|
|
* Gitee仓库地址:[http://115.29.108.160:3000/TripartiteOpenSource/netmc](http://115.29.108.160:3000/TripartiteOpenSource/netmc)
|
|
|
|
|
* Github仓库地址:[http://115.29.108.160:3000/TripartiteOpenSource/netmc](http://115.29.108.160:3000/TripartiteOpenSource/netmc)
|
2020-11-03 14:00:28 +08:00
|
|
|
|
|
2020-11-12 15:25:52 +08:00
|
|
|
|
## 下载方式
|
2021-11-13 11:56:53 +08:00
|
|
|
|
* Git下载命令:`git clone http://115.29.108.160:3000/TripartiteOpenSource/netmc.git -b master`
|
2020-11-03 14:00:28 +08:00
|
|
|
|
|
2020-11-12 15:25:52 +08:00
|
|
|
|
## 项目结构
|
2020-11-03 14:00:28 +08:00
|
|
|
|
```sh
|
|
|
|
|
└── framework
|
|
|
|
|
├── codec 编码解码
|
2020-11-12 15:25:52 +08:00
|
|
|
|
├── core 消息分发、处理
|
2020-11-03 14:00:28 +08:00
|
|
|
|
└── session 消息发送和会话管理
|
|
|
|
|
```
|
2020-11-12 15:25:52 +08:00
|
|
|
|
|
|
|
|
|
## 使用说明
|
2020-11-03 14:00:28 +08:00
|
|
|
|
|
|
|
|
|
* @Endpoint,服务接入点,等价SpringMVC的 @Controller;
|
|
|
|
|
* @Mapping,定义消息ID,等价SpringMVC中 @RequestMapping;
|
|
|
|
|
* @AsyncBatch, 异步批量消息,对于并发较高的消息,如0x0200(位置信息汇报),使用该注解,显著提升Netty和MySQL入库性能。
|
|
|
|
|
|
2020-11-12 15:25:52 +08:00
|
|
|
|
## 消息接入:
|
2020-11-03 14:00:28 +08:00
|
|
|
|
```java
|
|
|
|
|
@Endpoint
|
|
|
|
|
public class JT808Endpoint {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private LocationService locationService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceService deviceService;
|
|
|
|
|
|
|
|
|
|
//异步批量处理 队列大小20000 最大累积200处理一次 最大等待时间5秒
|
|
|
|
|
@AsyncBatch(capacity = 20000, maxElements = 200, maxWait = 5000)
|
|
|
|
|
@Mapping(types = 位置信息汇报, desc = "位置信息汇报")
|
|
|
|
|
public void 位置信息汇报(List<T0200> list) {
|
|
|
|
|
locationService.batchInsert(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
@Mapping(types = 终端注册, desc = "终端注册")
|
|
|
|
|
public T8100 register(T0100 message, Session session) {
|
|
|
|
|
Header header = message.getHeader();
|
|
|
|
|
|
|
|
|
|
T8100 result = new T8100(session.nextSerialNo(), header.getMobileNo());
|
|
|
|
|
result.setSerialNo(header.getSerialNo());
|
|
|
|
|
|
|
|
|
|
String token = deviceService.register(message);
|
|
|
|
|
if (token != null) {
|
|
|
|
|
session.register(header);
|
|
|
|
|
|
|
|
|
|
result.setResultCode(T8100.Success);
|
|
|
|
|
result.setToken(token);
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
result.setResultCode(T8100.NotFoundTerminal);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-11-12 15:25:52 +08:00
|
|
|
|
详细的例子请参考Test目录
|
2020-11-03 14:00:28 +08:00
|
|
|
|
|
2021-11-13 11:56:53 +08:00
|
|
|
|
当前项目是Fork [剑器近](https://gitee.com/yezhihao) 的 [netmc](https://gitee.com/yezhihao/netmc?_from=gitee_search)
|