Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
*.project
*/.settings/
*/target/
*/logs/
*/bin/
*/WebContent/
*/.DS_Store

.idea/

target/
logs/

# Mobile Tools for Java (J2ME)
.mtj.tmp/
Expand Down
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### v0.8.2
* 支持别名、标签设置及推送
* 存储推送消息到缓存
* 支持离线消息重复

#### v0.8.0

1. 增加本地ip和外网ip配置项
Expand Down
95 changes: 82 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,35 @@

## 源码
* 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 客户端源码
* server [https://github.com/dengly/mpush](https://github.com/dengly/mpush) 服务端源码
* alloc [https://github.com/dengly/alloc](https://github.com/dengly/alloc) 调度器源码
* mpns [https://github.com/dengly/mpns](https://github.com/dengly/mpns) 个性化推送中心源码
* java-client [https://github.com/dengly/mpush-client-java](https://github.com/dengly/mpush-client-java) 纯java客户端源码
* android sdk&demo [https://github.com/dengly/mpush-android](https://github.com/dengly/mpush-android) 安卓SDK和DEMO源码
* IOS sdk(swift) [https://github.com/dengly/mpush-client-swift](https://github.com/dengly/mpush-client-swift) swift版客户端源码
* IOS sdk(OC) [https://github.com/dengly/mpush-client-oc](https://github.com/dengly/mpush-client-oc) Object C 客户端源码

ps:由于源码分别在github和码云有两份,最新的代码以github为主

## 模块说明
* conf - 配置模块,仅仅是配置文件
* mpush-api - api接口
* mpush-boot - 启动模块,用于启动服务
* mpush-cache - redis数据缓存,redis操作管理,redis订阅发布
* mpush-client - MPush客户端
* mpush-common - 通用模块
* mpush-core - 核心模块
* mpush-monitor - 监控模块
* mpush-netty - netty连接模块
* mpush-test - 单元测试模块
* mpush-tools - 工具模块
* mpush-zk - zookeeper模块

## 服务调用关系
![](https://mpusher.github.io/docs/服务依赖关系.png)
![服务调用关系](https://mpusher.github.io/docs/服务依赖关系.png)

## 源码测试
1. ```git clone https://github.com/mpusher/mpush.git```
1. ```git clone https://github.com/dengly/mpush.git```
2. 导入到eclipse或Intellij IDEA
3. 打开```mpush-test```模块,所有的测试代码都在该模块下
4. 修改配置文件```src/test/resource/application.conf```文件修改方式参照 服务部署第6点
Expand All @@ -39,9 +53,9 @@ ps:由于源码分别在github和码云有两份,最新的代码以github为

3. 安装```Redis``` (安装配置步骤略)

4. 下载mpush server 最新的正式包[https://github.com/mpusher/mpush/releases](https://github.com/mpusher/mpush/releases)
4. 下载mpush server 最新的正式包[https://github.com/dengly/mpush/releases](https://github.com/dengly/mpush/releases)

5. 解压下载的tar包`tar -zvxf mpush-release-0.0.2.tar.gz`到 mpush 目录, 结构如下
5. 解压下载的tar包`tar -zvxf mpush-release-0.8.2.tar.gz`到 mpush 目录, 结构如下

><pre class="md-fences">
>drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:30 bin —> 启动脚本
Expand Down Expand Up @@ -85,7 +99,54 @@ ps:由于源码分别在github和码云有两份,最新的代码以github为
</dependency>
```
启动入口`com.mpush.bootstrap.ServerLauncher.java`


## 推送说明

#### http推送接口信息体
```json
{
"userId":"",
"alias":"",
"tags":"",
"title":"",
"content":"",
"flags":"",
"msgType":"",
"extras":{
"expire":""
}
}
```

参数说明

参数 | 类型 | 是否必传 | 说明
--- | --- | --- | ---
userId | String | 否 | 用户id
alias | String | 否 | 别名
tags | String | 否 | 标签
title | String | 是 | 标题
content | String | 是 | 内容
msgType | int | 是 | 推送类型,1通知 - 会在通知栏显示,2消息 - 不会在通知栏显示,业务自定义消息,3通知+消息
flags | int | 否 | 特性字段,0x01:声音,0x02:震动,0x03:闪灯
extras | object | 否 | 扩展
expire | int | 否 | 过期时间,单位为秒,默认1800,即30分钟

> * `userId`、`alias`、`tags`三者必须有且只能有一种,多个用英文逗号分隔
> * `userId`和`alias` 全局唯一
> * `userId`、`alias`、`tags`长度都小于128,且只能是英文字符、数组和英文符号`-`或`_`

#### 内部推送接口信息体
`com.mpush.api.push.PushMsg`

参数说明

参数 | 类型 | 是否必传 | 说明
--- | --- | --- | ---
msgId | String | 是 | 信息id
content | String | 是 | 内容
msgType | com.mpush.api.push.MsgType | 是 | 推送类型,1通知 - 会在通知栏显示,2消息 - 不会在通知栏显示,业务自定义消息,3通知+消息

## 配置文件详解
```java
##################################################################################################################
Expand Down Expand Up @@ -324,4 +385,12 @@ mp {
}
}
```
11. 未完待续...

## 独立部署
1. 打包 `mvn clean package -Pzip`
2. 打好的包位置: `mpush-boot/target/mpush-release-版本号.tar.gz`
3. 解压 `tar -zvxf mpush-release-版本号.tar.gz`
4. `cd mpush-版本号`
5. `vim conf/mpush.conf`
6. `chmod +x bin/*.sh`
7. `bin/mp.sh start`
3 changes: 3 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* 将用户id、别名、标签、登录设备信息、离线信息存储到数据库
* 推送消息存储到数据库
* 添加信息接收结果
22 changes: 22 additions & 0 deletions conf/mpush.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mp.log-level=debug
mp.core.min-heartbeat=3m
mp.security.private-key="MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA="
mp.security.public-key="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB"
mp.zk.server-address="10.0.0.231:2181"
mp.redis { //redis 集群配置
nodes:["10.0.0.211:6380","10.0.0.211:6381","10.0.0.212:6380","10.0.0.212:6381"] //格式是ip:port
cluster-model:cluster //single, cluster
maxAttempts=3 // 出现异常最大重试次数
soTimeout=2000 // 读取数据超时时间
connectionTimeout=2000 // 连接超时时间
}
mp.net.local-ip="192.168.31.169" //本地ip, 默认取第一个网卡的本地IP
mp.net.public-ip="192.168.31.169" //外网ip, 默认取第一个网卡的外网IP
mp.net.ws-server-port=0 //websocket对外端口, 0表示禁用websocket
mp.net.gateway-server-net=tcp // 网关服务使用的网络 udp/tcp
mp.net.connect-server-port=3000 //接入服务的端口号
mp.http.proxy-enabled=true //启用Http代理功能
mp.snowflake { //雪花算法
workerId=0 // 工作机器ID(0~31)
datacenterId=0 // 数据中心ID(0~31)
}
13 changes: 11 additions & 2 deletions conf/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ mp {
redis {
cluster-model=single //single,cluster,sentinel
sentinel-master:""
nodes:[] s//["127.0.0.1:6379"]格式ip:port
password="" //your password
nodes:[] //["127.0.0.1:6379"]格式ip:port
password="" // 密码
maxAttempts=1 // 出现异常最大重试次数
soTimeout=2000 // 读取数据超时时间
connectionTimeout=2000 // 连接超时时间
config {
maxTotal:8,
maxIdle:4,
Expand Down Expand Up @@ -236,4 +239,10 @@ mp {
thread-pool-factory:"com.mpush.tools.thread.pool.DefaultThreadPoolFactory"
dns-mapping-manager:"com.mpush.common.net.HttpProxyDnsMappingManager"
}

#雪花算法
snowflake {
workerId=0 // 工作机器ID(0~31)
datacenterId=0 // 数据中心ID(0~31)
}
}
2 changes: 1 addition & 1 deletion mpush-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>mpush</artifactId>
<groupId>com.github.mpusher</groupId>
<version>0.8.1</version>
<version>0.8.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 2 additions & 0 deletions mpush-api/src/main/java/com/mpush/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public interface Constants {
String EMPTY_STRING = "";
String ANY_HOST = "0.0.0.0";
String KICK_CHANNEL_PREFIX = "/mpush/kick/";
// 过期时间,单位为秒,默认1800,即30分钟
int EXPIRE_TIME = 1800;

static String getKickChannel(String hostAndPort) {
return KICK_CHANNEL_PREFIX + hostAndPort;
Expand Down
2 changes: 2 additions & 0 deletions mpush-api/src/main/java/com/mpush/api/MPushContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
/**
* Created by ohun on 2017/6/21.
*
* MPush上下文
*
* @author [email protected] (夜色)
*/
public interface MPushContext {
Expand Down
2 changes: 2 additions & 0 deletions mpush-api/src/main/java/com/mpush/api/common/Condition.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
/**
* Created by ohun on 16/10/24.
*
* 条件
*
* @author [email protected] (夜色)
*/
public interface Condition extends Predicate<Map<String, Object>> {
Expand Down
12 changes: 12 additions & 0 deletions mpush-api/src/main/java/com/mpush/api/connection/Cipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@
/**
* Created by ohun on 2015/12/28.
*
* 暗号、加密方式
*
* @author [email protected]
*/
public interface Cipher {

/**
* 解码
* @param data
* @return
*/
byte[] decrypt(byte[] data);

/**
* 编码
* @param data
* @return
*/
byte[] encrypt(byte[] data);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class SessionContext {
public String clientVersion;
public String deviceId;
public String userId;
public String alias;
public String tags;
public int heartbeat = 10000;// 10s
public Cipher cipher;
Expand Down Expand Up @@ -97,6 +98,7 @@ public String toString() {
", osVersion='" + osVersion + '\'' +
", deviceId='" + deviceId + '\'' +
", userId='" + userId + '\'' +
", alias='" + alias + '\'' +
", tags='" + tags + '\'' +
", heartbeat=" + heartbeat +
'}';
Expand Down
6 changes: 6 additions & 0 deletions mpush-api/src/main/java/com/mpush/api/event/Topics.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
* @author [email protected] (夜色)
*/
public interface Topics {
/**
* mq在线订阅主题
*/
String ONLINE_CHANNEL = "/mpush/online/";

/**
* mq离线订阅主题
*/
String OFFLINE_CHANNEL = "/mpush/offline/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@
/**
* Created by ohun on 2015/12/22.
*
* 包接收器
*
* @author [email protected]
*/
public interface PacketReceiver {
/**
* 接收
* @param packet
* @param connection
*/
void onReceive(Packet packet, Connection connection);
}
30 changes: 30 additions & 0 deletions mpush-api/src/main/java/com/mpush/api/protocol/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,55 @@
* @author [email protected]
*/
public enum Command {
// 心跳
HEARTBEAT(1),
// 握手
HANDSHAKE(2),
// 登录
LOGIN(3),
// 登出
LOGOUT(4),
// 绑定
BIND(5),
// 解绑
UNBIND(6),
// 快速链接
FAST_CONNECT(7),
// 暂停
PAUSE(8),
// 恢复
RESUME(9),
// 错误
ERROR(10),
// 正常
OK(11),
// http代理
HTTP_PROXY(12),
// 踢除
KICK(13),
// 网关踢除
GATEWAY_KICK(14),
// 推送
PUSH(15),
// 网关推送
GATEWAY_PUSH(16),
// 通知
NOTIFICATION(17),
// 网关通知
GATEWAY_NOTIFICATION(18),
// 聊天
CHAT(19),
// 网关聊天
GATEWAY_CHAT(20),
// 组
GROUP(21),
// 网关组
GATEWAY_GROUP(22),
// 确认
ACK(23),
// 不确认
NACK(24),
// 未知
UNKNOWN(-1);

Command(int cmd) {
Expand All @@ -57,6 +82,11 @@ public enum Command {

public final byte cmd;

/**
* 从数据包中获取命令
* @param b
* @return
*/
public static Command toCMD(byte b) {
Command[] values = values();
if (b > 0 && b < values.length) return values[b - 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.mpush.api.Constants;
import com.mpush.api.spi.common.Json;
import com.mpush.api.spi.common.JsonFactory;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
Expand All @@ -48,7 +47,7 @@ public JsonPacket(Command cmd) {
this.addFlag(FLAG_JSON_BODY);
}

public JsonPacket(Command cmd, int sessionId) {
public JsonPacket(Command cmd, long sessionId) {
super(cmd, sessionId);
this.addFlag(FLAG_JSON_BODY);
}
Expand Down
Loading