Real Time Event Dispatcher

25
unconference Real Time Event Dispatcher Pushing symfony events in real time to your clients

description

Pushing symfony events in real time to your clientsThis talk, held at the symfony live Paris unconference, gives an overview about how events thrown in symfony can be dispatched in real time to web clients. It describes the architecture of the solution and provides examples using the open source comet server APE

Transcript of Real Time Event Dispatcher

  • 1. Real Time Event Dispatcher
    • Pushing symfony events
    • in real time
    • to your clients
  • 2. Imagine Games Remember Google Wave? No? Anyone??? Read/Delete a message, all favicons change Your turn? Instant notification GMail Like tail f /var/log/my.log >some.browsers
  • 3. ITS JUST SOOOO COOL!!! You click somewhere and immediately see a response somewhere else... Real Time Event Dispatcher
  • 4. @KaroDidi 1 wife, 2 kids, 3 monitors 34 years Day-Job: Working on Excel/Access VBA Applications :-/ True heart belongs to Web and PHP since >10 Years Own company/Freelancer www.smartpixelmedia.de Real-Life? Ah, right... Mountainbike Model plane/heli Peter Dietrich Real Time Event Dispatcher Hobbies: www.karopapier.de www.xosofox.de www.managerator.de www.tmeet.de www.timini.de www.beididi.de www.jobeet.de / www.symfony2.de www.d1d.li
  • 5. The Big Bicture Some PHP Some data transport Some JS Real Time Event Dispatcher sfBackend APE
  • 6. Real Time Event Dispatcher lib/model APE Custom Event Handler sfEventHandler Browser Browser Browser Throw Event HTTP Request JSON data Process Event Response on long-polling AJAX request Event bubbling through Browser Tab Browser Tab
  • 7. Real-Time?? Really really?
    • Yes, really really! *
    • Because it is not Polling! Data is being pushed!
    Real Time Event Dispatcher * Conditions apply: Network latency, Server load,
  • 8. Polling?
    • Polling is just reverse Spam
    Real Time Event Dispatcher Alexis Richardson http://www.rabbitmq.com/resources/RabbitMQ_Oxford_Geek_Night.pdf (Slide 23) http://www.ape-project.org/comics/1/Chapter-I-common-let-s-push.html
  • 9. AJAX Long Polling
    • POST /longpoll HTTP/1.1
    • .oO(ZZZZZZ) - Wait for data
    • Or close, send data, and wait
    • again
    Real Time Event Dispatcher Server Client 25s 25s POST Data Rx Data
  • 10. Comet Servers
    • APE (AJAX Push Engine, V2 coming, OSS)
    • node.js
    • StreamHub (Community Edition available)
    • Meteor (OSS)
    • Share your alternatives later?
    Real Time Event Dispatcher BTW, your Apache would of course instantly go down...
  • 11. What is APE?
    • www.ape-project.org
    • C, optimised for long-polling
    • Provides Server and Client JS Framework
    • Channels to listen on
    • Internally calls it pipes public and private (=sent to a channel or send to a user)
    Real Time Event Dispatcher http://www.xosofox.de/2010/03/playing-with-my-new-pet-ape/
  • 12. ... Some APE specifics
    • Functionality by itself quite bare
    • Comes with some modules
    • Add Server Side JS
    • getPipeByUser?
    • You need to define your own user session handling to send to username
    Real Time Event Dispatcher http://www.xosofox.de/2010/10/ape-user-handling/
  • 13. Enough! Gimmi code!
    • Sf Event Dispatcher
    Real Time Event Dispatcher Dennis Benkert @denderello #sfLive2010 http://www.slideshare.net/denderello/symfony-live-2010-using-symfony-events-to-create-clean-class-interfaces
  • 14. ... More code
    • Custom Event Handler
    Real Time Event Dispatcher Event Payload Channel Define your payload here!
  • 15. ... Even more Code
    • Call to inline push on APE
    • JSON based
    • Need special commands on the server
    Real Time Event Dispatcher
  • 16. Even more Code Real Time Event Dispatcher Event Payload Channel
  • 17. Server Side JS
    • Example of event dispatching
    Real Time Event Dispatcher Event Payload Channel
  • 18. Gimmi JS
    • Client Side APE_JSF EventHandler
    Real Time Event Dispatcher
  • 19. Gimmi JS
    • Do something
      • Change favicon
      • Add/Remove Elements
      • Redraw Canvas
      • Add to Log
    Real Time Event Dispatcher
  • 20. Some things to consider
    • Auth*ation
    • User-Handling, concurrent tabs?
    • Refresh < -- > Session resume
    • Channels
    • Public?
    • Page-Design
      • Reloads? => Reconnect => new session
      • Persistent overlay
        with iframe? Real Time Event Dispatcher
      • 21. APE Alternatives?
        • node.js (bare)
          • socket.io (tries to find best method, websockets, AJAX, Flash, ...)
        • RabbitMQ?
          • JSONRPC
          • Better ask @old_sound about that
          • RabbitMQ and APE could work together
        Real Time Event Dispatcher
      • 22. Psst... Annoying stuff
        • APE
          • APE Protocol takes some time to grasp
          • Little/confusing docs
          • Performance
        • General:
          • Browser parallel limits
          • Same origin (APEs workaround is *.domain.com)
          • Iframe
          • User/session handling
        Real Time Event Dispatcher
      • 23. Recap
        • Nice interaction between sf backend server, Comet server and Client
        • Interesting, different techniques involved
          • PHP Backend
          • JS Server side
          • JS Client side
        • Just soo cool as soon as it works ;-)
        Real Time Event Dispatcher
      • 24. Further reading
        • Ape-project.org
        • Node.js
        • RabbitMQ
        Real Time Event Dispatcher
      • 25. Theres one more thing
        • Questions?
        • Share your experience
        • If you like it, keep nagging @KaroDidi to release sfRealTimeEventDispatcherPlugin
        Real Time Event Dispatcher ... And please give http://tmeet.de/sflive a try