Can we use Principal object in web socket protocol in Spring
I have an experience using Principal object in http request and process the request further using info about authenticates user from Principal. I wonder if I can do the same thing using Web socket.
In Spring(not boot), Websocket endpoint error
@Configuration @EnableWebSocketMessageBroker public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { … @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry .addEndpoint(“/websocket”) .setAllowedOrigins(“*”) .addInterceptors(new HttpHandshakeInterceptor()) .withSockJS(); } … } It is my Spring Porject websocket Config. And now, I try to connect from client. const socket = new SockJS(‘http://{IP:PORT}/websocket’); // sucess const socket = new WebSocket(‘ws://{IP:PORT}/websocket’); // fail const socket […]
spring boot realtime notification with WebSocket
I have this ecommerce project that I am working on using spring boot. I want to implement a notification to it. What I am trying to achieve is that when a buyer place an order, I want to send a notification to the owner(s) of that product that an order has been placed for delivery as well as also sending a notification to the buyer that he/she has placed an order successfully along with the content of the order. Note that I want the content of the notification to include the order that was placed and I also want the notification to be sent to all the owners of the products that was purchased. What I mean is that a buyer might decide to select a product from different product’s owners, add them together in his/her cart before checking out. In my product implementation, each product has an owner id attached to it so I want to send the notification to all the owners that’s associated to the product(s) that was added to the cart as well as their product details. I thought of using WebSocket for this but I don’t really know how to implement it. I will be glad if someone can give me a guide on how to achieve that or if there is any other way that I can achieve that easily apart from using WebSocket.