pig cloud框架中引入websocket

一、依赖添加(Maven)

复制代码
<!--		websocket依赖-->
		<dependency>
			<groupId>com.pig4cloud.plugin</groupId>
			<artifactId>websocket-spring-boot-starter</artifactId>
			<version>3.0.0</version>
		</dependency>

二、开箱即用websocket

创建service服务层,实现websock推送

java 复制代码
package com.wxzx.scheduling.zk.controller;

@Slf4j
@RestController
@RequestMapping("/websocket")
public class WebSocketTestController {
	@Autowired
	private CanalConnector canalConnector;

	@GetMapping("/test")
	public void getCanalStatus() {
	    // 业务代码实现
		String jsonResult = JSONObject.toJSONString(checkInOutVoWebSocketVos);
		try {
			log.info("websocket推送成功");
            // 这里直接使用
			WebSocketMessageSender.broadcast(jsonResult);
		} catch (Exception e) {
			log.error("websocket推送数据失败:"+e.getMessage(),e);
		}
	}

}
相关推荐
Jony_3 天前
高可用移动网络连接
网络协议
chilix3 天前
Linux 跨网段路由转发配置
网络协议
DianSan_ERP5 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅5 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
gihigo19985 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
2501_946205525 天前
晶圆机器人双臂怎么选型?适配2-12寸晶圆的末端效应器有哪些?
服务器·网络·机器人
linux kernel5 天前
第七部分:高级IO
服务器·网络
数字护盾(和中)5 天前
BAS+ATT&CK:企业主动防御的黄金组合
服务器·网络·数据库
~远在太平洋~5 天前
Debian系统如何删除多余的kernel
linux·网络·debian
unfeeling_5 天前
Keepalived实验
linux·服务器·网络