forked from yangzongzhuan/RuoYi-Cloud
-
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.
- Loading branch information
mingxing.ai
committed
Aug 17, 2023
1 parent
0dd3d65
commit c45b16d
Showing
25 changed files
with
218 additions
and
504 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
75 changes: 75 additions & 0 deletions
75
...uoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/DefaultSocketIOServer.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,75 @@ | ||
package com.ruoyi.common.websocket; | ||
|
||
import com.corundumstudio.socketio.Configuration; | ||
import com.corundumstudio.socketio.SocketConfig; | ||
import com.corundumstudio.socketio.SocketIOServer; | ||
import com.corundumstudio.socketio.Transport; | ||
import com.ruoyi.common.websocket.handler.SocketIOServerHandler; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Resource; | ||
|
||
@Slf4j | ||
@Component | ||
public class DefaultSocketIOServer implements InitializingBean { | ||
|
||
@Resource | ||
private SocketIOServerHandler socketIOServerHandler; | ||
|
||
@Value("${socket.io.host:localhost}") | ||
private String host; | ||
|
||
@Value("${socket.io.port:9001}") | ||
private Integer port; | ||
|
||
@Value("${socket.io.bossCount:1}") | ||
private int bossCount; | ||
|
||
@Value("${socket.io.workCount:10}") | ||
private int workCount; | ||
|
||
@Value("${socket.io.allowCustomRequests:true}") | ||
private boolean allowCustomRequests; | ||
|
||
@Value("${socket.io.upgradeTimeout:100000}") | ||
private int upgradeTimeout; | ||
|
||
@Value("${socket.io.pingTimeout:600000}") | ||
private int pingTimeout; | ||
|
||
@Value("${socket.io.pingInterval:20000}") | ||
private int pingInterval; | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
SocketConfig socketConfig = new SocketConfig(); | ||
socketConfig.setReuseAddress(true); | ||
socketConfig.setTcpNoDelay(true); | ||
socketConfig.setSoLinger(0); | ||
|
||
Configuration configuration = new Configuration(); | ||
configuration.setSocketConfig(socketConfig); | ||
// host在本地测试可以设置为localhost或者本机IP,在Linux服务器跑可换成服务器IP | ||
configuration.setHostname(host); | ||
configuration.setPort(port); | ||
// socket连接数大小(如只监听一个端口boss线程组为1即可) | ||
configuration.setBossThreads(bossCount); | ||
configuration.setWorkerThreads(workCount); | ||
configuration.setAllowCustomRequests(allowCustomRequests); | ||
// 协议升级超时时间(毫秒),默认10秒。HTTP握手升级为ws协议超时时间 | ||
configuration.setUpgradeTimeout(upgradeTimeout); | ||
// Ping消息超时时间(毫秒),默认60秒,这个时间间隔内没有接收到心跳消息就会发送超时事件 | ||
configuration.setPingTimeout(pingTimeout); | ||
// Ping消息间隔(毫秒),默认25秒。客户端向服务器发送一条心跳消息间隔 | ||
configuration.setPingInterval(pingInterval); | ||
configuration.setTransports(Transport.POLLING, Transport.WEBSOCKET); | ||
configuration.setOrigin(":*:"); | ||
SocketIOServer socketIOServer = new SocketIOServer(configuration); | ||
socketIOServer.addListeners(socketIOServerHandler); | ||
socketIOServer.start(); | ||
log.info("socket io server start successfully!"); | ||
} | ||
} |
97 changes: 0 additions & 97 deletions
97
...mmon/ruoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/WebSocketServer.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...uoyi-common-websocket/src/main/java/com/ruoyi/common/websocket/config/SocketIOConfig.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,10 @@ | ||
package com.ruoyi.common.websocket.config; | ||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan(basePackages = "com.ruoyi.common.websocket") | ||
public class SocketIOConfig { | ||
} | ||
|
16 changes: 0 additions & 16 deletions
16
...oyi-common-websocket/src/main/java/com/ruoyi/common/websocket/confog/WebSocketConfig.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...i-common-websocket/src/main/java/com/ruoyi/common/websocket/handler/MessageProcessor.java
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
...mon-websocket/src/main/java/com/ruoyi/common/websocket/handler/SocketIOServerHandler.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,37 @@ | ||
package com.ruoyi.common.websocket.handler; | ||
|
||
import com.corundumstudio.socketio.AckRequest; | ||
import com.corundumstudio.socketio.SocketIOClient; | ||
import com.corundumstudio.socketio.annotation.OnConnect; | ||
import com.corundumstudio.socketio.annotation.OnEvent; | ||
import com.ruoyi.common.core.constant.TokenConstants; | ||
import com.ruoyi.common.websocket.session.SocketIOSessionPool; | ||
import com.ruoyi.common.websocket.session.model.SocketIOSession; | ||
import com.sun.nio.sctp.MessageInfo; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.HashMap; | ||
|
||
@Slf4j | ||
@Component | ||
public class SocketIOServerHandler { | ||
|
||
@Resource | ||
private SocketIOSessionPool sessionPool; | ||
|
||
@OnConnect | ||
public void onConnect(SocketIOClient socketIOClient) { | ||
socketIOClient.sendEvent("connect", "成功"); | ||
sessionPool.createSession(SocketIOSession.builder().client(socketIOClient).build()); | ||
} | ||
|
||
@OnEvent("heartbeat") | ||
public void onHeartbeat(SocketIOClient socketIOClient, AckRequest ackRequest) { | ||
log.info("接受到心跳信息"); | ||
socketIOClient.sendEvent("heartbeat", "ok"); | ||
} | ||
|
||
} |
28 changes: 0 additions & 28 deletions
28
...ocket/src/main/java/com/ruoyi/common/websocket/handler/ext/SubscribeMessageProcessor.java
This file was deleted.
Oops, something went wrong.
67 changes: 0 additions & 67 deletions
67
...-common-websocket/src/main/java/com/ruoyi/common/websocket/session/ClientSessionPool.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.