SlideShare a Scribd company logo
Real-time Web with Rails
and XMPP
Münchner Ruby on Rails User Group, 2010/12/2

Li Cai (ca168168@gmail.com)
founder: reliwa.de
partner & ex-CTO: 16ds.com
Motivation: 16ds.com

• B2B portal and business network for the
  chemical industry
• Market indexes for 30+ bulk chemicals
  based on prices submitted by diverse
  market players
• Real-time multi-party price negotiation
                                 Münchner Ruby on Rails User Group, 2010/12/2
Multi-party price negotiation
•   User self-organized
•   Access control based on organizational structure of the
    company
•   Customizable quotation templates for each product
•   Configurable admission control and protection of sensitive
    data (customer identities, price details, etc.)
•   Different negotiation modes: fixed price, bargaining, bidding,
    moderated bidding
•   Real-world near auctions by utilizing “Counting-Down-
    Hammer”


                                                Münchner Ruby on Rails User Group, 2010/12/2
Server push in Rails
•   Polling: simple (but...)
•   Comet: setup external server for server push (Jetty,
    glassfish, cometd, ErlyComet, node.js, etc.)
•   FlashXML Socket: full-duplex TCP stream socket
    connection (extra work for firewall traversal)
•   XMPP/BOSH: bidirectional streams over HTTP
    connection
•   WebSockets: full-duplex over single TCP socket is
    being standardized by the W3C (HTML5)

                                         Münchner Ruby on Rails User Group, 2010/12/2
XMPP
•   eXtensible Messaging and Presence Protocol
•   Data exchanged over a pair of XML streams
    •   extensibility: very easy to add new features to the protocol
•   XMPP Toolkits
    •   presence
    •   instant messaging
    •   Multi User Chat (XEP-0045)
    •   Publish/Subscribe (XEP-0060)
    •   and many more...


                                                   Münchner Ruby on Rails User Group, 2010/12/2
XMPP
•   BOSH (XEP-0124, XEP-0206)
    •   long-lived bidirectional streams over HTTP connection
    •   hide user credentials by session attachment
    •   many XMPP servers have BOSH connection manager
        build-in
•   XMPP Component (XEP-0114)
    •   stand-alone server process written with whatever
        language you like
    •   easily extend the server with your own application logic


                                                Münchner Ruby on Rails User Group, 2010/12/2
Extend XMPP with our new
features
•   Build multi-party price negotiation on top of MUC
•   Create XMPP account for every user, while hiding the
    credentials by using session attachment
•   Create MUC-rooms on demand, and manage the member
    list by our application
•   Implement an XMPP component to interact with our
    application as well as the clients
•   Extend name space and let our application handle stuffs
•   Configure default settings of the XMPP server for security


                                             Münchner Ruby on Rails User Group, 2010/12/2
Rails and XMPP


                                Application                        Background
  Web Client   HTTP Server
                             Instances (Rails)                     Jobs (Rails)


               BOSH Conn.
                                                 Message Queue
                Manager


                              XMPP Server
               XMPP Server
                              Component




                                                          Münchner Ruby on Rails User Group, 2010/12/2
XMPP servers
•   ejabberd
    •   written in Erlang, well-known for its scalability
    •   http://www.process-one.net/en/ejabberd/
•   Openfire
    •   written in Java, very easy to install and configure
    •   http://www.igniterealtime.org/projects/openfire/
•   Tigase
    •   written in Java
    •   http://www.tigase.org/
•   and much more...


                                                            Münchner Ruby on Rails User Group, 2010/12/2
XMPP libraries - server side
•   xmpp4r
    •   feature-rich, threaded ruby
    •   http://home.gna.org/xmpp4r/
•   blather
    •   lightweight, DSL-style, evented ruby
    •   http://sprsquish.github.com/blather/
•   skates
    •   lightweight, MVC-style, evented ruby
    •   http://skates.rubyforge.org/
•   strophe-ruby
    •   ruby binding for libstrophe, can be run within a Rails-app
    •   https://github.com/yong/stropheruby



                                                                 Münchner Ruby on Rails User Group, 2010/12/2
XMPP libraries - client side
•   strophe.js
    •   JavaScript
    •   http://code.stanziq.com/strophe/
•   xmpp4js
    •   JavaScript
    •   http://xmpp4js.sourceforge.net/
•   XIFF
    •   Flash/ActionScript
    •   http://www.igniterealtime.org/projects/xiff/
•   and many more...


                                                       Münchner Ruby on Rails User Group, 2010/12/2
Example: user submits a bid

XMPP Comp.                                                          User M                   User A                 User B
                    XMPP MUC                        Web App
  (Spider)                                                        (Moderator)             (Participant)          (Participant)



                                                                                  submit bid

                               room_jid, user_jid, [bid]



     groupchat:x.spider_bid.submitted [bid w. public info]

                                                                update bid_list        update bid_list         update bid_list

     private? && msg:x.spider_bid.submitted [bid w. all info]
                                                                update bid_list        update bid_list




                                                                                  Münchner Ruby on Rails User Group, 2010/12/2
Example: user submits a bid

Rails:
# class RoomBid < ActiveRecord:Base

def submit

  # ... authorization check and application level processing ...

  Spider.notify "bid.submitted", {
     :room_jid => room.jid,
     :bid => public_info.to_json
  }).merge(public? ? {} : {
     :private_recipient_jids => [room.moderator.jid, submitter.jid],
     :bid_full => all_info.to_json
  })
end

# class Spider

def notify key, options = {}
  mq.exchange('spider', :type => :topic).publish(Marshal.dump(options), :key => key)
end



                                                                        Münchner Ruby on Rails User Group, 2010/12/2
Example: user submits a bid

XMPP Component:
# handling of the queue event: “bid.submitted”

send_msg do |xml|

  # send broadcast message

  xml.message(:to => options[:room_jid], :from => SPIDER_JID, :type => :groupchat) do
    xml.x :xmlns => NS_SPIDER_BID do
      xml.submitted options[:bid]
    end
  end

  # send private messages

  options[:private_recipient_jids] && options[:private_recipient_jids].each do |jid|
    xml.message(:to => jid, :from => SPIDER_JID, :type => :normal) do
      xml.x :xmlns => NS_SPIDER_BID do
        xml.submitted options[:bid_full], :in => options[:room_jid]
      end
    end
  end
end
                                                                        Münchner Ruby on Rails User Group, 2010/12/2
Example: user submits a bid

Client (with strophe.js):
// broadcast messages

on_broadcast_message: function (message) {

     var from = $(message).attr('from');
     var room = Strophe.getNodeFromJid(from);

     msg = $(message).find("x[xmlns='" + NS.SPIDER_BID + "'] > submitted");
	    if (msg.length > 0) {
	    	   Client.on_bid_submitted(room, JSON.parse(msg.text(), true);
     }

     // other events ...
},

// update local db, render the gui

on_bid_submitted: function (room, bid, broadcasted) {
	   Room.set_bid(room, bid, broadcasted);
	   Renderer.render_bid(room, bid);
},


                                                                         Münchner Ruby on Rails User Group, 2010/12/2
Conclusions

•   Pros:
    •   powerful toolkits for application
    •   server push for free
    •   scalability
    •   transparent for users
•   Cons:
    •   a bit admin work

                                            Münchner Ruby on Rails User Group, 2010/12/2
Demo




       Münchner Ruby on Rails User Group, 2010/12/2

More Related Content

What's hot

gRPC Design and Implementation
gRPC Design and ImplementationgRPC Design and Implementation
gRPC Design and Implementation
Varun Talwar
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
Bruce Snyder
 
HTTP2 and gRPC
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPC
Guo Jing
 
WSO2 ESB Introduction to Inbound Endpoints
WSO2 ESB Introduction to Inbound EndpointsWSO2 ESB Introduction to Inbound Endpoints
WSO2 ESB Introduction to Inbound Endpoints
Isuru Udana
 
Jabber is more than instant messaging
Jabber is more than instant messagingJabber is more than instant messaging
Jabber is more than instant messagingFlorian Holzhauer
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets Cocoa
Robbert
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPC
C4Media
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBoss
JBug Italy
 
gRPC and Microservices
gRPC and MicroservicesgRPC and Microservices
gRPC and Microservices
Jonathan Gomez
 
UltraESB - an introduction
UltraESB - an introductionUltraESB - an introduction
UltraESB - an introduction
AdroitLogic
 
Introduction to REST and JAX-RS
Introduction to REST and JAX-RSIntroduction to REST and JAX-RS
Introduction to REST and JAX-RS
Ted Pennings
 
Crash course to the Apache Camel
Crash course to the Apache CamelCrash course to the Apache Camel
Crash course to the Apache Camel
Henryk Konsek
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
Hiroshi SHIBATA
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
rockyjaiswal
 
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
AboutYouGmbH
 
gRPC - RPC rebirth?
gRPC - RPC rebirth?gRPC - RPC rebirth?
gRPC - RPC rebirth?
Luís Barbosa
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
Hiroshi SHIBATA
 
Work WIth Redis and Perl
Work WIth Redis and PerlWork WIth Redis and Perl
Work WIth Redis and Perl
Brett Estrade
 

What's hot (20)

gRPC Design and Implementation
gRPC Design and ImplementationgRPC Design and Implementation
gRPC Design and Implementation
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
HTTP2 and gRPC
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPC
 
WSO2 ESB Introduction to Inbound Endpoints
WSO2 ESB Introduction to Inbound EndpointsWSO2 ESB Introduction to Inbound Endpoints
WSO2 ESB Introduction to Inbound Endpoints
 
Jabber is more than instant messaging
Jabber is more than instant messagingJabber is more than instant messaging
Jabber is more than instant messaging
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets Cocoa
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPC
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Camel and JBoss
Camel and JBossCamel and JBoss
Camel and JBoss
 
gRPC and Microservices
gRPC and MicroservicesgRPC and Microservices
gRPC and Microservices
 
UltraESB - an introduction
UltraESB - an introductionUltraESB - an introduction
UltraESB - an introduction
 
Introduction to REST and JAX-RS
Introduction to REST and JAX-RSIntroduction to REST and JAX-RS
Introduction to REST and JAX-RS
 
Crash course to the Apache Camel
Crash course to the Apache CamelCrash course to the Apache Camel
Crash course to the Apache Camel
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
 
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t... Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
 
gRPC - RPC rebirth?
gRPC - RPC rebirth?gRPC - RPC rebirth?
gRPC - RPC rebirth?
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
PHP-GTK
PHP-GTKPHP-GTK
PHP-GTK
 
Work WIth Redis and Perl
Work WIth Redis and PerlWork WIth Redis and Perl
Work WIth Redis and Perl
 

Similar to Real-time Web with Rails and XMPP

Real time Web Application with XMPP and Wave
Real time Web Application with XMPP and WaveReal time Web Application with XMPP and Wave
Real time Web Application with XMPP and Wave
Mickaël Rémond
 
Chat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIPChat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIP
Genora Infotech
 
Micro on NATS - Microservices with Messaging
Micro on NATS - Microservices with MessagingMicro on NATS - Microservices with Messaging
Micro on NATS - Microservices with Messaging
Apcera
 
Ruby Microservices with RabbitMQ
Ruby Microservices with RabbitMQRuby Microservices with RabbitMQ
Ruby Microservices with RabbitMQ
Zoran Majstorovic
 
Construyendo un nuevo ecosistema para comunicaciones interoperables
Construyendo un nuevo ecosistema para comunicaciones interoperablesConstruyendo un nuevo ecosistema para comunicaciones interoperables
Construyendo un nuevo ecosistema para comunicaciones interoperables
OpenDireito
 
Building a new ecosystem for interoperable communications
Building a new ecosystem for interoperable communicationsBuilding a new ecosystem for interoperable communications
Building a new ecosystem for interoperable communications
PaloSanto Solutions
 
ROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor HelicoptersROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor Helicopters
Atılay Mayadağ
 
Staying on Topic - Invoke OpenFaaS functions with Kafka
Staying on Topic - Invoke OpenFaaS functions with KafkaStaying on Topic - Invoke OpenFaaS functions with Kafka
Staying on Topic - Invoke OpenFaaS functions with Kafka
Richard Gee
 
A vision for ejabberd - ejabberd SF Meetup
A vision for ejabberd - ejabberd SF MeetupA vision for ejabberd - ejabberd SF Meetup
A vision for ejabberd - ejabberd SF Meetup
Mickaël Rémond
 
Cloud Foundry Open Tour China (english)
Cloud Foundry Open Tour China (english)Cloud Foundry Open Tour China (english)
Cloud Foundry Open Tour China (english)marklucovsky
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOpsRicardo Sanchez
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsSVDevOps
 
micro-ROS: bringing ROS 2 to MCUs
micro-ROS: bringing ROS 2 to MCUsmicro-ROS: bringing ROS 2 to MCUs
micro-ROS: bringing ROS 2 to MCUs
eProsima
 
Jax2013 PaaS-Parade - Part 1: Cloud Foundry
Jax2013 PaaS-Parade - Part 1: Cloud FoundryJax2013 PaaS-Parade - Part 1: Cloud Foundry
Jax2013 PaaS-Parade - Part 1: Cloud Foundrymartinlippert
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
Timur Safin
 
Building Hopsworks, a cloud-native managed feature store for machine learning
Building Hopsworks, a cloud-native managed feature store for machine learning Building Hopsworks, a cloud-native managed feature store for machine learning
Building Hopsworks, a cloud-native managed feature store for machine learning
Jim Dowling
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and RailsWen-Tien Chang
 
Node.js scaling in highload
Node.js scaling in highloadNode.js scaling in highload
Node.js scaling in highload
Timur Shemsedinov
 
OneTeam Media Server
OneTeam Media ServerOneTeam Media Server
OneTeam Media Server
Mickaël Rémond
 

Similar to Real-time Web with Rails and XMPP (20)

Real time Web Application with XMPP and Wave
Real time Web Application with XMPP and WaveReal time Web Application with XMPP and Wave
Real time Web Application with XMPP and Wave
 
Chat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIPChat app case study - xmpp vs SIP
Chat app case study - xmpp vs SIP
 
Micro on NATS - Microservices with Messaging
Micro on NATS - Microservices with MessagingMicro on NATS - Microservices with Messaging
Micro on NATS - Microservices with Messaging
 
Node.js
Node.jsNode.js
Node.js
 
Ruby Microservices with RabbitMQ
Ruby Microservices with RabbitMQRuby Microservices with RabbitMQ
Ruby Microservices with RabbitMQ
 
Construyendo un nuevo ecosistema para comunicaciones interoperables
Construyendo un nuevo ecosistema para comunicaciones interoperablesConstruyendo un nuevo ecosistema para comunicaciones interoperables
Construyendo un nuevo ecosistema para comunicaciones interoperables
 
Building a new ecosystem for interoperable communications
Building a new ecosystem for interoperable communicationsBuilding a new ecosystem for interoperable communications
Building a new ecosystem for interoperable communications
 
ROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor HelicoptersROS Based Programming and Visualization of Quadrotor Helicopters
ROS Based Programming and Visualization of Quadrotor Helicopters
 
Staying on Topic - Invoke OpenFaaS functions with Kafka
Staying on Topic - Invoke OpenFaaS functions with KafkaStaying on Topic - Invoke OpenFaaS functions with Kafka
Staying on Topic - Invoke OpenFaaS functions with Kafka
 
A vision for ejabberd - ejabberd SF Meetup
A vision for ejabberd - ejabberd SF MeetupA vision for ejabberd - ejabberd SF Meetup
A vision for ejabberd - ejabberd SF Meetup
 
Cloud Foundry Open Tour China (english)
Cloud Foundry Open Tour China (english)Cloud Foundry Open Tour China (english)
Cloud Foundry Open Tour China (english)
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
Ruby projects of interest for DevOps
 
Ricardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devopsRicardo Sanchez - Ruby projects of interest for devops
Ricardo Sanchez - Ruby projects of interest for devops
 
micro-ROS: bringing ROS 2 to MCUs
micro-ROS: bringing ROS 2 to MCUsmicro-ROS: bringing ROS 2 to MCUs
micro-ROS: bringing ROS 2 to MCUs
 
Jax2013 PaaS-Parade - Part 1: Cloud Foundry
Jax2013 PaaS-Parade - Part 1: Cloud FoundryJax2013 PaaS-Parade - Part 1: Cloud Foundry
Jax2013 PaaS-Parade - Part 1: Cloud Foundry
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
Building Hopsworks, a cloud-native managed feature store for machine learning
Building Hopsworks, a cloud-native managed feature store for machine learning Building Hopsworks, a cloud-native managed feature store for machine learning
Building Hopsworks, a cloud-native managed feature store for machine learning
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
 
Node.js scaling in highload
Node.js scaling in highloadNode.js scaling in highload
Node.js scaling in highload
 
OneTeam Media Server
OneTeam Media ServerOneTeam Media Server
OneTeam Media Server
 

Recently uploaded

IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 

Recently uploaded (20)

IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 

Real-time Web with Rails and XMPP

  • 1. Real-time Web with Rails and XMPP Münchner Ruby on Rails User Group, 2010/12/2 Li Cai (ca168168@gmail.com) founder: reliwa.de partner & ex-CTO: 16ds.com
  • 2. Motivation: 16ds.com • B2B portal and business network for the chemical industry • Market indexes for 30+ bulk chemicals based on prices submitted by diverse market players • Real-time multi-party price negotiation Münchner Ruby on Rails User Group, 2010/12/2
  • 3. Multi-party price negotiation • User self-organized • Access control based on organizational structure of the company • Customizable quotation templates for each product • Configurable admission control and protection of sensitive data (customer identities, price details, etc.) • Different negotiation modes: fixed price, bargaining, bidding, moderated bidding • Real-world near auctions by utilizing “Counting-Down- Hammer” Münchner Ruby on Rails User Group, 2010/12/2
  • 4. Server push in Rails • Polling: simple (but...) • Comet: setup external server for server push (Jetty, glassfish, cometd, ErlyComet, node.js, etc.) • FlashXML Socket: full-duplex TCP stream socket connection (extra work for firewall traversal) • XMPP/BOSH: bidirectional streams over HTTP connection • WebSockets: full-duplex over single TCP socket is being standardized by the W3C (HTML5) Münchner Ruby on Rails User Group, 2010/12/2
  • 5. XMPP • eXtensible Messaging and Presence Protocol • Data exchanged over a pair of XML streams • extensibility: very easy to add new features to the protocol • XMPP Toolkits • presence • instant messaging • Multi User Chat (XEP-0045) • Publish/Subscribe (XEP-0060) • and many more... Münchner Ruby on Rails User Group, 2010/12/2
  • 6. XMPP • BOSH (XEP-0124, XEP-0206) • long-lived bidirectional streams over HTTP connection • hide user credentials by session attachment • many XMPP servers have BOSH connection manager build-in • XMPP Component (XEP-0114) • stand-alone server process written with whatever language you like • easily extend the server with your own application logic Münchner Ruby on Rails User Group, 2010/12/2
  • 7. Extend XMPP with our new features • Build multi-party price negotiation on top of MUC • Create XMPP account for every user, while hiding the credentials by using session attachment • Create MUC-rooms on demand, and manage the member list by our application • Implement an XMPP component to interact with our application as well as the clients • Extend name space and let our application handle stuffs • Configure default settings of the XMPP server for security Münchner Ruby on Rails User Group, 2010/12/2
  • 8. Rails and XMPP Application Background Web Client HTTP Server Instances (Rails) Jobs (Rails) BOSH Conn. Message Queue Manager XMPP Server XMPP Server Component Münchner Ruby on Rails User Group, 2010/12/2
  • 9. XMPP servers • ejabberd • written in Erlang, well-known for its scalability • http://www.process-one.net/en/ejabberd/ • Openfire • written in Java, very easy to install and configure • http://www.igniterealtime.org/projects/openfire/ • Tigase • written in Java • http://www.tigase.org/ • and much more... Münchner Ruby on Rails User Group, 2010/12/2
  • 10. XMPP libraries - server side • xmpp4r • feature-rich, threaded ruby • http://home.gna.org/xmpp4r/ • blather • lightweight, DSL-style, evented ruby • http://sprsquish.github.com/blather/ • skates • lightweight, MVC-style, evented ruby • http://skates.rubyforge.org/ • strophe-ruby • ruby binding for libstrophe, can be run within a Rails-app • https://github.com/yong/stropheruby Münchner Ruby on Rails User Group, 2010/12/2
  • 11. XMPP libraries - client side • strophe.js • JavaScript • http://code.stanziq.com/strophe/ • xmpp4js • JavaScript • http://xmpp4js.sourceforge.net/ • XIFF • Flash/ActionScript • http://www.igniterealtime.org/projects/xiff/ • and many more... Münchner Ruby on Rails User Group, 2010/12/2
  • 12. Example: user submits a bid XMPP Comp. User M User A User B XMPP MUC Web App (Spider) (Moderator) (Participant) (Participant) submit bid room_jid, user_jid, [bid] groupchat:x.spider_bid.submitted [bid w. public info] update bid_list update bid_list update bid_list private? && msg:x.spider_bid.submitted [bid w. all info] update bid_list update bid_list Münchner Ruby on Rails User Group, 2010/12/2
  • 13. Example: user submits a bid Rails: # class RoomBid < ActiveRecord:Base def submit # ... authorization check and application level processing ... Spider.notify "bid.submitted", { :room_jid => room.jid, :bid => public_info.to_json }).merge(public? ? {} : { :private_recipient_jids => [room.moderator.jid, submitter.jid], :bid_full => all_info.to_json }) end # class Spider def notify key, options = {} mq.exchange('spider', :type => :topic).publish(Marshal.dump(options), :key => key) end Münchner Ruby on Rails User Group, 2010/12/2
  • 14. Example: user submits a bid XMPP Component: # handling of the queue event: “bid.submitted” send_msg do |xml| # send broadcast message xml.message(:to => options[:room_jid], :from => SPIDER_JID, :type => :groupchat) do xml.x :xmlns => NS_SPIDER_BID do xml.submitted options[:bid] end end # send private messages options[:private_recipient_jids] && options[:private_recipient_jids].each do |jid| xml.message(:to => jid, :from => SPIDER_JID, :type => :normal) do xml.x :xmlns => NS_SPIDER_BID do xml.submitted options[:bid_full], :in => options[:room_jid] end end end end Münchner Ruby on Rails User Group, 2010/12/2
  • 15. Example: user submits a bid Client (with strophe.js): // broadcast messages on_broadcast_message: function (message) { var from = $(message).attr('from'); var room = Strophe.getNodeFromJid(from); msg = $(message).find("x[xmlns='" + NS.SPIDER_BID + "'] > submitted"); if (msg.length > 0) { Client.on_bid_submitted(room, JSON.parse(msg.text(), true); } // other events ... }, // update local db, render the gui on_bid_submitted: function (room, bid, broadcasted) { Room.set_bid(room, bid, broadcasted); Renderer.render_bid(room, bid); }, Münchner Ruby on Rails User Group, 2010/12/2
  • 16. Conclusions • Pros: • powerful toolkits for application • server push for free • scalability • transparent for users • Cons: • a bit admin work Münchner Ruby on Rails User Group, 2010/12/2
  • 17. Demo Münchner Ruby on Rails User Group, 2010/12/2

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n