Search code examples
webeventsqueuemicroservices

Web apps integration with event based services


I am looking for a best practise when connecting a web application (a React single page app for example) with pure event based backend (microservices, ActiveMQ for example).

When I do a GET call from React (which is request response), how do I get the response considering all backend services are event based?

My thoughts are:

  1. Execute the GET command
  2. Have a REST controller service in the backend (request-response) which fires an event and returns back a response that everything went ok
  3. On the client side, the signal is caught, but nothing happens, just keep loading
  4. Event is processed meanwhile in the backend, which fires another "response" event when done, to which (using stickiness or similar approach) the same REST controller listens
  5. The controller sends the actual response to the browser, using websockets (or similar)
  6. Browser gets the response, display the results

I know there are workarounds, but I am looking for the best event-based solution.


Solution

  • Execute the GET command

    That's right

    Have a REST controller service in the backend (request-response) which fires an event and returns back a response that everything went ok

    Yes and you would return a reference ID that client can use to track the progress.

    On the client side, the signal is caught, but nothing happens, just keep loading

    Depends. If you want client to wait then you keep on show loading. If it's a long process then you may not block the user and send the notification later that it's done.

    Event is processed meanwhile in the backend, which fires another "response" event when done, to which (using stickiness or similar approach) the same REST controller listens

    In decoupled architecture every thing is async. Means fire and forget. When you return reference id to client, the controller is done you can't block anything. Client would use that id to check the progress (cache / DB etc). If you are going websocket path then possible controller could notify based on status change.

    you already have the understanding , so it really depends on the workflow you are trying to build.