SlideShare ist ein Scribd-Unternehmen logo
1 von 17
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

Weitere ähnliche Inhalte

Was ist angesagt?

Jabber is more than instant messaging
Jabber is more than instant messagingJabber is more than instant messaging
Jabber is more than instant messaging
Florian Holzhauer
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 

Was ist angesagt? (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
 

Ähnlich wie Real-time Web with Rails and XMPP

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
 
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
SVDevOps
 
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
 
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
martinlippert
 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
 

Ähnlich wie 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)
 
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
 
Ruby projects of interest for DevOps
Ruby projects of interest for DevOpsRuby projects of interest for DevOps
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
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

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

Hinweis der Redaktion

  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