Camel route "to" a specific websocket endpoint

I have several camel routes with mini nests and moorings. I can send a message to all clients connected to websocket, but how to send a message to a specific endpoint. How can I keep a list of all connected clients with client ID as a reference so that I can direct a specific client. Is it possible? Can I specify a dynamic client in the URI?

Or maybe I'm thinking about it wrong, and I need to create themes in active mq and subscribe to them with clients. Does this mean that I create a theme for every websocket client? and direct the message to the desired topic.

At least on the right track here, what examples can you point out? Google did not help.

+4
source share
2 answers

The approach you take depends on how sensitive the customer information is. The disadvantage of one topic with selectors is that anyone can subscribe to a topic without a selector and see all the information for everyone - usually this is not what you want to do.

The best scheme is to use a message distribution mechanism (a set of Camel routes) that act as an intermediary between the websocket clients and the system that creates the messages. This mechanism is responsible for distributing messages from one recipient to target clients. I worked on several banking web interfaces that used a similar scheme.

For this to work, you first generate a separate token / UUID for each user; this is presented to the user when the session is established (usually through some profile / profile message). It is very important that the UUID can be generated as a clientId hash, and not be stored in the database, because it will be used all the time, and you want to make sure that it is quickly developed.

The user then uses this information to connect to specific topics that use this UUID as a suffix. For example, two users who subscribe to the orderConfirmation topic will subscribe to their own version of this topic:

 clientA -> orderConfirmation.71jqsd87162iuhw78162wd7168 clientB -> orderConfirmation.76232hdwe7r23j92irjh291e0d 

To track "presence", your customers should periodically send a heartbeat message containing their clientId on a known topic that your distribution mechanism is listening to. Clients should not subscribe to this topic for reading (see ActiveMQ Security ). The message distribution mechanism must store in memory a data structure that contains the clientId, and the time during which a heartbeat was noticed.

When a message is received by the distribution mechanism, it checks whether the identifier of the client for which it received the message has a live / current session, determines the UUID for the client and broadcasts the message on the relevant topic.

Over time, this will create a large number of topics in your broker that you do not want to hang out when the user leaves. You can configure ActiveMQ to remove them if they have been inactive for some time .

+2
source

You definitely do not want to create a separate endpoint for each client. Subject and subscription with a selector is an elegant way to solve it. I would say the best.

You need a separate topic with which each client will subscribe with a selector similar to where clientId in ('${myClientId}', 'EVERYONE') . Now, when you want to publish a message for a specific client, you set the clientId property to the identifier of that client. If you want to broadcast, you will set it to "EVERYONE"

Hope I understood the problem correctly ...

0
source

Source: https://habr.com/ru/post/1479965/


All Articles