websocketstomp

Can I use STOMP for Ajax-like requests?


My web page has a WebSocket connection with STOMP protocol.

I was wondering if I can use this channel with STOMP to send synchronous requests, like to an Ajax call (I know Ajax is considered asynchronous, but I meant it send the request and waits for the answer).

I tried to use STOMP messages, but I cannot easily link requests and responses.


Solution

  • This is a pretty generic question so I'm going to give a pretty generic answer. This is not a "how to."

    You can use STOMP in a request-reply pattern to mimic what you get with Ajax.

    You can link requests and responses together using a correlation ID.

    The specifics here will really depend on the message broker you use, but generally speaking the STOMP protocol is flexible enough to support your use-case.