eli
eli21h ago

Dynamic KV queue listener removal

It is possible to add listeners dynamically, but it seems impossible to remove them. I am creating listeners dynamically to process incoming messages from incoming WebSocket events. Each WebSocket client has an ID, and I want to create a queue dynamically for each ID when it connects, then process items in each queue sequentially to avoid concurrency issues arising from multiple rapid messages being received from the same client. However, if the connection is lost, I will need to create a new listener with a new WebSocket instance, so it can continue to process messages on the new connection. If I cannot remove the previous listener for this ID, I guess it will keep firing but be unable to send messages with its now stale WebSocket connection. Addding a listener currently returns void, but a convention I've seen is that adding listeners returns a function for removing them later. It seems like a good pattern to me. Would you consider it?
0 Replies
No replies yetBe the first to reply to this messageJoin