Dhanavenkatesh
Dhanavenkatesh

Reputation: 81

To build spring integration channel as spring websocket doesn't support messaging for non-stomp client

As we are not using stomp for our websocket server, spring doesn't offer message broker framework. My vision is to use spring messaging pub/sub with Redis message store for dev and migrate message broker from Redis to SQS+Dynamo for prod version.

As I exclude (since ios & Android not ready to put stomp client infront due to lack of support) Stomp, spring websocket library doesn't enable pub/sub function as well.

Our Business case example:

Every connected websocket session will initiate request to another microservice (which is a Java websocket client) to get data. My vision is to connect these two service through pub/sub architecture with redis.

  1. Mobile client sends -> "Hi, Is my bill paid?" through websocket.
  2. Websocket server receive this message and pass it to websocket client service through redis pub/sub.
  3. As websocket server and Websocket client are connected via Redi pub/sub. They can exchange messages.
  4. Websocket client will be connected to human agents system via socket and pass "Hi, Is my bill paid?".
  5. The response ("Yes, it is paid.") will be again published to websocket server.
  6. Websocket server will send it back to specific user destination.

Due to business reason we would like to keep 2 services for this use case. Websocket client can connect to customer agent system and its decoupled from our business logic. Our mobile apps will speak to our own websocket server. This gives us a flexibility to add more customization and independent from a specific vendor.

Here is my workaround

  1. Use spring-websocket without stomp to create Websocket server.
  2. Use spring-Integration to create messaging architecture.
  3. Every websocket session is bound to a spring integration channel and send response to user specific destination.
  4. Create a Redis request/response queue for every connection.
  5. Spring integration channel subcribe to redis queue.

As our infrastructure doesn't offer Rabbit MQ support, Redis queue will be replaced by SQS in prod.

Question: Can we create spring integration channels at runtime and bind to specific service or queue? Thought process is to offer one channel per websocket session and delete channel when session ends.

Is there a better alternate solution available in spring integration or spring messaging to execute this use case?

Upvotes: 1

Views: 1620

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

See the Java DSL Dynamic and Runtime Integration Flows.

You can register and destroy sub flows on-demand.

Keep a reference to the dynamically registered flow id and call remove() on the context.

Spring integration has built-in Websocket support based on Spring Framework's foundation.

Upvotes: 1

Related Questions