Skip to content

Commit

Permalink
Init message push service by websocket.
Browse files Browse the repository at this point in the history
  • Loading branch information
KangSpace committed Jul 14, 2024
1 parent 51e8455 commit d826a86
Show file tree
Hide file tree
Showing 223 changed files with 15,955 additions and 0 deletions.
13 changes: 13 additions & 0 deletions message-push-common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.idea
/message-push-common*/target
/message-push-common-*/target
/message-push-common*/target/*
/message-push-common-*/target/*

.DS_Store
*.iml

/.idea/*
/target/*

!.mvn/wrapper/maven-wrapper.jar
3 changes: 3 additions & 0 deletions message-push-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# message-push-common

消息推送项目公共包
134 changes: 134 additions & 0 deletions message-push-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.kangspace.messagepush</groupId>
<artifactId>message-push</artifactId>
<version>${revision}</version>
</parent>

<artifactId>message-push-common</artifactId>
<version>${revision}</version>

<properties>
<java.version>1.8</java.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>

</properties>

<dependencies>

<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<optional>true</optional>
<scope>provided</scope>
</dependency>

<!-- common util -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>

<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>

<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>

<!-- 其他 -->
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>maven2</id>
<name>maven2</name>
<url>https://repo1.maven.org/maven2</url>
</repository>
</repositories>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.kangspace.messagepush.core.constant;

/**
* 错误消息常量类
*
* @author [email protected]
* @since 2021/10/27
*/
public interface ErrorMessageConstants {
/**
* 协议错误
*/
String INVALID_PROTOCOL_TYPE_MSG = "错误的请求协议,要求协议为:%s,实际为:%s";
/**
* 请求参数错误
*/
String INVALID_REQUEST_PARAM_MSG = "错误的请求参数,要求为:%s,实际为:%s";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.kangspace.messagepush.core.constant;

/**
* 常量类
*
* @author [email protected]
* @date 2021-08-25
*/
public interface MessagePushConstants {

/**
* 服务路由前缀
*/
String LB_PATH = "lb://";

/**
* 成功码
*/
Integer SUCCESS_CODE = 1;
/**
* 失败码
*/
Integer FAIL_CODE = 0;

/**
* Response body 属性
*/
String CACHED_RESPONSE_BODY_ATTR = "customCachedResponseBody";

/**
* WebSocket 支持的协议
*/
String[] WEBSOCKET_PROTOCOLS = {"ws", "wss"};

/**
* UID Http请求头Key
*/
String HTTP_HEADER_UID_KEY = "uid";
/**
* auth-app-id Http请求头,值为生成Passport Token使用的AppId
*/
String HTTP_HEADER_AUTH_APP_ID_KEY = "auth-app-id";

/**
* 请求参数 Exchange Attr Key
*/
String EXCHANGE_ATTR_REQUEST_PARAM = "_requestParam";

/**
* 一致性HASH每个物理节点的虚拟节点数
* (每个物理节点的总虚拟节点保持在100-200,默认取:160,此处默认值:40(每个虚拟节点会生成4个节点))
*/
int NUMBER_OF_VIRTUAL_NODE = 40;

/**
* 消息推送Websocket服务名
*/
String MESSAGE_WS_SERVICE_ID = "message-push-ws-microservice";

/**
* 用户Session绑定 ServerWebExchange属性key
*/
String USER_SESSION_HOLDER_EXCHANGE_ATTR_KEY = "user-session-holder";

/**
* 用户Session绑定 ServerWebExchange属性key
*/
String WEBSOCKET_TARGET_SERVICE_NODE_ATTR_KEY = "websocket-target-service-node";

/**
* 推送目标平台
*/
enum PUSH_PLATFORM {
ALL,
H5,
Android,
iOS;

@Override
public String toString() {
return super.toString().toLowerCase();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.kangspace.messagepush.core.constant;

/**
* 排序常量类
*
* @author [email protected]
* @since 2021-04-23
*/
public class OrderConstant {

/**
* 顺序
*/
public static final Integer ASC = 1;

/**
* 逆序
*/
public static final Integer DESC = 2;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.kangspace.messagepush.core.constant;

/**
* Redis相关常量类
*
* @author [email protected]
* @since 2021/10/27
*/
public interface RedisConstants {

String DELIMTRER = ":";
/**
* 消息推送相关key前缀
*/
String MESSAGE_PUSH_BASE_KEY = "message_push";
/**
* 消息推送相关Hash环key
*/
String MESSAGE_PUSH_HASH_RING_KEY = MESSAGE_PUSH_BASE_KEY + DELIMTRER + "hash_ring";
/**
* 消息推送相关Hash环更新同步锁key
*/
String MESSAGE_PUSH_HASH_RING_STORE_LOCK_KEY = MESSAGE_PUSH_BASE_KEY + DELIMTRER + "hash_ring_store_lock";
/**
* 消息推送相关Hash环更新同步锁超时时间,单位s
*/
long MESSAGE_PUSH_HASH_RING_STORE_LOCK_EXPIRE_SEC = 3;

/**
* 实例用户映射 map key
* key: 服务实例 ip:port
* value: array 用户ID列表
*/
String MESSAGE_PUSH_INSTANCE_USER_MAP_KEY = MESSAGE_PUSH_BASE_KEY + DELIMTRER + "instance_user";


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.kangspace.messagepush.core.dto.page;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
* 排序字段
*
* @author [email protected]
* @since 2021-04-23
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class Order {

/**
* 字段名
*/
private String field;

/**
* 排序方式,ApiConst.ASC或ApiConst.DESC
*/
private Integer sequence;

}
Loading

0 comments on commit d826a86

Please sign in to comment.