C
C#6mo ago
reinaldyrfl

✅ Passing realtime data from Worker to ASP.NET Web API

I'm working on a stock broker company, currently working for the stock chart infrastructure. I need to connect to the realtime data feed server via a single TCP socket (the server's using C++), and fan out the stocks data in realtime via WebSocket to the frontend client (which is just static HTML/JS also statically served by ASP.NET Core). One thing that bugs me and the team is: how do we properly transfer the data from the Worker instance to the Web API instance, so that it can be properly being fan out? At first I was thinking of using System.Threading.Channels, but having it as a singleton that used by both the Web API and Worker doesn't makes sense to me, as I suppose the class will be created twice on the Web API and on Worker (or did I got it wrong?). I don't want to add another external infrastructure like using Kafka, Rabbit, or Redis pubsub, I want to avoid more latency. So the questions would be: 1. How do I properly transfer (and possibly fan out) the data being consumed by Worker instance to the ASP.NET Core instance? 2. Is using System.Threading.Channels the best way to achieve this? On other language, I'd use channel in Go and std::sync::mpsc in Rust.
4 Replies
jcotton42
jcotton426mo ago
Is using System.Threading.Channels the best way to achieve this? On other language, I'd use channel in Go and std::sync::mpsc in Rust.
well those are all the same concept
but having it as a singleton that used by both the Web API and Worker doesn't makes sense to me, as I suppose the class will be created twice on the Web API and on Worker (or did I got it wrong?)
if it's registered in the DI container as singleton, the DI container will always return the same instance
reinaldyrfl
reinaldyrfl6mo ago
Got it. I don't think this is possible before, was thinking of migrating to FASTER KV for Pub/Sub case.
jcotton42
jcotton426mo ago
reinaldyrfl
reinaldyrfl6mo ago
Thank you for the guide!
Want results from more Discord servers?
Add your server
More Posts