1 Star 0 Fork 428

sloth4413 / mpush

forked from MPUSH消息推送 / mpush 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

详细教程

源码

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

  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文件

       #主要修改以下配置
       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,可以添加如下依赖

<dependency>
   <groupId>com.github.mpusher</groupId>
   <artifactId>mpush-boot</artifactId>
   <version>0.0.2</version>
</dependency>

启动入口com.mpush.bootstrap.ServerLauncher.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"
 }
}
  1. 未完待续...
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} 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.

简介

mpush 消息推送Server 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/sloth4413/mpush.git
git@gitee.com:sloth4413/mpush.git
sloth4413
mpush
mpush
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891