agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
892 stars 48 forks source link

How do I identify which command is the WebSocket message replying to? #367

Closed ratsclub closed 2 months ago

ratsclub commented 7 months ago

I'm trying to write a Deno WebSocket client for M36 but I don't understand how to identify which message is which.

Consider the scenario where you have multiple HTTP requests doing operations on the database, you would end up with multiple commands being sent from the same WebSocket connection. How can I tell the responses apart? Is there a way to send and receive a unique identifier or something else?

agentm commented 7 months ago

Hm, the Haskell API has a SessionId precisely for this use-case but it looks like this API component was not exposed to Websockets. That's clearly an oversight, so we'll need to add this capability to the Websocket API to make this work.

The intention is to allow one Session for each parallel-capable request- Sessions are effectively bound to potential (uncommitted) transactions.

Would that address your use-case?

ratsclub commented 7 months ago

I think that this is exactly what we are looking after!

agentm commented 2 months ago

We've overhauled the websocket API to use tagged JSON objects over the wire. Check out the WebSocket TutorialD Client for an example usage.

This patch enabled createSessionAtHead support as well per request request UUIDs which are roundtripped from the client. Note that request UUIDs are not validated by the server- the client is presumed to reuse request UUIDs.