We use Google Pub/Sub for event streams which we want consumed by transient websocket clients. What is a good pattern for creating subscriptions and cleaning them up when the client is no longer connected? The main use case is an admin portal where we want to update the display in real-time based on data change events.
Initial thoughts:
- The clients won't reliably clean up after themselves on shutdown, so subscriptions should be cleaned up externally somehow when clients disappear
- Each server node could create a topic subscription on startup and re-broadcast messages to interested clients, but the second part seems sort of like building a new message queue
- In the case of (2), we still have a cleanup problem if nodes crash without deleting their subscription (though much less so than creating a subscription for each websocket client)
Is there a common architecture pattern (or existing project) that solves this problem?