Connecting and sending message between Spring WebSocket instances

柔情痞子 提交于 2021-02-08 10:48:32

问题


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.

How can I connect to my other services over websocket?

How can I send messages using the STOMP protocol (preferably using the same marshalling/unmarshalling magic I get with received messages)?

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

回答1:


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

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

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

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

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



来源:https://stackoverflow.com/questions/48793167/connecting-and-sending-message-between-spring-websocket-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!