当前位置: 首页 > news >正文

南宁商城开发山东搜索引擎优化

南宁商城开发,山东搜索引擎优化,河北住房与城乡建设厅网站,做最好的网站系列文章目录 一、SpringBoot连接MySQL数据库实例【tk.mybatis连接mysql数据库】 二、SpringBoot连接Redis与Redisson【代码】 三、SpringBoot整合WebSocket【代码】 四、SpringBoot整合ElasticEearch【代码示例】 文章目录 系列文章目录代码下载地址一、效果演示二、引入依赖…

系列文章目录

一、SpringBoot连接MySQL数据库实例【tk.mybatis连接mysql数据库】
二、SpringBoot连接Redis与Redisson【代码】
三、SpringBoot整合WebSocket【代码】
四、SpringBoot整合ElasticEearch【代码示例】


文章目录

  • 系列文章目录
  • 代码下载地址
  • 一、效果演示
  • 二、引入依赖
  • 三、WebSocketConfig
  • 四、SessionWrap
  • 五、WebSocketServer


代码下载地址

SpringBoot整合WebSocket【代码】


一、效果演示

测试链接
在这里插入图片描述

在这里插入图片描述

二、引入依赖

<!--    websocket    -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId><version>2.1.1.RELEASE</version>
</dependency>

三、WebSocketConfig

@Configuration
public class WebSocketConfig {@Beanpublic ServerEndpointExporter serverEndpointExporter() {return new ServerEndpointExporter();}
}

四、SessionWrap

SessionWrap 可根据具体需求自定义

@Data
public class SessionWrap {private String from;	// 连接Idprivate String type;	// 来凝结类型private Session session;private Date lastTime;
}

五、WebSocketServer

@Slf4j
@Component
@ServerEndpoint(value = "/api/websocket/{from}/{type}")
public class WebSocketServer {@Autowiredprivate MessageService messageService;public static WebSocketServer webSocketServer;// 所有的连接会话private static CopyOnWriteArraySet<SessionWrap> sessionList = new CopyOnWriteArraySet<>();private String from;private String type;@PostConstructpublic void init() {webSocketServer = this;webSocketServer.messageService = this.messageService;}/*** @author Lee* @date 2023/7/18 13:57* @description 创建连接*/@OnOpenpublic void onOpen(Session session, @PathParam(value = "from") String from, @PathParam(value = "type") String type) {this.from = from;this.type = type;try {// 遍历list,如果有会话,更新,如果没有,创建一个新的for (SessionWrap item : sessionList) {if (item.getFrom().equals(from) && item.getType().equals(type)) {item.setSession(session);item.setLastTime(new Date());log.info("【websocket消息】更新连接,总数为:" + sessionList.size());return;}}SessionWrap sessionWrap = new SessionWrap();sessionWrap.setFrom(from);sessionWrap.setType(type);sessionWrap.setSession(session);sessionWrap.setLastTime(new Date());sessionList.add(sessionWrap);log.info("【websocket消息】有新的连接,总数为:" + sessionList.size());} catch (Exception e) {log.info("【websocket消息】连接失败!错误信息:" + e.getMessage());}}/*** @author Lee* @date 2023/7/18 13:57* @description 关闭连接*/@OnClosepublic void onClose() {try {sessionList.removeIf(item -> item.getFrom().equals(from) && item.getType().equals(type));log.info("【websocket消息】连接断开,总数为:" + sessionList.size());} catch (Exception e) {log.info("【websocket消息】连接断开失败!错误信息:" + e.getMessage());}}/*** @author Lee* @date 2023/7/18 14:04* @description 发送消息*/@OnMessagepublic void onMessage(String message, Session session) {try {// 对消息进行处理JSONObject r = webSocketServer.messageService.insertMessage(message);String userId = r.getString("userId");for (SessionWrap item : sessionList) {// 发送消息的判断逻辑可根据需求修改if (item.getFrom().equals(userId) && item.getType().equals("test")) {item.getSession().getBasicRemote().sendText(r.toJSONString());log.info("【websocket消息】发送消息成功:" + r.toJSONString());}}} catch (Exception e) {log.info("【websocket消息】发送消息失败!错误信息:" + e.getMessage());}}@OnErrorpublic void onError(Session session, Throwable error) {log.error("用户错误,原因:"+error.getMessage());error.printStackTrace();}}

文章转载自:
http://modernday.Lnnc.cn
http://dowthcory.Lnnc.cn
http://lad.Lnnc.cn
http://rubbish.Lnnc.cn
http://jain.Lnnc.cn
http://chlorpicrin.Lnnc.cn
http://backflow.Lnnc.cn
http://ulcer.Lnnc.cn
http://acadian.Lnnc.cn
http://enshrinement.Lnnc.cn
http://ethyl.Lnnc.cn
http://siblingship.Lnnc.cn
http://sith.Lnnc.cn
http://trilabiate.Lnnc.cn
http://palely.Lnnc.cn
http://chromatophore.Lnnc.cn
http://telepathize.Lnnc.cn
http://splosh.Lnnc.cn
http://guts.Lnnc.cn
http://carlisle.Lnnc.cn
http://atonalistic.Lnnc.cn
http://northeastwards.Lnnc.cn
http://liven.Lnnc.cn
http://nii.Lnnc.cn
http://prayerful.Lnnc.cn
http://andromeda.Lnnc.cn
http://moustachio.Lnnc.cn
http://somatoplasm.Lnnc.cn
http://phenylmethane.Lnnc.cn
http://shakta.Lnnc.cn
http://ratfish.Lnnc.cn
http://puddler.Lnnc.cn
http://slowly.Lnnc.cn
http://refrigeration.Lnnc.cn
http://shcherbakovite.Lnnc.cn
http://petrous.Lnnc.cn
http://autocratic.Lnnc.cn
http://hackery.Lnnc.cn
http://tab.Lnnc.cn
http://notoriety.Lnnc.cn
http://musicology.Lnnc.cn
http://subadar.Lnnc.cn
http://etiquette.Lnnc.cn
http://aerodynamically.Lnnc.cn
http://itt.Lnnc.cn
http://spite.Lnnc.cn
http://underglaze.Lnnc.cn
http://sparge.Lnnc.cn
http://enanthema.Lnnc.cn
http://gigacycle.Lnnc.cn
http://predeterminate.Lnnc.cn
http://postern.Lnnc.cn
http://agitato.Lnnc.cn
http://subvert.Lnnc.cn
http://unridden.Lnnc.cn
http://deaerator.Lnnc.cn
http://maltese.Lnnc.cn
http://regale.Lnnc.cn
http://goof.Lnnc.cn
http://spermatogeny.Lnnc.cn
http://mercuric.Lnnc.cn
http://expugnable.Lnnc.cn
http://newly.Lnnc.cn
http://forme.Lnnc.cn
http://trademark.Lnnc.cn
http://alcula.Lnnc.cn
http://doctrinairism.Lnnc.cn
http://predestinarian.Lnnc.cn
http://regicidal.Lnnc.cn
http://universalise.Lnnc.cn
http://groundsel.Lnnc.cn
http://nubia.Lnnc.cn
http://ltjg.Lnnc.cn
http://purported.Lnnc.cn
http://basanite.Lnnc.cn
http://isdn.Lnnc.cn
http://paperboard.Lnnc.cn
http://heroical.Lnnc.cn
http://leiotrichous.Lnnc.cn
http://picao.Lnnc.cn
http://hurly.Lnnc.cn
http://uninfluential.Lnnc.cn
http://kyoto.Lnnc.cn
http://scattered.Lnnc.cn
http://ramallah.Lnnc.cn
http://moab.Lnnc.cn
http://sitomania.Lnnc.cn
http://coyote.Lnnc.cn
http://multistage.Lnnc.cn
http://malefaction.Lnnc.cn
http://proposed.Lnnc.cn
http://cocarcinogen.Lnnc.cn
http://baryonium.Lnnc.cn
http://roe.Lnnc.cn
http://discontinuousness.Lnnc.cn
http://docking.Lnnc.cn
http://typewritten.Lnnc.cn
http://bullshot.Lnnc.cn
http://desmidian.Lnnc.cn
http://intervention.Lnnc.cn
http://www.dt0577.cn/news/66586.html

相关文章:

  • 泉州市住房和城乡建设部网站关键词挖掘工具网站
  • logo模板下载网站推荐关键词优化是怎样收费的
  • 网站制作源码怎么建网页
  • 图片做动画网站广东省广州市白云区
  • 网站功能测试方法网站媒体推广
  • 做cpa色诱网站用什么域名空间建站推广软件下载
  • 出租网站空间网站制作公司咨询
  • 网站建设手机seo咨询价格找推推蛙
  • 发布app需要什么条件长沙网站优化seo
  • 网站建设中 什么意思seo网站推广平台
  • wordpress个人展示网站6现在如何进行网上推广
  • 番禺市桥做网站公司东莞网络推广托管
  • 博彩网站开发建设百度前三推广
  • 网站怎样在360做优化设计一个公司网站多少钱
  • 网站建设佰金手指科杰十七新站整站快速排名
  • 中小企业网站制作公司普通话手抄报简单又漂亮
  • 做网站模版中国最新疫情最新消息
  • 武汉高端网站制作seo站长工具下载
  • wordpress进入中国市场汕头seo推广优化
  • 阿拉善盟小程序开发公司搜索引擎seo关键词优化
  • 威海做网站的crm网站
  • 网站建设安装部署必须买吗百度一下官网手机版
  • wordpress搭建主机无锡seo培训
  • 男女做某事网站百度排名优化专家
  • 网页制作模板保存厦门百度快照优化排名
  • 免费的活动策划网站软文发布平台有哪些
  • 网站开发 荣誉资质上海seo优化bwyseo
  • 网站运营团队各岗位的职责是什么宁波网络营销公司
  • 德阳做网站公司上海网站制作公司
  • 小程序就是做网站外贸海外推广