spring-websocket

Spring session + Spring web socket. Send message to specific client based on session id

↘锁芯ラ 提交于 2019-12-04 04:16:40
问题 I have followed Quetion1 and Quetion2 from stack overflow to send messages to specific client, based on its sessionId but could not find success. Below is my sample RestController class @RestController public class SpringSessionTestApi { @Autowired public SimpMessageSendingOperations messagingTemplate; @MessageMapping("/messages") public void greeting(HelloMessage message, SimpMessageHeaderAccessor headerAccessor) throws Exception { String sessionId = (String) headerAccessor

STOMP or XMPP - Over websocket

扶醉桌前 提交于 2019-12-03 22:32:24
I am working on a project which involves real time chat (messaging, including group chats). I have worked with websockets before, So I started working on this using spring-websockets and I did some reading about what is the best way to implement it. Then I came across STOMP (as a sub-protocol for websockets)and as there is direct support for STOMP in spring it was bit easy to achieve what I was supposed to do. But my doubt is as far as my understanding STOMP and XMPP are similar protocols(messaging protocols) but I could not find any questions/blogs where the differences are explained and why

How to reject topic subscription based on user rights with Spring-websocket

时光怂恿深爱的人放手 提交于 2019-12-03 17:55:27
问题 I'm implementing a version of the stock application where the server able to reject topic subscription for certain topic based on the user rights. Is there a way in spring-websocket to do this? For example: In the stock example project we have price topic for 3 instrument: Apple, Microsoft, Google And have two user: User1, User2 User1 should have access to Apple and Microsoft User2 should have access to Google only If User1 subscribe to Google he should got rejected response, and message

Spring WebSocket. Get access to Cookie in Config

懵懂的女人 提交于 2019-12-03 17:11:43
I'm trying to configure WebSocket via Spring with STOMP, OAuth 2 and SockJS. New spec tells us how to implement it using Interceptors. The case is: if user is authenticated there is an Bearer Token in Native header of CONNECT request and there is no problem to set principal via Token. But my task is to use BrowserToken for unauthorized users (which is saved in Cookies). How can i get it from the request? I've found a solution: @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/websocket/tracker") .withSockJS() .setInterceptors

Send Notification to specific user in spring boot websocket

此生再无相见时 提交于 2019-12-03 16:21:50
问题 I want to send notification to specific client. e.g username user @Configuration @EnableWebSocketMessageBroker public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) { stompEndpointRegistry.addEndpoint("/socket") .setAllowedOrigins("*") .withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/topic", "

Spring: send message to websocket clients

穿精又带淫゛_ 提交于 2019-12-03 13:33:32
问题 I'm building a webchat with Spring Boot, RabbitMQ and WebSocket as POC, but I'm stucked a the last point: WebSockets I want my ws clients to connect to a specific endpoint, like /room/{id} and when a new message arrives, I want the server to send the response to clients, but I searched for something similar and didn't found. Currently, when the message arrives, I process it with RabbitMQ, like container.setMessageListener(new MessageListenerAdapter(){ @Override public void onMessage(org

How to send ERROR message to STOMP clients with Spring WebSocket?

泪湿孤枕 提交于 2019-12-03 11:56:06
问题 I am using Spring's STOMP over WebSocket implementation with a full-featured ActiveMQ broker. When users SUBSCRIBE to a topic, there is some permissions logic that they must pass through before being successfully subscribed. I am using a ChannelInterceptor to apply the permissions logic, as configured below: WebSocketConfig.java: @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints

How to send custom message to custom user with spring websocket?

半城伤御伤魂 提交于 2019-12-03 10:58:33
I'm new to spring websocket . I want to send product changes to clients. For this, I want to do it as follows: Client creates a socket connection and subscribes destination: var socket = new SockJS('/websocket'); var stompClient = Stomp.over(socket); stompClient.connect({}, function (frame) { stompClient.subscribe('/product/changes', function (scoredata) { // We received product changes }); }); //Send Ajax request and say server I want to know product with id=5 changes. sendAjaxRequest(5); I've configured spring app as follow: @Configuration @EnableWebSocketMessageBroker public class

Simple: convertAndSendToUser Where do I get a username?

北慕城南 提交于 2019-12-03 08:47:41
In Spring Boot (Websockets) I just saw this example: messaging.convertAndSendToUser( username, "/queue/notifications", new Notification("You just got mentioned!")); Where does the guy get a username from? I can't find any mention about where to get that username... This answer is written based on this application: https://github.com/spring-guides/gs-messaging-stomp-websocket In order to register a user, you must first create an object that will represent it, for example: public final class User implements Principal { private final String name; public User(String name) { this.name = name; }

Websockets, SockJs, Stomp, Spring, RabbitMQ, delete User specific Queues automatically

倾然丶 夕夏残阳落幕 提交于 2019-12-03 08:28:09
i hope someone can help me with this issue: I use the Websocket support of Spring. With SockJs and StompJs i subscribe a queue like this: var socket = new SockJS(localhost + 'websocket'); stompClient = Stomp.over(socket); stompClient.connect('', '', function(frame) { stompClient.subscribe("/user/queue/gotMessage", function(message) { gotMessage((JSON.parse(message.body))); }); }, function(error) { }); This works really fine with the SimpMessageSendingOperations of Spring. BUT there is one big problem. the Queue name looks like this: gotMessage-user3w4tstcj and its not declared as an auto