Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contiguous stream of data ? #156

Open
journeytosilius opened this issue Jul 30, 2021 · 1 comment
Open

contiguous stream of data ? #156

journeytosilius opened this issue Jul 30, 2021 · 1 comment

Comments

@journeytosilius
Copy link

New to websockets here. I am developing an app that receives a data through a ZMQ socket every second, then processes it and prepares it in JSON format, and my goal was to be able to stream this real time data contiguously serving it through websockets, so a React app can grab it and make visuals with it.

My questions:

  • is it possible to stream JSON data regardless of if a client is connected to the endpoint, and once the client connects, it starts doing something with the data the server is streaming ?
  • can you add multiple / routes, and run them on separate threads ? My goal is to add a / route for each ZMQ socket receiving data, to later stream them on different tabs on the React app.

Thanks !

@mattgodbolt
Copy link
Owner

is it possible to stream JSON data regardless of if a client is connected to the endpoint, and once the client connects, it starts doing something with the data the server is streaming ?

With no clients, there's nothing to stream to. You can write code to buffer those JSON documents though.

can you add multiple / routes, and run them on separate threads ? My goal is to add a / route for each ZMQ socket receiving data, to later stream them on different tabs on the React app.

Not easily. Seasocks is inherently single-threaded, but typically if you have work on other threads you can kick them to the seasocks thread to send.

In similar designs I've used before I end up having a buffer of messages, and then onConnect I send them all to new clients. On a new message I add to the buffer (for later replay), and then loop over all currently connected instances to send to them.

If those messages are generated on another thread I'll use seasocks.execute() to ensure the enqueing/loop over all instances happens on the Seasocks thread, while everything else happens on my other threads.

If I get time I'll try and write an example that does this kind of thing - it's the kind of Seasocks is designed for. (originally, outputting streaming market data from a C++ trading app for visualisation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants