The Situation: Practicing Data Ingestion in Rails (and Trying to be Async)
So, for reasons that (ahem) may or may not be job-interview-r...
For further actions, you may consider blocking this person and/or reporting abuse
If by chance you still have this project's code available, could you share the configurations you used? I'm trying to use server-sent events, and I can't even duplicate the behavior you demonstrate here (I'm interested in creating an API that pumps out events while waiting for something else to finish, and am only attempting to see the events via curl, to no avail).
Hi Derrell! Here are the repos for the broadcaster and listener, please feel to poke around for the configurations you need:
Broadcaster: github.com/isalevine/rails-data-in...
Listener: github.com/isalevine/rails-data-in...
Let me know if you run into specific issues setting these up and running them, and I'll help as best I can! :)
Many thanks!
It looks like the issue is not in your broadcaster server, but in your listener server.
From the Net::HTTP docs:
So you need to use
response.read_body
and pass a block to it, instead ofresponse.body
in your listener:See the docs: ruby-doc.org/stdlib-2.6.5/libdoc/n...
Hi Ely, great call on this!
response.read_body
is exactly what I was missing. I really appreciate you pointing me to the right place in the docs! :)In the end, here's the listener_controller code I used:
Thank you again!
Hi, Isa. I ran into similar problems like you did. Here's a blog post that explained it well jvns.ca/blog/2021/01/12/day-36--se...
I had to enforce
Last-Modified
header to get SSE to actually stream instead of showing up at once. Hope this helps. Thanks for an awesome article!Maybe it's waiting for the end of the stream? What happens if you open and close the stream each time you generate a character?
That's what I thought too! One of the things I tried was moving the
5.times do
loop outside of thebegin
statement, so that a new SSE is opened and closed once per loop:And fascinatingly, only ONE character is generated and sent now! Whyyyyy Rails, why won't you let me send multiple SSEs?!
That's interesting. Well, at least it confirms it's waiting for the end of the stream to finish receiving. I wonder if the receiver can be somehow switched back into a state of listening for a new connection at that point?
I'm having trouble with this as well ... what version of rails are you using?
Hi Salvador! Both the broadcaster and listener repos (linked below) are using Rails 5.2.3.
Broadcaster: github.com/isalevine/rails-data-in...
Listener: github.com/isalevine/rails-data-in...