Git Product home page Git Product logo

Comments (4)

jeremyevans avatar jeremyevans commented on September 23, 2024 3

The streaming plugin handles streaming, and I use it for SSE in one of my apps. I'm using LISTEN in PostgreSQL for updates and a Queue for synchronization. See http://roda.jeremyevans.net/rdoc/classes/Roda/RodaPlugins/Streaming.html for details on the streaming support. Here's a basic idea of what I'm doing:

# outside your Roda.route block
Thread.new do
  DB.listen('channel_name', :loop=>proc{QUEUES.each{|q| q.push('')}}, :timeout=>60) do |_, _, msg|
    QUEUES.each{|q| q.push(msg)}
  end
end

# inside your Roda.route block
r.get "streaming" do
  response['Content-Type'] = 'text/event-stream;charset=UTF-8'
  response['X-Accel-Buffering'] = 'no' # for nginx
  q = Queue.new
  QUEUES.each{|q| q.push('')}
  QUEUES << q
  stream(:loop=>true, :callback=>proc{QUEUES.delete(q)}) do |out|
    out << "data: #{q.pop}\n\n"
  end
end

Note that as this isn't a bug in Roda, per the contribution guidelines, you should probably be asking about it on the ruby-roda Google Group or the IRC channel.

from roda.

tobymao avatar tobymao commented on September 23, 2024 1

This guide helped me, but I couldn't get messages streamed in until i set

response['Transfer-Encoding'] = 'identity'

from roda.

activestylus avatar activestylus commented on September 23, 2024

Thanks for the quick response and duly noted - I wiIl post further queries of this nature in the group.

I continue to be impressed by how many batteries come included in this tiny framework. Bravo!

from roda.

makevoid avatar makevoid commented on September 23, 2024

thanks @tobymao for pointing this out, I had some code that wasn't working anymore on latest Chrome and adding response['Transfer-Encoding'] = 'identity' made it work again! many thanks!

I think someone should probably update Roda's streaming plugin documentation with your note https://github.com/jeremyevans/roda/blob/master/lib/roda/plugins/streaming.rb#L6

The alternative I guess is to provide an example implementation of chunked (default) encoding where apparently you need to pass the size of the chunk in hex and /r/n as separators.

from roda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.