Vaadin + Spring <-> JMS design question

Hi, I have a question on the best way to design the below:

I have a Vaadin-spring-boot application that needs to send / receive messages over JMS to communicate with a legacy Java serverside process, for two main use cases:
(1) The legacy Java process sends out status updates which needs to be shown in all active GUI sessions - a text on a label
(2) The web gui user can send a request object over JMS, and the legacy process replies with a response - but only to the user’s web gui that sent the request.

So in terms of code I have
(a) a class MyGUI extending UI
(b) and a spring bean called LegacyService that contains the methods to send/receive messages over JMS which is autowired into the UI and the UI can call / get a callback from when JMS message is received.

The question is, for requirement (1) since every active session needs to be updated with status messages from the legacy app when its sent a status update, do I have to keep a track of the active UI sessions myself somewhere - e.g. an arraylist in a new component - to cycle through and update when a JMS message is received? how can I check the session is still active, and by keeping a hold of it in the Arraylist it won’t get garbage collected, could be a problem for when users are hammering refresh and every refresh creates a new session?

And for (2), I guess I will have to keep track of which session has made a request to the JMS, and then when we get a response, update that Session only with a response?

Any tips / advise on the above appreciated thanks.

One thing you could try: override the detach() method in your UI class and remove the session from the list / map there. Add a session destroy event (see ) to see that everything gets cleaned up ok.



Normally when you´re listening for JMS messages, it happens in a background thread, so I believe in order to implement (1) you would need to use something like explained in
Vaadin Push
. Take a look at the

Regarding (2), you can implement the request/reply pattern in JMS (
), so you shouldn’t need to keep track of the sender session, as you will obtain the response synchronously.

thanks for the suggestions both of you - they all sound like the things I need to get this working optimally!