forked from chenxuebing3/learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
剩下的就是业务信息与channelId之间的维护和支持多种手段的推送问题
- Loading branch information
Showing
27 changed files
with
1,388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/** | ||
!**/src/test/** | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM registry.cn-hangzhou.aliyuncs.com/sherry/java:1.8.0_111 | ||
VOLUME /tmp | ||
ADD ws-push.jar ws-push.jar | ||
RUN sh -c 'touch /ws-push.jar' | ||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | ||
RUN echo 'Asia/Shanghai' > /etc/timezone | ||
ENV JAVA_OPTS="" | ||
ENTRYPOINT [ "sh", "-c", "java -Xms$Xms -Xmx$Xmx $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /ws-push.jar" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.2.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.zhangln.push</groupId> | ||
<artifactId>ws-push</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>ws-push</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<mysql.jdbc.version>5.1.48</mysql.jdbc.version> | ||
<mybatis-plus.version>3.1.0</mybatis-plus.version> | ||
<velocity.version>2.0</velocity.version> | ||
<netty.version>4.1.25.Final</netty.version> | ||
<docker.maven.version>1.1.1</docker.maven.version> | ||
<docker.repository>registry.cn-hangzhou.aliyuncs.com</docker.repository> | ||
<docker.auth>docker-aliyun-yiding</docker.auth> | ||
<docker.registry.name>cloud-micro</docker.registry.name> | ||
<hutool.version>4.6.1</hutool.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>fastjson</artifactId> | ||
<version>1.2.62</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-all</artifactId> | ||
<version>${netty.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-all</artifactId> | ||
<version>${hutool.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-redis</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-amqp</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-websocket</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-boot-starter</artifactId> | ||
<version>${mybatis-plus.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-generator</artifactId> | ||
<version>${mybatis-plus.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.velocity</groupId> | ||
<artifactId>velocity-engine-core</artifactId> | ||
<version>${velocity.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>${mysql.jdbc.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<includes> | ||
<include>**/*.properties</include> | ||
<include>**/*.xml</include> | ||
<include>**/*.yaml</include> | ||
<include>**/*.yml</include> | ||
<include>**/*.sql</include> | ||
<include>**/*.html</include> | ||
<include>**/*.css</include> | ||
<include>**/*.js</include> | ||
</includes> | ||
<!-- <filtering>true</filtering>--> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<finalName>${project.name}</finalName> | ||
</configuration> | ||
</plugin> | ||
<!-- 资源文件拷贝插件 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.7</version> | ||
<configuration> | ||
<encoding>UTF-8</encoding> | ||
<!-- <delimiters>@</delimiters>--> | ||
<useDefaultDelimiters>false</useDefaultDelimiters> | ||
</configuration> | ||
</plugin> | ||
<!-- java编译插件 --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.2</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<encoding>UTF-8</encoding> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>versions-maven-plugin</artifactId> | ||
<version>2.6</version> | ||
<configuration> | ||
<generateBackupPoms>false</generateBackupPoms> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.spotify</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<version>${docker.maven.version}</version> | ||
<configuration> | ||
<imageName>${docker.repository}/${docker.registry.name}/${project.artifactId}:${project.version} | ||
</imageName> | ||
<dockerDirectory>./</dockerDirectory> | ||
<serverId>${docker.auth}</serverId> | ||
<resources> | ||
<resource> | ||
<targetPath>/</targetPath> | ||
<directory>${project.build.directory}</directory> | ||
<include>${project.name}.jar</include> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
35 changes: 35 additions & 0 deletions
35
WebSocket/ws-push/src/main/java/com/zhangln/push/wspush/NettyBooter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.zhangln.push.wspush; | ||
|
||
import com.zhangln.push.wspush.websocket.WebSocketServer; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* 当SpringBoot启动后,加载这个类 | ||
* | ||
* @author mac | ||
*/ | ||
@Component | ||
@Slf4j | ||
public class NettyBooter implements ApplicationListener<ContextRefreshedEvent> { | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
|
||
if (event.getApplicationContext().getParent() == null) { | ||
//事件获得上下文对象化后启动服务器 | ||
try { | ||
WebSocketServer.getInstance() | ||
.start(10002); | ||
} catch (Exception e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
WebSocket/ws-push/src/main/java/com/zhangln/push/wspush/WsPushApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.zhangln.push.wspush; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author zhangliuning | ||
*/ | ||
@SpringBootApplication | ||
public class WsPushApplication implements CommandLineRunner { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(WsPushApplication.class, args); | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
System.out.println("TODO 下线注册在本实例上的客户端连接"); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
WebSocket/ws-push/src/main/java/com/zhangln/push/wspush/config/MyBatisPlusConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.zhangln.push.wspush.config; | ||
|
||
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor; | ||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; | ||
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
/** | ||
* @author sherry | ||
* @description | ||
* @date Create in 2019/12/6 | ||
* @modified By: | ||
*/ | ||
@EnableTransactionManagement | ||
@Configuration | ||
@MapperScan(basePackages = "com.zhangln.push.wspush.mapper") | ||
@Slf4j | ||
public class MyBatisPlusConfig { | ||
|
||
/** | ||
* 乐观锁 | ||
* | ||
* @return | ||
*/ | ||
@Bean | ||
public OptimisticLockerInterceptor optimisticLockerInterceptor() { | ||
return new OptimisticLockerInterceptor(); | ||
} | ||
|
||
/** | ||
* 分页插件 | ||
*/ | ||
@Bean | ||
public PaginationInterceptor paginationInterceptor() { | ||
PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); | ||
return paginationInterceptor; | ||
} | ||
|
||
/** | ||
* SQL执行效率插件 | ||
*/ | ||
@Bean | ||
@Profile({"DEV", "TEST"}) | ||
public PerformanceInterceptor performanceInterceptor() { | ||
return new PerformanceInterceptor(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
WebSocket/ws-push/src/main/java/com/zhangln/push/wspush/controller/RegUserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.zhangln.push.wspush.controller; | ||
|
||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* <p> | ||
* 注册用户,即允许使用推送服务的账号 前端控制器 | ||
* </p> | ||
* | ||
* @author sherry | ||
* @since 2019-12-06 | ||
*/ | ||
@RestController | ||
@RequestMapping("/wspush/reg-user-entity") | ||
public class RegUserController { | ||
|
||
} | ||
|
33 changes: 33 additions & 0 deletions
33
WebSocket/ws-push/src/main/java/com/zhangln/push/wspush/controller/WsPushController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.zhangln.push.wspush.controller; | ||
|
||
import com.zhangln.push.wspush.websocket.UserChannelRelation; | ||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author sherry | ||
* @description | ||
* @date Create in 2019/12/7 | ||
* @modified By: | ||
*/ | ||
@RestController | ||
@RequestMapping("/push") | ||
@Slf4j | ||
public class WsPushController { | ||
|
||
@GetMapping(value = "/test1", params = {"channelId", "msg"}) | ||
public ResponseEntity pushTest(String channelId, String msg) { | ||
|
||
UserChannelRelation.get(channelId) | ||
.ifPresent(channel -> { | ||
channel.writeAndFlush(new TextWebSocketFrame(msg)); | ||
}); | ||
|
||
return ResponseEntity.ok("推送成功"); | ||
} | ||
|
||
} |
Oops, something went wrong.