Mutiple controllers mapped to one Spring websocket - spring-boot

I have a question related to Spring websockets with the STOMP protocol over it.
I'm using websockets for different application but not with the combination of Spring.
I have a client server application that holds multiple websockets connections to the server. Now can I create a client application that connects to the Websocket of Spring (with STOMP). Also can I map one websocket to multiple controllers in Spring? The data for every controller is different. So for example my client sends data to the server and set something a value to say, the data need to be send to controller X. Can Spring automaticly transfer the data to the correct controller?
The image below show a POC for my question. The client does send different messages to the Spring server using a websocket connection. Now for every message the controller need to be changed. So for example for message X the controller X need to handle the request and for message Y the controller Y need to handle the request.
How can I achieve this using Spring websockets using STOMP?

You need use microservices and Spring Cloud. https://spring.io/blog/2015/07/14/microservices-with-spring
The main WebServer need connect to other servers with different functionalities. It is a transactional services.

Related

How can i secure web sockets using spring security?

I'm trying to implement a notification service for my final project. therefore I want to know how to send data to specific users through a socket.

Spring RSocket Kubernetes server - Side car to convert http requests from client?

Small question regarding how to convert http requests into RSocket please.
The server setup is a very straightforward RSocket server.
The server is dockerized and deployed in Kubernetes.
Now there are many clients, I do not have control over them. The clients would like to talk to this RSocket server. The JSON payload the clients sends are all compatible with the RSocket server. However, all clients are just using http clients, not RSocket.
May I ask what is the easiest solution to convert the https requests send from the clients please?
What I tried: Built a layer in between, using Spring Cloud Gateway to take as input a http request, and forward it using a RSocket client.
The drawback of this solution is that there is now another app in the picture. Instead of maintaining one business RSocket application, there is a need to implement and maintain another web server entirely.
May I ask if there is some kind of sidecar pattern using maybe ngnix, istio, Kubernetes services, that can perform the same, without having to full blown develop another web app please?
May I ask what is the easiest solution to convert the https requests send from the clients please?
Thank you
May I ask if there is some kind of sidecar pattern using maybe ngnix, istio, Kubernetes services, that can perform the same, without having to full blown develop another web app please?
No, The concept maybe called broker gateway but not sidecar pattern. You should implements a broker gateway to conevert the protocol, such as HTTP(Rest), GraphQL, gRPC. You can refer a sample project alibaba-rsocket-broker.

Consuming CometD messages with spring webflux

We have a system which publishes messages via cometD.
I wrote a simple java program to establish a connection to the server
then use the bearer token returned from the login to and consume messages
But I want to move this to a Webflux project, but unsure where to start, I can see there is out of box JMS-webflux wrapper, can I use this or is it best to build something similar ?
I'm very new to cometD and have only used simple webflux components,
I can also just use Spring boot, but ideally just like a JmsReceiver or similar
Thanks

How to access request object in #MessageMapping method with spring websocket implementation

I am integrating an existing spring MVC web application with spring websockets. I was successfully able to integrate by following the instructions in
https://spring.io/guides/gs/messaging-stomp-websocket/
The existing web application has a filter, which sets a few of the attributes. I have a requirement to access the attributes set by the filter in the controller i,e in #MessageMapping method.
Could some one tel how can we access the request object in the #MessageMapping method?
When a STOMP client connects to the application, it first has to request a protocol upgrade to switch to websocket. Once using that websocket connection, the messages sent/received don't go through your regular Servlet filter - only the first HTTP request (the "Handshake") did.
Depending on your use case, there are several ways to achieve this.
If it's related to Authentication, then there are existing features for this in the Spring Framework, but also in Spring Security.
If it's related to the HTTP session, you can easily ask for all HTTP session attributes to be copied into the websocket session - or even customize the Handshake for your own needs (see reference doc). Once done, you can inject the Websocket scope in a #MessageMapping controller method and get those attributes (see reference doc).

Spring Integration - HTTP gateway and JMS

I have a requirement where client sends an HTTP requests, our application processes it and generates response and sends back the HTTP response. The request and response need to be persisted on JMS queues. In order for us to leverage Spring integration in this scenario, can we use spring integration HTTP gateways in place of our current MVC controllers ? Would I need separate gateways for each different uri mapping ? Can the HTTP gateway be integrated with JMS channels ? I would appreciate some ideas on the high level architecture using Spring Integration for this scenario.
Thanks.
The fastest on-ramp would probably to inject a Messaging Gateway (<gateway/>) into your existing controller; if you are simply archiving the request/response, you just need a simply gateway method that returns void and in the Spring Integration flow, wire the <gateway/> to a <jms:outbound-channel-adapter/>.

Resources