diff --git a/.gitignore b/.gitignore
index a0043cc4..61f3420f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,15 @@
*.class
*.classpath
*.project
-*/.settings/*
-*/target/*
-*/bin/*
-*/WebContent/*
+*/.settings/
+*/target/
+*/bin/
+*/WebContent/
+*/.DS_Store
-.idea/*
-*.jar
-*.war
-*.ear
-*.iml
-./target/*
+.idea/
+
+target/
# Mobile Tools for Java (J2ME)
.mtj.tmp/
@@ -20,6 +18,9 @@
*.jar
*.war
*.ear
+*.iml
+.DS_Store
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+mpush-test/src/test/resources/application.conf
diff --git a/Changelog.md b/Changelog.md
new file mode 100644
index 00000000..fc7e5191
--- /dev/null
+++ b/Changelog.md
@@ -0,0 +1,126 @@
+#### v0.8.0
+
+1. 增加本地ip和外网ip配置项
+2. ConnServer和GatewayServer增加bind ip和register ip 配置项
+3. ConnServer增加权重等扩展属性配置项
+4. 系统模块化重构:SPI增加Plugin接口及其init方法,增加MPushContext对象,方便插件初始化时控制系统内部对象
+5. 广播推送增加RedisBroadcastController存储推送结果到redis, 并通过redis控制推送任务
+6. 启动脚本优化修复不能加载自定义SPI的bug
+7. EventBus订阅方法增加@AllowConcurrentEvents注解,提高高并发性能
+8. 代码优化,当GatewayClient启动时从ZK获取的链接为空时,后续会尝试重新获取
+9. 优化ServerLauncher和PushClient代码,方便自定义系统配置和spring方式启动
+10. 依赖类库升级,日志优化,及其他bug fix
+
+
+
+
+#### v0.7.1
+
+1. 修复网关客户端获取连接失败bug
+2. 修复ZK临时节点在连接断开未重新注册bug
+3. PushClient代码优化,依赖服务启动/停止顺序优化
+4. 增加查询在线用户列表接口,修复Json转换bug
+5. 修改http代理request.copy引用计数bug
+6. 依赖类库升级,日志优化,及其他bug fix
+
+
+
+
+#### v0.7.0
+
+1. 网关新增udp, sctp协议支持,目前支持的协议有tcp/udp/sctp/udt, 推荐tcp
+2. 增加websocket接入层,和原接入层共享线程资源,增加websocket js client
+3. 抽象出cache层,不再直接依赖redis模块,支持自定义缓存实现
+4. 抽象出服务注册与发现层,不再直接依赖Zookeeper模块, 支持自定义服务注册发现
+5. 添加测试用的默认缓存实现以及注册发现实现,在不安装redis,zk的情况下也能进行源码测试
+6. 推送中心模块重构,支持不同的消息来源,支持自定义消息来源,编写从MQ订阅消息demo
+7. Gateway Client代码重构,支持多线程,多连接数配置
+8. 线程池优化,重新设计各模块线程配置方式,EventBus使用动态线程池,增加Netty线程池监控
+9. PushClient任务超时代码优化, 优化Timer任务线程池,在任务取消后直接从队列里删除
+10. PushSender同步调用直接返回PushResult不再兼容老的返回Boolean类型
+11. 修改TimeLine多线程bug,优化PushRequest多线程下代码
+12. 修复ID_SEQ在高并发下重复的问题,不再使用LongAdder
+13. 代码优化,内存优化,修复推送超时问题
+14. 增加推送压测代码,增加推送统计及流控QPS监控等
+15. 增加tcp/udp 发送接收缓冲区配置
+16. 增netty write-buffer-water-mark配置
+17. 代码优化, 内存优化,及时释放无用的对象
+18. 流控调优,默认关闭流量整形
+19. 增加jmx监控统计, 脚本加入JMX设置,jvm设置
+20. 增加PushCenter消息流转时间线, 方便监控消息的各个生命周期的耗时(PushClient -> GatewayClient -> GatewayServer -> PushCenter -> ConnServer -> Client)
+21. 服务启动/停止流程优化,boot chain正序启动,逆序停止,启动流程日志优化
+
+
+
+
+#### v0.6.1
+
+1. 产品版本策略修改,主版本前移一位,最后一位用于小版本bug fix
+2. 新增支持单机多实例部署方式
+3. 升级依赖类库,解决由于版本升级引起的jedis和zk兼容性问题
+4. 核心日志打印内容优化,更利于问题排查
+5. 修复connId高并发下可能重复的bug
+6. 增加压测代码,优化测试模块
+7. 配置文件优化,增加相应的注释说明
+8. 修复流控发送计数引起的bug
+9. 优化内存占用,连接断开后立即释放Connection的引用
+10. 其他bug fix及代码优化
+
+
+
+
+#### v0.0.6
+
+1. 网关服务增加UDP及组播支持,后续网关部分的TCP部分将逐步淘汰
+2. 新增用户打标,修改标签,取消标签功能
+3. 全网推送增加按标签过滤,按条件过滤,条件表达式目前支持javascript
+4. Service模块代码优化,增加同步启动/停止,超时监控
+5. 推送模块增加流控功能, 分为全局流控和广播流控,以及基于Redis实现的实时流控
+6. 由于网关采用了UDP,PushClient模块和踢人模块增加UDP支持
+7. 线程池代码优化,线程命名调整, 支持配置调整Netty boss和work的线程数
+8. 路由模块:客户端定义增加SPI支持, 用户可自定义控制多端在线策略
+9. 日志及配置项优化,增加mp.home配置项
+10. 心跳检测优化,连接一建立就开始检测心跳,防止客户端握手失败或未握手的情况
+
+
+
+
+#### v0.0.5
+
+1. redis 增加redis3.x集群支持, 配置项不再兼容
+2. 绑定用户调整,校验重复绑定,以及未解绑,就绑定的场景
+3. 新增client push上行功能, 并支持用户以SPI方式集成自己的Handler
+4. 全网推送增加按标签过滤推送用户
+5. 增加流量控制,tcp发送缓冲区检测代码优化
+6. 修复ACK超时方法调用错误bug,增加ack超时时间设置
+7. 解码优化, 不再抛出解码异常,取消循环解码
+8. NettyServer 增加IoRate设置,优雅停止流程优化,先关闭main reactor
+9. 心跳优化,连接建立后就开始计算心跳
+10. sessionId生成器性能优化,采用jdk8 LongAdder
+11. Service模块开始使用java8 CompletableFuture
+12. SPI模块优化增加@Spi注解,多个实现可以指定顺序
+13. Profile 性能分析模块优化,增加性能监控开关配置,加入javassist优化性能
+14. zk client 代码优化,修改临时节点重复注册问题,增加DNS ZK Node
+15. 脚步修改start-foreground不能加载配置项bug, 修改windows启动命令bug
+16. 其他bug fix
+
+
+
+
+#### v0.0.4
+
+1. push client API 调整
+2. push 接口增加了全网推送功能
+3. 用户下线后路由信息不再删除,而是修改为下线状态
+4. 修复ZK Client临时节点断开后,不能恢复注册的bug
+5. 其他bug fix
+
+#### v0.0.3
+
+1. 增加了消息ACK功能
+2. 修复脚本换行问题
+3. bug fix
+
+### v0.0.2
+
+1. 增加多端同时在线攻能
diff --git a/README.md b/README.md
index f5a812c9..e6bbb603 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,292 @@
-# mpush
-mobile push
+## [详细教程](http://mpush.mydoc.io)
+
+* 官网:[https://mpusher.github.io](https://mpusher.github.io)
+* 文档:[http://mpush.mydoc.io](http://mpush.mydoc.io)
+* QQ群:__114583699__
+
+## 源码
+* group [https://github.com/mpusher/](https://github.com/mpusher/) 源代码空间
+* server [https://github.com/mpusher/mpush](https://github.com/mpusher/mpush) 服务端源码
+* alloc [https://github.com/mpusher/alloc](https://github.com/mpusher/alloc) 调度器源码
+* mpns [https://github.com/mpusher/mpns](https://github.com/mpusher/mpns) 个性化推送中心源码
+* java-client [https://github.com/mpusher/mpush-client-java](https://github.com/mpusher/mpush-client-java) 纯java客户端源码
+* android sdk&demo [https://github.com/mpusher/mpush-android](https://github.com/mpusher/mpush-android) 安卓SDK和DEMO源码
+* IOS sdk(swift) [https://github.com/mpusher/mpush-client-swift](https://github.com/mpusher/mpush-client-swift) swift版客户端源码
+* IOS sdk(OC) [https://github.com/mpusher/mpush-client-oc](https://github.com/mpusher/mpush-client-oc) Object C 客户端源码
+
+ps:由于源码分别在github和码云有两份,最新的代码以github为主
+
+## 服务调用关系
+
+
+## 源码测试
+1. ```git clone https://github.com/mpusher/mpush.git```
+2. 导入到eclipse或Intellij IDEA
+3. 打开```mpush-test```模块,所有的测试代码都在该模块下
+4. 修改配置文件```src/test/resource/application.conf```文件修改方式参照 服务部署第6点
+5. 运行```com.mpush.test.sever.ServerTestMain.java```启动长链接服务
+6. 运行```com.mpush.test.client.ConnClientTestMain.java``` 模拟一个客户端
+7. 运行```com.mpush.test.push.PushClientTestMain``` 模拟给用户下发消息
+8. 可以在控制台观察日志看服务是否正常运行,消息是否下发成功
+
+## 服务部署
+
+###### 说明:mpush 服务只依赖于zookeeper和redis,当然还有JDK>=1.8
+
+1. 安装```jdk 1.8``` 以上版本并设置```%JAVA_HOME%```
+
+2. 安装```zookeeper``` (安装配置步骤略)
+
+3. 安装```Redis``` (安装配置步骤略)
+
+4. 下载mpush server 最新的正式包[https://github.com/mpusher/mpush/releases](https://github.com/mpusher/mpush/releases)
+
+5. 解压下载的tar包`tar -zvxf mpush-release-0.0.2.tar.gz`到 mpush 目录, 结构如下
+
+ >
+ >drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:30 bin —> 启动脚本
+ >drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:52 conf —> 配置文件
+ >drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:29 lib —> 核心类库
+ >-rw-rw-r-- 1 shinemo shinemo 11357 May 31 11:07 LICENSE
+ >drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:32 logs —> 日志目录
+ >-rw-rw-r-- 1 shinemo shinemo 21 May 31 11:07 README.md
+ >drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:52 tmp
+ >
+
+6. 修改 conf 目录下的 ```vi mpush.conf```文件, ```mpush.conf```里的配置项会覆盖同目录下的```reference.conf```文件
+ ```java
+ #主要修改以下配置
+ mp.net.connect-server-port=3000//长链接服务对外端口, 公网端口
+ mp.zk.server-address="127.0.0.1:2181"//zk 机器的地址
+ mp.redis={//redis 相关配置
+ nodes:["127.0.0.1:6379"] //格式是ip:port
+ cluster-model:single //single, cluster
+ }
+ //还有用于安全加密的RSA mp.security.private-key 和 mp.security.public-key 等...
+ ```
+ 如果要修改其他配置请参照reference.conf文件
+
+7. 给bin目录下的脚本增加执行权限```chmod u+x *.sh```
+
+8. 执行```./mp.sh start``` 启动服务, 查看帮助```./mp.sh``` 目前支持的命令:
+
+ ```Usage: ./mp.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}```
+
+ ```set-env.sh``` 用于增加和修改jvm启动参数,比如堆内存、开启远程调试端口、开启jmx等
+
+9. ```cd logs```目录,```cat mpush.out```查看服务是否启动成功
+10. 集成部署,比如集成到现有web工程一起部署到tomcat,可以添加如下依赖
+
+ ```xml
+
+ com.github.mpusher
+ mpush-boot
+ 0.0.2
+
+ ```
+ 启动入口`com.mpush.bootstrap.ServerLauncher.java`
+
+## 配置文件详解
+ ```java
+##################################################################################################################
+#
+# NOTICE:
+#
+# 系统配置文件,所有列出的项是系统所支持全部配置项
+# 如果要覆盖某项的值可以添加到mpush.conf中。
+#
+# 配置文件格式采用HOCON格式。解析库由https://github.com/typesafehub/config提供。
+# 具体可参照器说明文档,比如含有特殊字符的字符串必须用双引号包起来。
+#
+##############################################################################################################
+
+mp {
+ #日志配置
+ log.level=warn
+ log.dir=${user.dir}/../logs
+
+ #核心配置
+ core {
+ max-packet-size=10k //系统允许传输的最大包的大小
+ compress-threshold=10k //数据包启用压缩的临界值,超过该值后对数据进行压缩
+ min-heartbeat=3m //最小心跳间隔
+ max-heartbeat=3m //最大心跳间隔
+ max-hb-timeout-times=2 //允许的心跳连续超时的最大次数
+ session-expired-time=1d //用于快速重连的session 过期时间默认1天
+ epoll-provider=netty //nio:jdk自带,netty:由netty实现
+ }
+
+ #安全配置
+ security {
+ #rsa 私钥, 公钥 key长度为1024;生成方式可以使用open-ssh或者使用工具类com.mpush.tools.crypto.RSAUtils#main
+ private-key="MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA="
+ public-key="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB"
+ aes-key-length=16 //AES key 长度
+ ras-key-length=1024 //RSA key 长度
+ }
+
+ #网络配置
+ net {
+ connect-server-port=3000 //长链接服务对外端口, 公网端口
+ gateway-server-port=3001 //网关服务端口, 内部端口
+ admin-server-port=3002 //控制台服务端口, 内部端口
+ public-host-mapping { //本机局域网IP和公网IP的映射关系
+ "127.0.0.1":"111.1.32.137"
+ }
+ traffic-shaping { //流量整形配置
+ gateway-client {
+ enabled:true
+ check-interval:100ms
+ write-global-limit:1k
+ read-global-limit:0
+ write-channel-limit:256b
+ read-channel-limit:0
+ }
+
+ gateway-server {
+ enabled:true
+ check-interval:100ms
+ write-global-limit:0
+ read-global-limit:10k
+ write-channel-limit:0
+ read-channel-limit:0.5k
+ }
+
+ connect-server {
+ enabled:false
+ check-interval:100ms
+ write-global-limit:0
+ read-global-limit:100k
+ write-channel-limit:3k
+ read-channel-limit:3k
+ }
+ }
+ }
+
+ #Zookeeper配置
+ zk {
+ server-address="127.0.0.1:2181"
+ namespace=mpush
+ digest=mpush
+ local-cache-path=/
+ retry {
+ #initial amount of time to wait between retries
+ baseSleepTimeMs=3s
+ #max number of times to retry
+ maxRetries=3
+ #max time in ms to sleep on each retry
+ maxSleepMs=5s
+ }
+ connectionTimeoutMs=5s
+ sessionTimeoutMs=5s
+ }
+
+ #Redis集群配置
+ redis {
+ write-to-zk=true
+ #redis 集群配置,group 是个二维数组,第一层表示有多少组集群,每个集群下面可以有多台机器
+ cluster-group:[
+ [
+ {
+ host:"127.0.0.1"
+ port:2181
+ password:ShineMoIpo
+ }
+ ]
+ ]
+ config {
+ maxTotal:8,
+ maxIdle:4,
+ minIdle:1,
+ lifo:true,
+ fairness:false,
+ maxWaitMillis:5000,
+ minEvictableIdleTimeMillis:300000,
+ softMinEvictableIdleTimeMillis:1800000,
+ numTestsPerEvictionRun:3,
+ testOnCreate:false,
+ testOnBorrow:false,
+ testOnReturn:false,
+ testWhileIdle:false,
+ timeBetweenEvictionRunsMillis:60000,
+ blockWhenExhausted:true,
+ jmxEnabled:true,
+ jmxNamePrefix:pool,
+ jmxNameBase:pool
+ }
+ }
+
+ #HTTP代理配置
+ http {
+ proxy-enabled=false //启用Http代理
+ max-conn-per-host=5 //每个域名的最大链接数, 建议web服务nginx超时时间设长一点, 以便保持长链接
+ default-read-timeout=10s //请求超时时间
+ max-content-length=5m //response body 最大大小
+ dns-mapping { //域名映射外网地址转内部IP
+ "mpush.com":["127.0.0.1:8080", "127.0.0.1:8081"]
+ }
+ }
+
+ #线程池配置
+ thread {
+ pool {
+ boss { //netty boss
+ min:4
+ max:16
+ queue-size:1000
+ }
+
+ work { //netty boss
+ min:8
+ max:32
+ queue-size:1000
+ }
+
+ event-bus {
+ min:4
+ max:4
+ queue-size:10000 //大量的online,offline,
+ }
+
+ http-proxy {
+ min:8
+ max:64
+ queue-size:1000
+ }
+
+ biz { //其他业务
+ min:4
+ max:64
+ queue-size:10
+ }
+
+ mq { //用户上下线消息, 踢人等
+ min:2
+ max:4
+ queue-size:10000
+ }
+
+ push-callback { //消息推送
+ min:2
+ max:2
+ queue-size:0
+ }
+ }
+ }
+
+ #系统监控配置
+ monitor {
+ dump-dir=/tmp/logs/mpush/
+ dump-stack=false //是否定时dump堆栈
+ dump-period=1m //多久监控一次
+ print-log=true //是否打印监控日志
+ }
+
+ #SPI扩展配置
+ spi {
+ thread-pool-factory:"com.mpush.tools.thread.pool.DefaultThreadPoolFactory"
+ dns-mapping-manager:"com.mpush.common.net.HttpProxyDnsMappingManager"
+ }
+}
+```
+11. 未完待续...
diff --git a/bin/mp-env.cmd b/bin/env-mp.cmd
similarity index 96%
rename from bin/mp-env.cmd
rename to bin/env-mp.cmd
index fa39e14c..46f05757 100644
--- a/bin/mp-env.cmd
+++ b/bin/env-mp.cmd
@@ -15,7 +15,7 @@ REM See the License for the specific language governing permissions and
REM limitations under the License.
set MPCFGDIR=%~dp0%..\conf
-set MP_LOG_DIR=%~dp0%..
+set MP_LOG_DIR=%~dp0%..\logs
set MP_LOG4J_PROP=INFO,CONSOLE
REM for sanity sake assume Java 1.6
@@ -30,7 +30,7 @@ SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH%
REM make it work for developers
SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH%
-set MPCFG=%MPCFGDIR%\zoo.cfg
+set MPCFG=%MPCFGDIR%\mpush.conf
@REM setup java environment variables
diff --git a/bin/mp-env.sh b/bin/env-mp.sh
old mode 100644
new mode 100755
similarity index 57%
rename from bin/mp-env.sh
rename to bin/env-mp.sh
index 618dee65..2ee5287f
--- a/bin/mp-env.sh
+++ b/bin/env-mp.sh
@@ -18,47 +18,48 @@
# This script should be sourced into other mpush
# scripts to setup the env variables
-# We use MPCFGDIR if defined,
+# We use MP_CFG_DIR if defined,
# otherwise we use /etc/mp
# or the conf directory that is
# a sibling of this script's directory
-MPBINDIR="${MPBINDIR:-/usr/bin}"
-MPUSH_PREFIX="${MPBINDIR}/.."
+MP_BIN_DIR="${MP_BIN_DIR:-/usr/bin}"
+MPUSH_PREFIX="${MP_BIN_DIR}/.."
+MPUSH_HOME=$MPUSH_PREFIX
-if [ "x$MPCFGDIR" = "x" ]
+if [ "x$MP_CFG_DIR" = "x" ]
then
if [ -e "${MPUSH_PREFIX}/conf" ]; then
- MPCFGDIR="$MPBINDIR/../conf"
+ MP_CFG_DIR="$MP_BIN_DIR/../conf"
else
- MPCFGDIR="$MPBINDIR/../etc/mpush"
+ MP_CFG_DIR="$MP_BIN_DIR/../etc/mpush"
fi
fi
-if [ -f "${MPBINDIR}/set-env.sh" ]; then
- . "${MPBINDIR}/set-env.sh"
+if [ "x${MP_DATA_DIR}" = "x" ]
+then
+ MP_DATA_DIR="${MPUSH_PREFIX}/tmp"
fi
-if [ "x$MPCFG" = "x" ]
+if [ "x${MP_LOG_DIR}" = "x" ]
then
- MPCFG="mpush.conf"
+ MP_LOG_DIR="${MPUSH_PREFIX}/logs"
fi
-MPCFG="$MPCFGDIR/$MPCFG"
-
-if [ -f "$MPBINDIR/java.env" ]
-then
- . "$MPBINDIR/java.env"
+if [ -f "${MP_BIN_DIR}/set-env.sh" ]; then
+ . "${MP_BIN_DIR}/set-env.sh"
fi
-if [ "x${MP_DATADIR}" = "x" ]
+if [ "x$MP_CFG" = "x" ]
then
- MP_DATADIR="${MPUSH_PREFIX}/tmp"
+ MP_CFG="mpush.conf"
fi
-if [ "x${MP_LOG_DIR}" = "x" ]
+MP_CFG="$MP_CFG_DIR/$MP_CFG"
+
+if [ -f "$MP_BIN_DIR/java.env" ]
then
- MP_LOG_DIR="${MPUSH_PREFIX}/logs"
+ . "$MP_BIN_DIR/java.env"
fi
if [ "x${MP_LOG4J_PROP}" = "x" ]
@@ -74,40 +75,21 @@ fi
#add the conf dir to classpath
-CLASSPATH="$MPCFGDIR:$CLASSPATH"
-
-for i in "$MPBINDIR"/../src/java/lib/*.jar
-do
- CLASSPATH="$i:$CLASSPATH"
-done
+CLASSPATH="$MP_CFG_DIR:$MP_BIN_DIR/bootstrap.jar:$CLASSPATH"
#make it work in the binary package
-#(use array for LIBPATH to account for spaces within wildcard expansion)
-if [ -e "${MPUSH_PREFIX}"/share/mpush/mpush-*.jar ]; then
- LIBPATH=("${MPUSH_PREFIX}"/share/mpush/*.jar)
-else
- #release tarball format
- for i in "$MPBINDIR"/../mpush-*.jar
- do
- CLASSPATH="$i:$CLASSPATH"
- done
- LIBPATH=("${MPBINDIR}"/../lib/*.jar)
-fi
-for i in "${LIBPATH[@]}"
+for i in "${MPUSH_PREFIX}"/lib/*.jar
do
CLASSPATH="$i:$CLASSPATH"
done
-#make it work for developers
-for d in "$MPBINDIR"/../build/lib/*.jar
-do
- CLASSPATH="$d:$CLASSPATH"
-done
-
-#make it work for developers
-CLASSPATH="$MPBINDIR/../build/classes:$CLASSPATH"
-
+if [ -e "${MPUSH_PREFIX}"/lib/plugins/*.jar ]; then
+ for j in "${MPUSH_PREFIX}"/lib/plugins/*.jar
+ do
+ CLASSPATH="$j:$CLASSPATH"
+ done
+fi
case "`uname`" in
CYGWIN*) cygwin=true ;;
@@ -118,5 +100,3 @@ if $cygwin
then
CLASSPATH=`cygpath -wp "$CLASSPATH"`
fi
-
-#echo "CLASSPATH=$CLASSPATH"
\ No newline at end of file
diff --git a/bin/mp.cmd b/bin/mp.cmd
index f578f4e0..496b0fc3 100644
--- a/bin/mp.cmd
+++ b/bin/mp.cmd
@@ -13,12 +13,20 @@ REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
+REM java -Dmp.conf=../conf/mpush.conf -Dmp.home=. -jar bootstrap.jar
+REM setlocal
+
+REM call "%~dp0env-mp.cmd"
+
+REM set MPMAIN=-jar %~dp0bootstrap.jar
+
+REM call %JAVA% "-Dmp.conf=%MPCFG%" "-Dmp.home=%~dp0%.." -cp "%CLASSPATH%" %MPMAIN% %*
+
+REM endlocal
+
+
+java -Dmp.conf=../conf/mpush.conf -Dmp.home=.. -jar bootstrap.jar
+
-setlocal
-call "%~dp0mpEnv.cmd"
-set MPMAIN="-jar ../boot.jar"
-echo on
-call %JAVA% "-Dmp.log.dir=%MP_LOG_DIR%" -cp "%CLASSPATH%" %MPMAIN% "%MPCFG%" %*
-endlocal
diff --git a/bin/mp.sh b/bin/mp.sh
old mode 100644
new mode 100755
index c40e2d3d..e0af6086
--- a/bin/mp.sh
+++ b/bin/mp.sh
@@ -24,14 +24,14 @@
# use POSTIX interface, symlink is followed automatically
-MPBIN="${BASH_SOURCE-$0}"
-MPBIN="$(dirname "${MPBIN}")"
-MPBINDIR="$(cd "${MPBIN}"; pwd)"
+MP_BIN="${BASH_SOURCE-$0}"
+MP_BIN="$(dirname "${MP_BIN}")"
+MP_BIN_DIR="$(cd "${MP_BIN}"; pwd)"
-if [ -e "$MPBIN/../libexec/mp-env.sh" ]; then
- . "$MPBINDIR/../libexec/mp-env.sh"
+if [ -e "$MP_BIN/../libexec/env-mp.sh" ]; then
+ . "$MP_BIN_DIR/../libexec/env-mp.sh"
else
- . "$MPBINDIR/mp-env.sh"
+ . "$MP_BIN_DIR/env-mp.sh"
fi
# See the following page for extensive details on setting
@@ -51,7 +51,7 @@ then
# for some reason these two options are necessary on jdk6 on Ubuntu
# accord to the docs they are not necessary, but otw jconsole cannot
# do a local attach
- MPMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY"
+ MP_MAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY"
else
if [ "x$JMXAUTH" = "x" ]
then
@@ -69,41 +69,41 @@ then
echo "MPush remote JMX authenticate set to $JMXAUTH" >&2
echo "MPush remote JMX ssl set to $JMXSSL" >&2
echo "MPush remote JMX log4j set to $JMXLOG4J" >&2
- MPMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMXPORT -Dcom.sun.management.jmxremote.authenticate=$JMXAUTH -Dcom.sun.management.jmxremote.ssl=$JMXSSL -Dmpush.jmx.log4j.disable=$JMXLOG4J"
+ MP_MAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMXPORT -Dcom.sun.management.jmxremote.authenticate=$JMXAUTH -Dcom.sun.management.jmxremote.ssl=$JMXSSL -Dmpush.jmx.log4j.disable=$JMXLOG4J"
fi
else
echo "JMX disabled by user request" >&2
- MPMAIN=""
+ MP_MAIN=""
fi
-MPMAIN="$MPMAIN -jar $MPBINDIR/bootstrap.jar"
+MP_MAIN="$MP_MAIN com.mpush.bootstrap.Main"
-if [ "x$SERVER_JVMFLAGS" != "x" ]
+if [ "x$SERVER_JVM_FLAGS" != "x" ]
then
- JVMFLAGS="$SERVER_JVMFLAGS $JVMFLAGS"
+ JVM_FLAGS="$SERVER_JVM_FLAGS $JVM_FLAGS"
fi
if [ "x$2" != "x" ]
then
- MPCFG="$MPCFGDIR/$2"
+ MP_CFG="$MP_CFG_DIR/$2"
fi
-# if we give a more complicated path to the config, don't screw around in $MPCFGDIR
-if [ "x$(dirname "$MPCFG")" != "x$MPCFGDIR" ]
+# if we give a more complicated path to the config, don't screw around in $MP_CFG_DIR
+if [ "x$(dirname "$MP_CFG")" != "x$MP_CFG_DIR" ]
then
- MPCFG="$2"
+ MP_CFG="$2"
fi
if $cygwin
then
- MPCFG=`cygpath -wp "$MPCFG"`
+ MP_CFG=`cygpath -wp "$MP_CFG"`
# cygwin has a "kill" in the shell itself, gets confused
KILL=/bin/kill
else
KILL=kill
fi
-echo "Using config: $MPCFG" >&2
+echo "Using config: $MP_CFG" >&2
case "$OSTYPE" in
*solaris*)
@@ -113,19 +113,18 @@ case "$OSTYPE" in
GREP=grep
;;
esac
-if [ -z "$MPPIDFILE" ]; then
-# MP_DATADIR="$($GREP "^[[:space:]]*dataDir" "$MPCFG" | sed -e 's/.*=//')"
- if [ ! -d "$MP_DATADIR" ]; then
- mkdir -p "$MP_DATADIR"
+if [ -z "$MP_PID_FILE" ]; then
+# MP_DATA_DIR="$($GREP "^[[:space:]]*dataDir" "$MP_CFG" | sed -e 's/.*=//')"
+ if [ ! -d "$MP_DATA_DIR" ]; then
+ mkdir -p "$MP_DATA_DIR"
fi
- MPPIDFILE="$MP_DATADIR/mpush_server.pid"
+ MP_PID_FILE="$MP_DATA_DIR/mpush_server.pid"
else
# ensure it exists, otw stop will fail
- mkdir -p "$(dirname "$MPPIDFILE")"
+ mkdir -p "$(dirname "$MP_PID_FILE")"
fi
if [ ! -w "$MP_LOG_DIR" ] ; then
-echo $MP_LOG_DIR
mkdir -p "$MP_LOG_DIR"
fi
@@ -134,22 +133,21 @@ _MP_DAEMON_OUT="$MP_LOG_DIR/mpush.out"
case $1 in
start)
echo -n "Starting mpush ... "
- if [ -f "$MPPIDFILE" ]; then
- if kill -0 `cat "$MPPIDFILE"` > /dev/null 2>&1; then
- echo $command already running as process `cat "$MPPIDFILE"`.
+ if [ -f "$MP_PID_FILE" ]; then
+ if kill -0 `cat "$MP_PID_FILE"` > /dev/null 2>&1; then
+ echo $command already running as process `cat "$MP_PID_FILE"`.
exit 0
fi
fi
- nohup "$JAVA" "-Dmp.conf=$MPCFG" "-Dmp.log.dir=${MP_LOG_DIR}" "-Dmp.root.logger=${MP_LOG4J_PROP}" \
- -cp "$CLASSPATH" $JVMFLAGS $MPMAIN > "$_MP_DAEMON_OUT" 2>&1 < /dev/null &
+ nohup "$JAVA" "-Dmp.home=$MPUSH_HOME" "-Dmp.conf=$MP_CFG" -cp "$CLASSPATH" $JVM_FLAGS $MP_MAIN > "$_MP_DAEMON_OUT" 2>&1 < /dev/null &
if [ $? -eq 0 ]
then
case "$OSTYPE" in
*solaris*)
- /bin/echo "${!}\\c" > "$MPPIDFILE"
+ /bin/echo "${!}\\c" > "$MP_PID_FILE"
;;
*)
- /bin/echo -n $! > "$MPPIDFILE"
+ /bin/echo -n $! > "$MP_PID_FILE"
;;
esac
if [ $? -eq 0 ];
@@ -166,67 +164,79 @@ start)
fi
;;
start-foreground)
- MP_CMD=(exec "$JAVA")
- if [ "${MP_NOEXEC}" != "" ]; then
- MP_CMD=("$JAVA")
- fi
- "${MP_CMD[@]}" "-Dmp.log.dir=${MP_LOG_DIR}" "-Dmp.root.logger=${MP_LOG4J_PROP}" \
- -cp "$CLASSPATH" $JVMFLAGS $MPMAIN "-Dmp.conf=$MPCFG"
+ "$JAVA" "-Dmp.home=$MPUSH_HOME" "-Dmp.conf=$MP_CFG" -cp "$CLASSPATH" $JVM_FLAGS $MP_MAIN
;;
print-cmd)
- echo "\"$JAVA\" $MPMAIN "
- echo "\"-Dmp.conf=$MPCFG\" -Dmp.log.dir=\"${MP_LOG_DIR}\" -Dmp.root.logger=\"${MP_LOG4J_PROP}\" "
- echo "$JVMFLAGS "
+ echo "\"$JAVA\" $MP_MAIN "
+ echo "\"-Dmp.home=$MPUSH_HOME -Dmp.conf=$MP_CFG\" "
+ echo "$JVM_FLAGS "
echo "-cp \"$CLASSPATH\" "
echo "> \"$_MP_DAEMON_OUT\" 2>&1 < /dev/null"
;;
stop)
- echo -n "Stopping mpush ... "
- if [ ! -f "$MPPIDFILE" ]
+ echo "Stopping mpush ... "
+ if [ ! -f "$MP_PID_FILE" ]
then
- echo "no mpush to stop (could not find file $MPPIDFILE)"
+ echo "no mpush to stop (could not find file $MP_PID_FILE)"
else
- $KILL -9 $(cat "$MPPIDFILE")
- rm "$MPPIDFILE"
- echo STOPPED
+ $KILL -15 $(cat "$MP_PID_FILE")
+ SLEEP=30
+ SLEEP_COUNT=1
+ while [ $SLEEP -ge 0 ]; do
+ kill -0 $(cat "$MP_PID_FILE") >/dev/null 2>&1
+ if [ $? -gt 0 ]; then
+ rm -f "$MP_PID_FILE" >/dev/null 2>&1
+ if [ $? != 0 ]; then
+ if [ -w "$MP_PID_FILE" ]; then
+ cat /dev/null > "$MP_PID_FILE"
+ else
+ echo "The PID file could not be removed or cleared."
+ fi
+ fi
+ echo STOPPED
+ break
+ fi
+ if [ $SLEEP -gt 0 ]; then
+ echo "stopping ... $SLEEP_COUNT"
+ sleep 1
+ fi
+ if [ $SLEEP -eq 0 ]; then
+ echo "MPUSH did not stop in time."
+ echo "To aid diagnostics a thread dump has been written to standard out."
+ kill -3 `cat "$MP_PID_FILE"`
+ echo "force stop MPUSH."
+ kill -9 `cat "$MP_PID_FILE"`
+ echo STOPPED
+ fi
+ SLEEP=`expr $SLEEP - 1`
+ SLEEP_COUNT=`expr $SLEEP_COUNT + 1`
+ done
fi
exit 0
;;
upgrade)
shift
echo "upgrading the servers to 3.*"
- "$JAVA" "-Dmpush.log.dir=${MP_LOG_DIR}" "-Dmpush.root.logger=${MP_LOG4J_PROP}" \
- -cp "$CLASSPATH" $JVMFLAGS com.mpush.tools.upgrade.UpgradeMain ${@}
+ "$JAVA" -cp "$CLASSPATH" $JVM_FLAGS com.mpush.tools.upgrade.UpgradeMain ${@}
echo "Upgrading ... "
;;
restart)
shift
"$0" stop ${@}
- sleep 5
+ sleep 1
"$0" start ${@}
;;
status)
# -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output
- clientPortAddress=`$GREP "^[[:space:]]*clientPortAddress[^[:alpha:]]" "$MPCFG" | sed -e 's/.*=//'`
+ clientPortAddress=`$GREP "^[[:space:]]*clientPortAddress[^[:alpha:]]" "$MP_CFG" | sed -e 's/.*=//'`
if ! [ $clientPortAddress ]
then
- clientPortAddress="localhost"
- fi
- clientPort=`$GREP "^[[:space:]]*clientPort[^[:alpha:]]" "$MPCFG" | sed -e 's/.*=//'`
- STAT=`"$JAVA" "-Dmp.log.dir=${MP_LOG_DIR}" "-Dmp.root.logger=${MP_LOG4J_PROP}" \
- -cp "$CLASSPATH" $JVMFLAGS org.apache.mpush.client.FourLetterWordMain \
- $clientPortAddress $clientPort srvr 2> /dev/null \
- | $GREP Mode`
- if [ "x$STAT" = "x" ]
- then
- echo "Error contacting service. It is probably not running."
- exit 1
- else
- echo $STAT
- exit 0
+ clientPortAddress="localhost"
fi
+ clientPort=`$GREP "^[[:space:]]*connect-server-port[^[:alpha:]]" "$MP_CFG" | sed -e 's/.*=//'`
+ telnet 127.0.0.1 3002
;;
*)
echo "Usage: $0 {start|start-foreground|stop|restart|status|upgrade|print-cmd}" >&2
-esac
+esac
\ No newline at end of file
diff --git a/bin/rsa.sh b/bin/rsa.sh
new file mode 100755
index 00000000..472ddbe6
--- /dev/null
+++ b/bin/rsa.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# use POSTIX interface, symlink is followed automatically
+MP_BIN="${BASH_SOURCE-$0}"
+MP_BIN="$(dirname "${MP_BIN}")"
+MP_BIN_DIR="$(cd "${MP_BIN}"; pwd)"
+
+if [ -e "$MP_BIN/../libexec/env-mp.sh" ]; then
+ . "$MP_BIN_DIR/../libexec/env-mp.sh"
+else
+ . "$MP_BIN_DIR/env-mp.sh"
+fi
+
+if [ $1 -gt 1024 ] ;then
+ echo "use rsa key size $1"
+ keySize = $1
+else
+ echo "use rsa key size 1024"
+ keySize = 1024
+fi
+
+"$JAVA" -cp "$CLASSPATH" com.mpush.tools.crypto.RSAUtils $keySize
\ No newline at end of file
diff --git a/bin/set-env.sh b/bin/set-env.sh
old mode 100644
new mode 100755
index 5325b967..cc67fa11
--- a/bin/set-env.sh
+++ b/bin/set-env.sh
@@ -1,2 +1,37 @@
#!/usr/bin/env bash
-#JVMFLAGS="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8008 -Dio.netty.leakDetectionLevel=advanced"
\ No newline at end of file
+#1. Netty 相关关设置项
+
+#-Dio.netty.leakDetection.level
+#netty的内存泄露检测分为四级:
+#DISABLED: 不进行内存泄露的检测;
+#SIMPLE: 抽样检测,且只对部分方法调用进行记录,消耗较小,有泄漏时可能会延迟报告,默认级别;
+#ADVANCED: 抽样检测,记录对象最近几次的调用记录,有泄漏时可能会延迟报告;
+#PARANOID: 每次创建一个对象时都进行泄露检测,且会记录对象最近的详细调用记录。是比较激进的内存泄露检测级别,消耗最大,建议只在测试时使用。
+
+#-Dio.netty.selectorAutoRebuildThreshold=512 默认512
+#在NIO中通过Selector的轮询当前是否有IO事件,根据JDK NIO api描述,Selector的select方法会一直阻塞,直到IO事件达到或超时,但是在Linux平台上这里有时会出现问题,在某些场景下select方法会直接返回,即使没有超时并且也没有IO事件到达,这就是著名的epoll bug,这是一个比较严重的bug,它会导致线程陷入死循环,会让CPU飙到100%,极大地影响系统的可靠性,到目前为止,JDK都没有完全解决这个问题。
+#但是Netty有效的规避了这个问题,经过实践证明,epoll bug已Netty框架解决,Netty的处理方式是这样的:
+#记录select空转的次数,定义一个阀值,这个阀值默认是512,可以在应用层通过设置系统属性io.netty.selectorAutoRebuildThreshold传入,当空转的次数超过了这个阀值,重新构建新Selector,将老Selector上注册的Channel转移到新建的Selector上,关闭老Selector,用新的Selector代替老Selector,详细实现可以查看NioEventLoop中的selector和rebuildSelector方法:
+
+#-Dio.netty.noKeySetOptimization
+#是否禁用nio Selector.selectedKeys优化, 通过反射实现, 默认false
+
+JVM_FLAGS="-Dio.netty.leakDetection.level=advanced"
+
+#JMX
+
+JMXDISABLE=true
+#JMXPORT=1099
+
+#3. 开启远程调试
+
+#JVM_FLAGS="$JVM_FLAGS -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8008"
+
+#4. GC配置
+
+#运行模式 整个堆内存大小 GC算法
+#JVM_FLAGS="$JVM_FLAGS -server -Xmx1024m -Xms1024m -XX:+UseG1GC -XX:MaxGCPauseMillis=200"
+#GC日志 发生OOM时创建堆内存转储文件
+#JVM_FLAGS="$JVM_FLAGS -Xloggc:$MP_LOG_DIR/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
+#发生OOM后的操作
+#JVM_FLAGS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$MP_LOG_DIR -XX:OnOutOfMemoryError=$MP_BIN_DIR/restart.sh"
\ No newline at end of file
diff --git a/conf/conf-dev.properties b/conf/conf-dev.properties
index 4a36a6eb..af07a4a1 100644
--- a/conf/conf-dev.properties
+++ b/conf/conf-dev.properties
@@ -1 +1,4 @@
-log.level=debug
\ No newline at end of file
+log.level=debug
+min.hb=10s
+rsa.privateKey=MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA=
+rsa.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB
diff --git a/conf/conf-pub.properties b/conf/conf-pub.properties
index a5051a64..f957e52e 100644
--- a/conf/conf-pub.properties
+++ b/conf/conf-pub.properties
@@ -1 +1,4 @@
-log.level=warn
\ No newline at end of file
+log.level=warn
+min.hb=3m
+rsa.privateKey=MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA=
+rsa.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB
diff --git a/conf/reference.conf b/conf/reference.conf
index 263e7849..90c0bfb6 100644
--- a/conf/reference.conf
+++ b/conf/reference.conf
@@ -8,53 +8,103 @@
# 配置文件格式采用HOCON格式。解析库由https://github.com/typesafehub/config提供。
# 具体可参照器说明文档,比如含有特殊字符的字符串必须用双引号包起来。
#
-##############################################################################################################
+##################################################################################################################
mp {
- log.level=warn
- log.dir=${user.dir}/../logs
+ #基础配置
+ home=${user.dir} //程序工作目前
+
+ #日志配置
+ log-level=warn
+ log-dir=${mp.home}/logs
+ log-conf-path=${mp.home}/conf/logback.xml
+ #核心配置
core {
- max-packet-size=10k//系统允许传输的最大包的大小
- compress-threshold=10k//数据包启用压缩的临界值,超过该值后对数据进行压缩
- min-heartbeat=10s
- max-heartbeat=3m
- max-hb-timeout-times=2//允许的心跳连续超时的最大次数
- session-expired-time=1d//用于快速重连的session 过期时间默认1天
- epoll-provider=netty//nio:jdk 自带,netty:有netty实现
+ max-packet-size=10k //系统允许传输的最大包的大小
+ compress-threshold=10k //数据包启用压缩的临界值,超过该值后对数据进行压缩
+ min-heartbeat=3m //最小心跳间隔
+ max-heartbeat=3m //最大心跳间隔
+ max-hb-timeout-times=2 //允许的心跳连续超时的最大次数
+ session-expired-time=1d //用于快速重连的session 过期时间默认1天
+ epoll-provider=netty //nio:jdk自带,netty:由netty实现
}
+ #安全配置
security {
+ #rsa 私钥、公钥key长度为1024;可以使用脚本bin/rsa.sh生成, @see com.mpush.tools.crypto.RSAUtils#main
private-key="MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA="
public-key="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB"
- aes-key-length=16
- ras-key-length=1024
+ aes-key-length=16 //AES key 长度
}
+ #网络配置
net {
- connect-server-port=3000
- gateway-server-port=3001
- admin-server-port=3002
- public-host-mapping {//本机局域网IP和公网IP的映射关系
- "10.1.0.32":"111.1.57.148"
+ local-ip="" //本地ip, 默认取第一个网卡的本地IP
+ public-ip="" //外网ip, 默认取第一个网卡的外网IP
+
+ connect-server-bind-ip="" //connSrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)
+ connect-server-register-ip=${mp.net.public-ip} //公网ip, 注册到zk中的ip, 默认是public-ip
+ connect-server-port=3000 //长链接服务对外端口, 公网端口
+ connect-server-register-attr { //注册到zk里的额外属性,比如配置权重,可在alloc里排序
+ weight:1
+ }
+
+ gateway-server-bind-ip="" //gatewaySrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)
+ gateway-server-register-ip=${mp.net.local-ip} //本地ip, 注册到zk中的ip, 默认是local-ip
+ gateway-server-port=3001 //网关服务端口, 内部端口
+ gateway-server-net=tcp //网关服务使用的网络类型tcp/udp/sctp/udt
+
+ gateway-client-port=4000 //UDP 客户端端口
+ gateway-server-multicast="239.239.239.88" //239.0.0.0~239.255.255.255为本地管理组播地址,仅在特定的本地范围内有效
+ gateway-client-multicast="239.239.239.99" //239.0.0.0~239.255.255.255为本地管理组播地址,仅在特定的本地范围内有效
+ gateway-client-num=1 //网关客户端连接数
+
+ admin-server-port=3002 //控制台服务端口, 内部端口
+ ws-server-port=0 //websocket对外端口, 公网端口, 0表示禁用websocket
+ ws-path="/" //websocket path
+
+ public-host-mapping { //本机局域网IP和公网IP的映射关系, 该配置后续会被废弃
+ //"10.0.10.156":"111.1.32.137"
+ //"10.0.10.166":"111.1.33.138"
+ }
+
+ snd_buf { //tcp/udp 发送缓冲区大小
+ connect-server=32k
+ gateway-server=0
+ gateway-client=0 //0表示使用操作系统默认值
+ }
+
+ rcv_buf { //tcp/udp 接收缓冲区大小
+ connect-server=32k
+ gateway-server=0
+ gateway-client=0 //0表示使用操作系统默认值
+ }
+
+ write-buffer-water-mark { //netty 写保护
+ connect-server-low=32k
+ connect-server-high=64k
+ gateway-server-low=10m
+ gateway-server-high=20m
}
- traffic-shaping {
+
+ traffic-shaping { //流量整形配置
gateway-client {
- enabled:true
+ enabled:false
check-interval:100ms
- write-global-limit:1k
+ write-global-limit:30k
read-global-limit:0
- write-channel-limit:256b
+ write-channel-limit:3k
read-channel-limit:0
}
gateway-server {
- enabled:true
+ enabled:false
check-interval:100ms
write-global-limit:0
- read-global-limit:10k
+ read-global-limit:30k
write-channel-limit:0
- read-channel-limit:0.5k
+ read-channel-limit:3k
}
connect-server {
@@ -68,11 +118,12 @@ mp {
}
}
+ #Zookeeper配置
zk {
server-address="127.0.0.1:2181"
namespace=mpush
- digest=mpush
- local-cache-path=/
+ digest=mpush //zkCli.sh acl 命令 addauth digest mpush
+ watch-path=/
retry {
#initial amount of time to wait between retries
baseSleepTimeMs=3s
@@ -85,18 +136,12 @@ mp {
sessionTimeoutMs=5s
}
+ #Redis集群配置
redis {
- write-to-zk=true
- #redis 集群配置,group 是个二维数组,第一层表示有多少组集群,每个集群下面可以有多台机器
- cluster-group:[
- [
- {
- host:"111.1.57.148"
- port:6379
- password:ShineMoIpo
- }
- ]
- ]
+ cluster-model=single//single,cluster,sentinel
+ password=""//your password
+ nodes:[]//["127.0.0.1:6379"]格式ip:port:password,密码可以不设置ip:port
+ sentinel-master:""
config {
maxTotal:8,
maxIdle:4,
@@ -113,75 +158,76 @@ mp {
testWhileIdle:false,
timeBetweenEvictionRunsMillis:60000,
blockWhenExhausted:true,
- jmxEnabled:true,
+ jmxEnabled:false,
jmxNamePrefix:pool,
jmxNameBase:pool
}
}
+ #HTTP代理配置
http {
- proxy-enabled=false
- max-conn-per-host=5
- default-read-timeout=10s
- max-content-length=5m
- dns-mapping {
- "mpush.com":["127.0.0.1:8080","127.0.0.1:8081"]
+ proxy-enabled=false //启用Http代理
+ max-conn-per-host=5 //每个域名的最大链接数, 建议web服务nginx超时时间设长一点, 以便保持长链接
+ default-read-timeout=10s //请求超时时间
+ max-content-length=5m //response body 最大大小
+ dns-mapping { //域名映射外网地址转内部IP, 域名部分不包含端口号
+ //"mpush.com":["127.0.0.1:8080", "127.0.0.1:8081"]
}
}
+ #线程池配置
thread {
pool {
- boss {
- min:4
+ conn-work:0 //接入服务线程池大小,0表示线程数根据cpu核数动态调整(2*cpu)
+ gateway-server-work:0 //网关服务线程池大小,0表示线程数根据cpu核数动态调整(2*cpu)
+ http-work:0 //http proxy netty client work pool size,0表示线程数根据cpu核数动态调整(2*cpu)
+ ack-timer:1 //处理ACK消息超时
+ push-task:0 //消息推送中心,推送任务线程池大小, 如果为0表示使用Gateway Server的work线程池,tcp下推荐0
+ gateway-client-work:0 //网关客户端线程池大小,0表示线程数根据cpu核数动态调整(2*cpu),该线程池在客户端运行
+ push-client:2 //消息推送回调处理,该线程池在客户端运行
+
+ event-bus { //用户处理内部事件分发
+ min:1
max:16
- queue-size:1000
- }
-
- work {
- min:8
- max:32
- queue-size:1000
- }
-
- event-bus {
- min:4
- max:4
queue-size:10000 //大量的online,offline,
}
- http-proxy {
- min:8
- max:64
- queue-size:1000
- }
-
- biz {
- min:4
- max:64
- queue-size:10
- }
-
- mq {
- min:2
+ mq { //用户上下线消息, 踢人等
+ min:1
max:4
queue-size:10000
}
+ }
+ }
+
+ #推送消息流控
+ push {
+ flow-control { //qps = limit/(duration)
+ global:{ //针对非广播推送的流控,全局有效
+ limit:5000 //qps = 5000
+ max:0 //UN limit
+ duration:1s //1s
+ }
- push-callback {
- min:2
- max:2
- queue-size:0
+ broadcast:{ //针对广播消息的流控,单次任务有效
+ limit:3000 //qps = 3000
+ max:100000 //10w
+ duration:1s //1s
}
- }
+ }
}
+ #系统监控配置
monitor {
- dump-dir=/tmp/logs/mpush/
- dump-stack=false
- dump-period=1m
- print-log=true
+ dump-dir=${mp.home}/tmp
+ dump-stack=false //是否定时dump堆栈
+ dump-period=1m //多久监控一次
+ print-log=true //是否打印监控日志
+ profile-enabled=false //开启性能监控
+ profile-slowly-duration=10ms //耗时超过10ms打印日志
}
+ #SPI扩展配置
spi {
thread-pool-factory:"com.mpush.tools.thread.pool.DefaultThreadPoolFactory"
dns-mapping-manager:"com.mpush.common.net.HttpProxyDnsMappingManager"
diff --git a/mpush-api/pom.xml b/mpush-api/pom.xml
index 141fb582..3361a1a6 100644
--- a/mpush-api/pom.xml
+++ b/mpush-api/pom.xml
@@ -2,23 +2,32 @@
+
+ 4.0.0
+
mpush
- com.mpush
- 1.0
+ com.github.mpusher
+ 0.8.0
+ ../pom.xml
- 4.0.0
- ${mpush.groupId}
mpush-api
- ${mpush-api-version}
- mpush-api
jar
+ mpush-api
+ MPUSH消息推送系统Api模块
+ https://github.com/mpusher/mpush
io.netty
netty-transport
+ compile
+
+
+ io.netty
+ netty-codec-http
+ compile
diff --git a/mpush-api/src/main/java/com/mpush/api/Constants.java b/mpush-api/src/main/java/com/mpush/api/Constants.java
index 27e5cece..169f0ab0 100644
--- a/mpush-api/src/main/java/com/mpush/api/Constants.java
+++ b/mpush-api/src/main/java/com/mpush/api/Constants.java
@@ -20,6 +20,7 @@
package com.mpush.api;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
/**
* Created by ohun on 2015/12/23.
@@ -27,9 +28,15 @@
* @author ohun@live.cn
*/
public interface Constants {
- Charset UTF_8 = Charset.forName("UTF-8");
+ Charset UTF_8 = StandardCharsets.UTF_8;
byte[] EMPTY_BYTES = new byte[0];
-
String HTTP_HEAD_READ_TIMEOUT = "readTimeout";
+ String EMPTY_STRING = "";
+ String ANY_HOST = "0.0.0.0";
+ String KICK_CHANNEL_PREFIX = "/mpush/kick/";
+
+ static String getKickChannel(String hostAndPort) {
+ return KICK_CHANNEL_PREFIX + hostAndPort;
+ }
}
diff --git a/mpush-api/src/main/java/com/mpush/api/MPushContext.java b/mpush-api/src/main/java/com/mpush/api/MPushContext.java
new file mode 100644
index 00000000..2d1d1f48
--- /dev/null
+++ b/mpush-api/src/main/java/com/mpush/api/MPushContext.java
@@ -0,0 +1,45 @@
+/*
+ * (C) Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * ohun@live.cn (夜色)
+ */
+
+package com.mpush.api;
+
+import com.mpush.api.common.Monitor;
+import com.mpush.api.spi.common.CacheManager;
+import com.mpush.api.spi.common.MQClient;
+import com.mpush.api.srd.ServiceDiscovery;
+import com.mpush.api.srd.ServiceRegistry;
+
+/**
+ * Created by ohun on 2017/6/21.
+ *
+ * @author ohun@live.cn (夜色)
+ */
+public interface MPushContext {
+
+ Monitor getMonitor();
+
+ ServiceDiscovery getDiscovery();
+
+ ServiceRegistry getRegistry();
+
+ CacheManager getCacheManager();
+
+ MQClient getMQClient();
+
+}
diff --git a/mpush-api/src/main/java/com/mpush/api/common/Condition.java b/mpush-api/src/main/java/com/mpush/api/common/Condition.java
new file mode 100644
index 00000000..b596d9cc
--- /dev/null
+++ b/mpush-api/src/main/java/com/mpush/api/common/Condition.java
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2015-2016 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * ohun@live.cn (夜色)
+ */
+
+package com.mpush.api.common;
+
+import java.util.Map;
+import java.util.function.Predicate;
+
+/**
+ * Created by ohun on 16/10/24.
+ *
+ * @author ohun@live.cn (夜色)
+ */
+public interface Condition extends Predicate