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);
		}
	}

}
相关推荐
chian-ocean1 天前
深入 CANN:使用 `tbe-op` 构建自定义高性能算子
网络
中议视控1 天前
可编程网络中央控制系统主机通过红外发射棒控制空调电视等红外设备
网络·物联网·5g
数据安全科普王1 天前
打破中心枷锁:P2P网络如何用“去中心化”重构互联网通信
网络·去中心化·p2p
爱吃烤鸡翅的酸菜鱼1 天前
CANN ops-nn激活函数与池化算子深度解析
网络·开源·aigc
saber_andlibert1 天前
TCMalloc底层实现
java·前端·网络
飞凌嵌入式1 天前
用「EN 18031认证」通关欧盟,这张 “网络安全护照” 已就位
网络·安全·能源
Trouvaille ~1 天前
TCP Socket编程实战(三):线程池优化与TCP编程最佳实践
linux·运维·服务器·网络·c++·网络协议·tcp/ip
JoySSLLian1 天前
手把手教你安装免费SSL证书(附宝塔/Nginx/Apache配置教程)
网络·人工智能·网络协议·tcp/ip·nginx·apache·ssl
Zach_yuan1 天前
自定义协议:实现网络计算器
linux·服务器·开发语言·网络
猫头虎1 天前
如何解决 OpenClaw “Pairing required” 报错:两种官方解决方案详解
网络·windows·网络协议·macos·智能路由器·pip·scipy