Spring WebSocket 实例之间连接和发送消息 [英] Connecting and sending message between Spring WebSocket instances

查看:41
本文介绍了Spring WebSocket 实例之间连接和发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个使用 Spring Boot WebSocket 的实例(根据 Spring 的前半部分创建)指南).我需要它们连接到特定主机名和端口的其他实例,并能够使用 STOMP 协议通过 websocket 连接发送消息.

I have multiple instances using Spring Boot WebSocket (created following the first half of Spring's guide). I need them to connect to other instances at specific hostnames and ports and to be able to send messages over the websocket connection using STOMP protocol.

不能回答我的问题的事情:

Things that don't answer my question:

  • I have read Spring: send message to websocket clients and Sending message to specific user on Spring Websocket but these and other questions seem to all assume that a client has already initiated a connection and that there are users and topics established. This is not my use case as my services are both server AND client.
  • I am not using a cluster and I am not sharing sessions across instances as in Spring Websocket in a tomcat cluster

推荐答案

我找到了一些可以说明如何实现这一点的资源:

I have found some resources that cast some light on how to accomplish this:

  1. http://www.baeldung.com/websockets-api-java-spring-client

https://www.sitepoint.com/implementing-spring-websocket-server-and-client/#javaspringchatclient

http://useof.org/java-open-source/org.springframework.messaging.simp.stomp.StompSessionHandler

第 3 项至少是一个完整的实现,但遗憾的是没有注释来解释正在发生的事情.

number 3 is at least a complete implementation but is unfortunately devoid of comments to explain what's going on.

这篇关于Spring WebSocket 实例之间连接和发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆