feat: init websocket模块

This commit is contained in:
weihongyang
2022-06-29 16:29:25 +08:00
parent 8d6cda8f90
commit 6d792317dd
4 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package com.cnbm.websocket.task;
import com.cnbm.scheduletask.task.ITask;
import com.cnbm.websocket.server.WebSocketServer;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @Author weihongyang
* @Date 2022/6/29 2:01 PM
* @Version 1.0
*/
@Log4j2
@Component("sendMessageTask")
public class SendMessageTask implements ITask {
public void run(String params) {
Iterator<Map.Entry<String, WebSocketServer>> socketIt = WebSocketServer.webSocketMap.entrySet().iterator();
while (socketIt.hasNext()) {
Map.Entry<String, WebSocketServer> socketServerEntry = socketIt.next();
try {
socketServerEntry.getValue().sendMsg("定时发送:"+new Date().toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
log.info("sendMessageTask定时任务正在执行参数为{}", params);
}
}