netmc/README.md

75 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

基于Netty实现Mvc开发模式的框架
====================
## 特性
* 基于Netty实现传统的MVC开发方式
## 场景
* TCP协议服务端开发
## 代码仓库
* 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)
## 下载方式
* Git下载命令`git clone http://115.29.108.160:3000/TripartiteOpenSource/netmc.git -b master`
## 项目结构
```sh
└── framework
├── codec 编码解码
├── core 消息分发、处理
└── session 消息发送和会话管理
```
## 使用说明
* @Endpoint服务接入点等价SpringMVC的 @Controller
* @Mapping定义消息ID等价SpringMVC中 @RequestMapping
* @AsyncBatch, 异步批量消息对于并发较高的消息如0x0200(位置信息汇报)使用该注解显著提升Netty和MySQL入库性能。
## 消息接入:
```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;
}
}
```
详细的例子请参考Test目录
当前项目是Fork [剑器近](https://gitee.com/yezhihao) 的 [netmc](https://gitee.com/yezhihao/netmc?_from=gitee_search)