Singleton websocket type instance
Hi, I want to implement MQTT, which acts as a pub/sub service through a hosted broker service. How would I achieve handlign the subscription of said service, as well as registering a listener that can interact with the functions I have defined as server side functions?
8 Replies
national-gold•3mo ago
on the client? or on the server?
some more context would help
extended-salmonOP•3mo ago
Yes, sorry, on the server.
Specifically, a single global instance for the server, not per-request.
national-gold•3mo ago
where do you deploy to?
extended-salmonOP•3mo ago
I'm deploying to Railway
My last-ditch solution would be to not use Tanstack Start at all, and create an in-between basic service that just communicates with the TSS app via HTTP and the broker in the internal network. The downside is that it's now a whole separate service.
national-gold•3mo ago
can't you just lazy init this and then reuse once initialized?
extended-salmonOP•3mo ago
Question is, where do I do the lazy initialization?
national-gold•3mo ago
first time you use it?
extended-salmonOP•3mo ago
I don't call it directly, it just sits there listening for incoming messages.