I got some great advice for putting together my websocket client here: Mixing asynchronous data feed with synchronous program flow control. And it’s working well.
10,000 foot view: I am consuming a stock price stream. This is a paid service that only allows one connection and it is somewhat fragile due to a short timeout period, a dearth of documentation, and no built-in caching/reconnecting. None of my plans breach the user agreement/contract; that’s not me.
I don’t want to write a cache/queue. I want to leave the stream alone and uncluttered with a bunch of synchronous calls that might throw exceptions or otherwise cause trouble; separation of concerns. I also want to test multiple versions of code against the single stream concurrently. I could record and play back data but that’s a pain, a disk hog, and it doesn’t address the fragility/complexity or any possible application of code against live data.
My ideas have been–
- proxy the websocket through nginx so multiple “muted” client connections still only share the single permissible connection to the real service (I’m not sure this is possible without a lot of code and it’s extra plumbing),
- write a websocket server, in Mojo still, around the websocket client that lets an arbitrary number of local clients receive an echo of the master client’s stream,
- write a simple streaming socket server in Perl that runs the websocket client and pushes out to any local socket clients,
- publish the data stream to a local DB (this would be slower than everything else if it’s relational but also perhaps the most reliable with a built-in “cache/queue” only in need of pruning),
- or come beg you guys for what is probably a better idea than I can summon.
So… I guess the last one. :P
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.