{"id":13756544,"url":"https://github.com/mpusher/mpush","last_synced_at":"2025-05-14T11:08:55.110Z","repository":{"id":40633462,"uuid":"57261362","full_name":"mpusher/mpush","owner":"mpusher","description":"MPush开源实时消息推送系统","archived":false,"fork":false,"pushed_at":"2022-06-17T01:50:04.000Z","size":2595,"stargazers_count":3772,"open_issues_count":31,"forks_count":1459,"subscribers_count":333,"default_branch":"master","last_synced_at":"2025-05-11T14:49:08.231Z","etag":null,"topics":["android","im","java","netty","push","tcp-ip"],"latest_commit_sha":null,"homepage":"https://mpusher.github.io","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mpusher.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-28T01:43:19.000Z","updated_at":"2025-05-09T09:31:48.000Z","dependencies_parsed_at":"2022-08-01T00:08:26.364Z","dependency_job_id":null,"html_url":"https://github.com/mpusher/mpush","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpusher%2Fmpush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpusher%2Fmpush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpusher%2Fmpush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpusher%2Fmpush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpusher","download_url":"https://codeload.github.com/mpusher/mpush/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129484,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","im","java","netty","push","tcp-ip"],"created_at":"2024-08-03T11:00:46.771Z","updated_at":"2025-05-14T11:08:55.059Z","avatar_url":"https://github.com/mpusher.png","language":"Java","readme":"## [详细教程](http://mpush.mydoc.io)\n\n* 官网：[https://mpusher.github.io](https://mpusher.github.io)\n* 文档：[http://mpush.mydoc.io](http://mpush.mydoc.io)\n* QQ群：__114583699__ \u003ca target=\"_blank\" href=\"http://shang.qq.com/wpa/qunwpa?idkey=1de86266c76d00c246c3c7f29cc002667d1c26fcc2f14d2a7b75b3126708e2e1\"\u003e\u003cimg border=\"0\" src=\"http://pub.idqqimg.com/wpa/images/group.png\" alt=\"MPUSH开源消息推送系统\" title=\"MPUSH开源消息推送系统\"\u003e\u003c/a\u003e\n\n## 源码\n* group [https://github.com/mpusher/](https://github.com/mpusher/) 源代码空间\n* server [https://github.com/mpusher/mpush](https://github.com/mpusher/mpush) 服务端源码\n* alloc [https://github.com/mpusher/alloc](https://github.com/mpusher/alloc)  调度器源码\n* mpns [https://github.com/mpusher/mpns](https://github.com/mpusher/mpns)     个性化推送中心源码\n* java-client [https://github.com/mpusher/mpush-client-java](https://github.com/mpusher/mpush-client-java) 纯java客户端源码\n* android sdk\u0026demo [https://github.com/mpusher/mpush-android](https://github.com/mpusher/mpush-android)    安卓SDK和DEMO源码\n* IOS sdk(swift) [https://github.com/mpusher/mpush-client-swift](https://github.com/mpusher/mpush-client-swift) swift版客户端源码\n* IOS sdk(OC) [https://github.com/mpusher/mpush-client-oc](https://github.com/mpusher/mpush-client-oc)  Object C 客户端源码\n\nps:由于源码分别在github和码云有两份，最新的代码以github为主\n\n## 服务调用关系\n![](https://mpusher.github.io/docs/服务依赖关系.png)\n\n## 源码测试\n1. ```git clone https://github.com/mpusher/mpush.git```\n2. 导入到eclipse或Intellij IDEA\n3. 打开```mpush-test```模块，所有的测试代码都在该模块下\n4. 修改配置文件```src/test/resource/application.conf```文件修改方式参照 服务部署第6点\n5. 运行```com.mpush.test.sever.ServerTestMain.java```启动长链接服务\n6. 运行```com.mpush.test.client.ConnClientTestMain.java``` 模拟一个客户端\n7. 运行```com.mpush.test.push.PushClientTestMain``` 模拟给用户下发消息\n8. 可以在控制台观察日志看服务是否正常运行，消息是否下发成功\n\n## 服务部署\n\n###### 说明：mpush 服务只依赖于zookeeper和redis，当然还有JDK\u003e=1.8\n\n1. 安装```jdk 1.8``` 以上版本并设置```%JAVA_HOME％```\n\n2. 安装```zookeeper``` (安装配置步骤略)\n\n3. 安装```Redis``` (安装配置步骤略)\n\n4. 下载mpush server 最新的正式包[https://github.com/mpusher/mpush/releases](https://github.com/mpusher/mpush/releases)\n\n5. 解压下载的tar包`tar -zvxf mpush-release-0.0.2.tar.gz`到 mpush 目录, 结构如下\n\n   \u003e\u003cpre class=\"md-fences\"\u003e\n   \u003edrwxrwxr-x 2 shinemo shinemo  4096 Aug 20 09:30 bin —\u003e 启动脚本\n   \u003edrwxrwxr-x 2 shinemo shinemo  4096 Aug 20 09:52 conf —\u003e 配置文件\n   \u003edrwxrwxr-x 2 shinemo shinemo  4096 Aug 20 09:29 lib —\u003e 核心类库\n   \u003e-rw-rw-r-- 1 shinemo shinemo 11357 May 31 11:07 LICENSE\n   \u003edrwxrwxr-x 2 shinemo shinemo  4096 Aug 20 09:32 logs —\u003e 日志目录\n   \u003e-rw-rw-r-- 1 shinemo shinemo    21 May 31 11:07 README.md\n   \u003edrwxrwxr-x 2 shinemo shinemo  4096 Aug 20 09:52 tmp\n   \u003e\u003c/pre\u003e\n\n6. 修改 conf 目录下的 ```vi mpush.conf```文件, ```mpush.conf```里的配置项会覆盖同目录下的```reference.conf```文件\n   ```java\n      #主要修改以下配置\n      mp.net.connect-server-port=3000//长链接服务对外端口, 公网端口\n      mp.zk.server-address=\"127.0.0.1:2181\"//zk 机器的地址\n      mp.redis={//redis 相关配置\n            nodes:[\"127.0.0.1:6379\"] //格式是ip:port\n            cluster-model:single //single, cluster\n      }\n      //还有用于安全加密的RSA mp.security.private-key 和 mp.security.public-key 等...\n   ```\n    如果要修改其他配置请参照reference.conf文件\n\n7. 给bin目录下的脚本增加执行权限```chmod u+x *.sh```\n\n8. 执行```./mp.sh start``` 启动服务, 查看帮助```./mp.sh``` 目前支持的命令：\n\n   ```Usage: ./mp.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}```\n\n   ```set-env.sh``` 用于增加和修改jvm启动参数，比如堆内存、开启远程调试端口、开启jmx等\n\n9. ```cd logs```目录，```cat mpush.out```查看服务是否启动成功\n10. 集成部署，比如集成到现有web工程一起部署到tomcat,可以添加如下依赖\n   \n   ```xml\n   \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.mpusher\u003c/groupId\u003e\n      \u003cartifactId\u003empush-boot\u003c/artifactId\u003e\n      \u003cversion\u003e0.0.2\u003c/version\u003e\n   \u003c/dependency\u003e\n   ```\n   启动入口`com.mpush.bootstrap.ServerLauncher.java` \n   \n## 配置文件详解\n   ```java\n##################################################################################################################\n#\n# NOTICE：\n#\n# 系统配置文件，所有列出的项是系统所支持全部配置项\n# 如果要覆盖某项的值可以添加到mpush.conf中。\n#\n# 配置文件格式采用HOCON格式。解析库由https://github.com/typesafehub/config提供。\n# 具体可参照说明文档，比如含有特殊字符的字符串必须用双引号包起来。\n#\n##################################################################################################################\n\nmp {\n    #基础配置\n    home=${user.dir} //程序工作目录\n\n    #日志配置\n    log-level=warn\n    log-dir=${mp.home}/logs\n    log-conf-path=${mp.home}/conf/logback.xml\n\n    #核心配置\n    core {\n        max-packet-size=10k //系统允许传输的最大包的大小\n        compress-threshold=10k //数据包启用压缩的临界值，超过该值后对数据进行压缩\n        min-heartbeat=3m //最小心跳间隔\n        max-heartbeat=3m //最大心跳间隔\n        max-hb-timeout-times=2 //允许的心跳连续超时的最大次数\n        session-expired-time=1d //用于快速重连的session 过期时间默认1天\n        epoll-provider=netty //nio:jdk自带，netty:由netty实现\n    }\n\n    #安全配置\n    security {\n        #rsa 私钥、公钥key长度为1024;可以使用脚本bin/rsa.sh生成, @see com.mpush.tools.crypto.RSAUtils#main\n        private-key=\"MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA=\"\n        public-key=\"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB\"\n        aes-key-length=16 //AES key 长度\n    }\n\n    #网络配置\n    net {\n        local-ip=\"\"  //本地ip, 默认取第一个网卡的本地IP\n        public-ip=\"\" //外网ip, 默认取第一个网卡的外网IP\n\n        connect-server-bind-ip=\"\"  //connSrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)\n        connect-server-register-ip=${mp.net.public-ip}  //公网ip, 注册到zk中的ip, 默认是public-ip\n        connect-server-port=3000 //长链接服务对外端口, 公网端口\n        connect-server-register-attr { //注册到zk里的额外属性，比如配置权重，可在alloc里排序\n            weight:1\n        }\n\n        gateway-server-bind-ip=\"\"  //gatewaySrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)\n        gateway-server-register-ip=${mp.net.local-ip}  //本地ip, 注册到zk中的ip, 默认是local-ip\n        gateway-server-port=3001 //网关服务端口, 内部端口\n        gateway-server-net=tcp //网关服务使用的网络类型tcp/udp/sctp/udt\n\n        gateway-client-port=4000 //UDP 客户端端口\n        gateway-server-multicast=\"239.239.239.88\" //239.0.0.0～239.255.255.255为本地管理组播地址，仅在特定的本地范围内有效\n        gateway-client-multicast=\"239.239.239.99\" //239.0.0.0～239.255.255.255为本地管理组播地址，仅在特定的本地范围内有效\n        gateway-client-num=1 //网关客户端连接数\n\n        admin-server-port=3002 //控制台服务端口, 内部端口\n        ws-server-port=0 //websocket对外端口, 公网端口, 0表示禁用websocket\n        ws-path=\"/\" //websocket path\n\n        public-host-mapping { //本机局域网IP和公网IP的映射关系, 该配置后续会被废弃\n            //\"10.0.10.156\":\"111.1.32.137\"\n            //\"10.0.10.166\":\"111.1.33.138\"\n        }\n\n        snd_buf { //tcp/udp 发送缓冲区大小\n            connect-server=32k\n            gateway-server=0\n            gateway-client=0 //0表示使用操作系统默认值\n        }\n\n        rcv_buf { //tcp/udp 接收缓冲区大小\n            connect-server=32k\n            gateway-server=0\n            gateway-client=0 //0表示使用操作系统默认值\n        }\n\n        write-buffer-water-mark { //netty 写保护\n            connect-server-low=32k\n            connect-server-high=64k\n            gateway-server-low=10m\n            gateway-server-high=20m\n        }\n\n        traffic-shaping { //流量整形配置\n            gateway-client {\n                enabled:false\n                check-interval:100ms\n                write-global-limit:30k\n                read-global-limit:0\n                write-channel-limit:3k\n                read-channel-limit:0\n            }\n\n            gateway-server {\n                enabled:false\n                check-interval:100ms\n                write-global-limit:0\n                read-global-limit:30k\n                write-channel-limit:0\n                read-channel-limit:3k\n            }\n\n            connect-server {\n                enabled:false\n                check-interval:100ms\n                write-global-limit:0\n                read-global-limit:100k\n                write-channel-limit:3k\n                read-channel-limit:3k\n            }\n        }\n    }\n\n    #Zookeeper配置\n    zk {\n        server-address=\"127.0.0.1:2181\" //多台机器使用\",\"分隔如：\"10.0.10.44:2181,10.0.10.49:2181\" @see org.apache.zookeeper.ZooKeeper#ZooKeeper()\n        namespace=mpush\n        digest=mpush //zkCli.sh acl 命令 addauth digest mpush\n        watch-path=/\n        retry {\n            #initial amount of time to wait between retries\n            baseSleepTimeMs=3s\n            #max number of times to retry\n            maxRetries=3\n            #max time in ms to sleep on each retry\n            maxSleepMs=5s\n        }\n        connectionTimeoutMs=5s\n        sessionTimeoutMs=5s\n    }\n\n    #Redis集群配置\n    redis {\n        cluster-model=single //single,cluster,sentinel\n        sentinel-master:\"\"\n        nodes:[] s//[\"127.0.0.1:6379\"]格式ip:port\n        password=\"\" //your password\n        config {\n            maxTotal:8,\n            maxIdle:4,\n            minIdle:1,\n            lifo:true,\n            fairness:false,\n            maxWaitMillis:5000,\n            minEvictableIdleTimeMillis:300000,\n            softMinEvictableIdleTimeMillis:1800000,\n            numTestsPerEvictionRun:3,\n            testOnCreate:false,\n            testOnBorrow:false,\n            testOnReturn:false,\n            testWhileIdle:false,\n            timeBetweenEvictionRunsMillis:60000,\n            blockWhenExhausted:true,\n            jmxEnabled:false,\n            jmxNamePrefix:pool,\n            jmxNameBase:pool\n        }\n    }\n\n    #HTTP代理配置\n    http {\n        proxy-enabled=false //启用Http代理\n        max-conn-per-host=5 //每个域名的最大链接数, 建议web服务nginx超时时间设长一点, 以便保持长链接\n        default-read-timeout=10s //请求超时时间\n        max-content-length=5m //response body 最大大小\n        dns-mapping { //域名映射外网地址转内部IP, 域名部分不包含端口号\n            //\"mpush.com\":[\"127.0.0.1:8080\", \"127.0.0.1:8081\"]\n        }\n    }\n\n    #线程池配置\n    thread {\n        pool {\n            conn-work:0 //接入服务线程池大小，0表示线程数根据cpu核数动态调整(2*cpu)\n            gateway-server-work:0 //网关服务线程池大小，0表示线程数根据cpu核数动态调整(2*cpu)\n            http-work:0 //http proxy netty client work pool size，0表示线程数根据cpu核数动态调整(2*cpu)\n            ack-timer:1 //处理ACK消息超时\n            push-task:0 //消息推送中心，推送任务线程池大小, 如果为0表示使用Gateway Server的work线程池，tcp下推荐0\n            gateway-client-work:0 //网关客户端线程池大小，0表示线程数根据cpu核数动态调整(2*cpu)，该线程池在客户端运行\n            push-client:2 //消息推送回调处理，该线程池在客户端运行\n\n            event-bus { //用户处理内部事件分发\n                min:1\n                max:16\n                queue-size:10000 //大量的online，offline\n            }\n\n            mq { //用户上下线消息, 踢人等\n                min:1\n                max:4\n                queue-size:10000\n            }\n        }\n    }\n\n    #推送消息流控\n    push {\n       flow-control { //qps = limit/(duration)\n            global:{ //针对非广播推送的流控，全局有效\n                limit:5000 //qps = 5000\n                max:0 //UN limit\n                duration:1s //1s\n            }\n\n            broadcast:{ //针对广播消息的流控，单次任务有效\n                limit:3000 //qps = 3000\n                max:100000 //10w\n                duration:1s //1s\n            }\n       }\n    }\n\n    #系统监控配置\n    monitor {\n        dump-dir=${mp.home}/tmp\n        dump-stack=false //是否定时dump堆栈\n        dump-period=1m  //多久监控一次\n        print-log=true //是否打印监控日志\n        profile-enabled=false //开启性能监控\n        profile-slowly-duration=10ms //耗时超过10ms打印日志\n    }\n\n    #SPI扩展配置\n    spi {\n        thread-pool-factory:\"com.mpush.tools.thread.pool.DefaultThreadPoolFactory\"\n        dns-mapping-manager:\"com.mpush.common.net.HttpProxyDnsMappingManager\"\n    }\n}\n```\n11. 未完待续...\n","funding_links":[],"categories":["Java"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpusher%2Fmpush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpusher%2Fmpush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpusher%2Fmpush/lists"}