reoxey
reoxey

Reputation: 704

Best way to pass messages between 2 different protocol routes connected to same client

I have a http route /checkout which initiates a workflow process in Zeebe. The checkout route will return 200 response straight-away to calling client. Now, workflow will run for a while. So to push the response back to client after completion, I have a /sse separate route for server-sent events. Here, I will store all the client connection in a global map.

My doubt is how do I find the exact client to send the response back through sse once?

Currently, I thought of using cookie to identify the client. Is there a better way?

Upvotes: 0

Views: 74

Answers (1)

Tourki
Tourki

Reputation: 1774

If you are already using cookies in your app than that's the way to go since the very purpose of cookies is identifying the client, so if you already have that, you should use it.

But if you rely on another authentication mechanism (like JWT), what you could do is using the url as a query.

So in the client instead of

let eventSource = new EventSource("/sse");

Do

let eventSource = new EventSource("/sse?authorization=jwt_token");

In the backend, you would validate that token, extract the Client ID and hit that global map with it to retrieve the corresponding connection.

(PS: instead of a global map, you should use a proper store, like redis, or an embedded key/value store like bbolt)

Upvotes: 1

Related Questions