SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Downloaden Sie, um offline zu lesen
Criando um Instant
Messenger com Rails
        Vinícius Baggio Fuentes
Agenda
• Experimentar: por que ruby e rails?
• Botando a mão na massa
• Trocando idéias com o GoogleTalk
• Juntando tudo: Rails
• Distributed Ruby (DRb)
• Perguntas
Experimentar: por
   que ruby e rails?

• Because we can!
• Rápidos resultados
• Criatividade e liberdade
Experimentar: por
   que ruby e rails?

• Because we can!
• Rápidos resultados
• Criatividade e liberdade
Botando a mão na
      massa (i)

• O que é XMPP/Jabber
Botando a mão na
      massa (i)

• O que é XMPP/Jabber
 • Trocar XMLs via rede
Botando a mão na
      massa (i)

• O que é XMPP/Jabber
 • Trocar XMLs via rede
 • Autenticação e encriptação
Botando a mão na
      massa (i)

• O que é XMPP/Jabber
 • Trocar XMLs via rede
 • Autenticação e encriptação
 • Descentralizado
Botando a mão na
      massa (i)

• O que é XMPP/Jabber
 • Trocar XMLs via rede
 • Autenticação e encriptação
 • Descentralizado
 • Extensível
Botando a mão na
      massa (ii)

• Usos do XMPP
Botando a mão na
      massa (ii)

• Usos do XMPP
 • Conversar
Botando a mão na
      massa (ii)

• Usos do XMPP
 • Conversar
 • Web Services
Botando a mão na
      massa (ii)

• Usos do XMPP
 • Conversar
 • Web Services
 • Robôs ajudantes
Botando a mão na
      massa (ii)

• Usos do XMPP
 • Conversar
 • Web Services
 • Robôs ajudantes
 • Manutenção e deploy
Botando a mão na
     massa (iii)

• XMPP
Botando a mão na
     massa (iii)

• XMPP
 • JID
Botando a mão na
     massa (iii)

• XMPP
 • JID
 • Presence
Botando a mão na
     massa (iii)

• XMPP
 • JID
 • Presence
 • Messages
Botando a mão na
       massa (iii)
                    JID’s:
         vinibaggio@gmail.com/GTalk
•   XMPP
      vinibaggio@vinibaggio.com/Pidgin
    • JID
    • Presence
    • Messages
Botando a mão na
     massa (iii)

• XMPP
 • JID
 • Presence
 • Messages
Botando a mão na
       massa (iii)
         <presence
         from='xxxxx@gmail.com'
         type='unavailable'
•   XMPP
         to='vinibaggio@gmail.com/
    •JID chattyAB9DA217'
         xmlns='jabber:client'/>
    • Presence
    • Messages
Botando a mão na
     massa (iii)

• XMPP
 • JID
 • Presence
 • Messages
Botando a mão na
       massa (iii)
        <message type='chat'
        to='xxxxxxx@gmail.com'
•   XMPPxmlns='jabber:client'>
          <body>Nao fuja!</body>
    •JID </message>
    • Presence
    • Messages
Botando a mão na
     massa (iii)

• XMPP
 • JID
 • Presence
 • Messages
Botando a mão na
     massa (iv)

• XMPP em Ruby:
Botando a mão na
     massa (iv)

• XMPP em Ruby:
 • XMPP4R
Botando a mão na
     massa (iv)

• XMPP em Ruby:
 • XMPP4R
 • XMPP4R::Simple
Botando a mão na
     massa (iv)

• XMPP em Ruby:
 • XMPP4R
 • XMPP4R::Simple
 • Net::XMPP
Trocando idéias com o
     GoogleTalk
Trocando idéias com o
require ‘xmpp4r’
               GoogleTalk
include Jabber
Jabber::debug = true

jid = Jabber::JID.new ‘vinibaggio@gmail.com/Chatty’
password = ‘*******’

client = Jabber::Client.new jid
client.connect ‘talk.google.com’
client.auth password
client.send Presence.new
@clients[email] = client
Trocando idéias com o
require ‘xmpp4r’
                GoogleTalk
include Jabber
           Type:    Status:
Jabber::debug (available)
            nil = true        nil (available)
            :error            :away
jid = Jabber::JID.new ‘vinibaggio@gmail.com/Chatty’
            :probe            :chat
password = ‘*******’
            :subscribe        :dnd
            :subscribed       :xa
client = Jabber::Client.new jid
            :unavailable
client.connect ‘talk.google.com’
            :unsubscribe
client.auth password
            :unsubscribed
client.send Presence.new
@clients[email] = client
Trocando idéias com o
               GoogleTalk
client.add_message_callback do |msg|
 unless msg.type == :error or msg.body.nil?
   push_msg msg
 end
end

client.add_presence_callback do |presence|
  push_presence presence
end
Trocando idéias com o
        GoogleTalk
def push_msg(msg)
 from = msg.from.bare.to_s
 to = msg.to.bare.to_s
 body = msg.body

 new_msg = {:body => body, :from => from}
 @msg_stack[to].push new_msg
end
Trocando idéias com o
               GoogleTalk
def push_presence(presence)
 from = presence.from.bare.to_s
 to = presence.to.bare.to_s
 if presence.type == :unavailable
    status = :unavailable
 else
    status = presence.show || :available
 end
 new_presence = {:status => status, :from => from}
 @presence_stack[to].push new_presence
end
Trocando idéias com o
      GoogleTalk

client.close
Trocando idéias com o
class XMPPConnector
                 GoogleTalk
  include Singleton
  def login(email, password); ...; end;
 def get_presences(jid); ...; end;
 def get_messages(jid); ...; end;
 def send_message(jid, to, msg); ...; end;
 def set_status(jid, status); ...; end;
 def logout(jid); ...; end;
 private
 def check_timeout; ...; end;
 def push_msg(msg); ...; end;
 def push_presence(msg); ...; end;
end
Trocando idéias com o
        GoogleTalk
connector = XMPPConnector.instance
jid = connector.login(‘vinibaggio@gmail.com’, ‘*****’)
msgs = connector.get_messages(jid)
presences = connector.get_presences(jid)
connector.send_message(jid, ‘xxxx@gmail.com’, ‘Oi!’)
connector.set.status(jid, :dnd);
Juntando tudo: Rails

   Acabou a parte do XMPP!
       Vamos pro Rails!!
Juntando tudo: Rails
require ‘xmppconnector’

class MessengerController < ApplicationController
  filter_parameter_logging :password
  def login
      email = params[:email]
      password = params[:password]
      xmpp = XMPPConnector.instance
      session[:jid] = xmpp.login(email, password)
      render :action => ‘chat’
  end
  ...
end
send_msg


check_updates
vinibaggio
vinibaggio

****************
Pergunta fatídica...
Pergunta fatídica...

    Does it scale?
Pergunta fatídica...

    Does it scale?
       Nope.
Tipo de request: Login (Mongrel simples)

                                                         Messenger#login(vinibaggio)
                            MessengerController::login


localhost:3000/login                                                   XMPP Layer
                         Request                                            joao
                                                App Rails
                       dispatcher                                          maria
                                                                       * vinibaggio
localhost:3000/chat
                                 :render => quot;chatquot;              OK
                                                                     mongrel simples
Tipo de request: Login (mod_rails)

                                                          Messenger#login(vinibaggio)
                            MessengerController::login

                                                                        XMPP Layer 1
                                                  Instância
                                                                               joao
                                                   Rails 1                    maria



                                                                        XMPP Layer 2
                                                  Instância
localhost:3000/login
                         Request                                              vitor
                                                   Rails 2                * vinibaggio
                       dispatcher
localhost:3000/chat



                                                                        XMPP Layer 5
                                                  Instância
                                                                              pedro
                                                   Rails 5                    paulo



                                 :render => quot;chatquot;               OK

                                                              mod_rails (Passenger)
Tipo de request: Send_msg (mod_rails)

                                                              Messenger#send_msg(vinibaggio)
                              MessengerController::send_msg

                                                                           XMPP Layer 1
                                                      Instância                   joao
                                                       Rails 1                   maria


                                                                  ERROR
                                                                           XMPP Layer 2
                                                      Instância
localhost:3000/send_msg
                            Request                                               vitor
                                                       Rails 2                 vinibaggio
                          dispatcher
 localhost:3000/timeout
                                   flash[:error] = quot;Invalid
                                        connectionquot;

                                                                           XMPP Layer 5
                                                      Instância
                                                                                 pedro
                                                       Rails 5                   paulo




                                                                  mod_rails (Passenger)
Distributed Ruby!


• Remote Method Invocation (RMI)
• Standard library
• Access Control Lists (ACLs)
require ‘drb’
DRb.start_service ‘druby://localhost:6666’, []
DRb.thread.join


                         Servidor
require ‘drb’
r = DRbObject.new nil, ‘druby://localhost:6666’
while true
  puts r.size
  r << 1
  puts r.size
  sleep 10
end


                        Cliente
A
Tempo
        0
   0s
        1   B
            1
   5s
            2
        2
  10s
        3
            3
  15s
            4
Arquitetura com mod_rails + DRb



                              Instância
                               Rails 1

                                             RemoteXMPP
Requests                      Instância
                                                  joao
               Request         Rails 2           maria
             dispatcher                          pedro
                                                 paulo
Response                                         vitor
                                              vinibaggio




                              Instância
                               Rails 5

                                 mod_rails
require ‘drb’
include ‘xmppconnector’
DRb.start_service ‘druby://localhost:6666’,
              XMPPConnector.instance
DRb.thread.join



                Servidor XMPP + DRb
Rails + DRb
require ‘xmppconnector’

class MessengerController < ApplicationController
  filter_parameter_logging :password
  def login
    ...
  end

 def xmpp
     DRbObject.new nil, ‘druby://localhost:6666’
 end
 ...
end
That’s it!

• Relembrando...
 • Biblioteca XMPP4R para XMPP
 • Rails para fazer a interface
 • Paralelizando a arquitetura
 • Distributed Ruby (DRb)
Obrigado!!!

• Perguntas??
• Contato:
 • vinibaggio@gmail.com
 • www.vinibaggio.com

Weitere ähnliche Inhalte

Ähnlich wie Criando um Instant Messenger

Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
l xf
 
Pentesting111111 Cheat Sheet_OSCP_2023.pdf
Pentesting111111 Cheat Sheet_OSCP_2023.pdfPentesting111111 Cheat Sheet_OSCP_2023.pdf
Pentesting111111 Cheat Sheet_OSCP_2023.pdf
faker1842002
 
Sinatraonpassenger 090419090519 Phpapp01
Sinatraonpassenger 090419090519 Phpapp01Sinatraonpassenger 090419090519 Phpapp01
Sinatraonpassenger 090419090519 Phpapp01
guestcaceba
 

Ähnlich wie Criando um Instant Messenger (14)

XMPP & AMQP in Ruby
XMPP & AMQP in RubyXMPP & AMQP in Ruby
XMPP & AMQP in Ruby
 
Php Security
Php SecurityPhp Security
Php Security
 
Aprendendo solid com exemplos
Aprendendo solid com exemplosAprendendo solid com exemplos
Aprendendo solid com exemplos
 
Messaging With Erlang And Jabber
Messaging With  Erlang And  JabberMessaging With  Erlang And  Jabber
Messaging With Erlang And Jabber
 
RabbitMQ for Perl mongers
RabbitMQ for Perl mongersRabbitMQ for Perl mongers
RabbitMQ for Perl mongers
 
%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs
%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs
%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs
 
Dynomite at Erlang Factory
Dynomite at Erlang FactoryDynomite at Erlang Factory
Dynomite at Erlang Factory
 
Fast & Scalable Front/Back-ends using Ruby, Rails & XMPP
Fast & Scalable Front/Back-ends using Ruby, Rails & XMPPFast & Scalable Front/Back-ends using Ruby, Rails & XMPP
Fast & Scalable Front/Back-ends using Ruby, Rails & XMPP
 
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
 
Sinatra
SinatraSinatra
Sinatra
 
Hack The Box Nest 10.10.10.178
Hack The Box Nest 10.10.10.178Hack The Box Nest 10.10.10.178
Hack The Box Nest 10.10.10.178
 
Pentesting111111 Cheat Sheet_OSCP_2023.pdf
Pentesting111111 Cheat Sheet_OSCP_2023.pdfPentesting111111 Cheat Sheet_OSCP_2023.pdf
Pentesting111111 Cheat Sheet_OSCP_2023.pdf
 
Sinatraonpassenger 090419090519 Phpapp01
Sinatraonpassenger 090419090519 Phpapp01Sinatraonpassenger 090419090519 Phpapp01
Sinatraonpassenger 090419090519 Phpapp01
 
Database Sharding At Netlog
Database Sharding At NetlogDatabase Sharding At Netlog
Database Sharding At Netlog
 

Kürzlich hochgeladen

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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+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@
 

Kürzlich hochgeladen (20)

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
 
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, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"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 ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+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...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Criando um Instant Messenger

  • 1. Criando um Instant Messenger com Rails Vinícius Baggio Fuentes
  • 2. Agenda • Experimentar: por que ruby e rails? • Botando a mão na massa • Trocando idéias com o GoogleTalk • Juntando tudo: Rails • Distributed Ruby (DRb) • Perguntas
  • 3. Experimentar: por que ruby e rails? • Because we can! • Rápidos resultados • Criatividade e liberdade
  • 4. Experimentar: por que ruby e rails? • Because we can! • Rápidos resultados • Criatividade e liberdade
  • 5. Botando a mão na massa (i) • O que é XMPP/Jabber
  • 6. Botando a mão na massa (i) • O que é XMPP/Jabber • Trocar XMLs via rede
  • 7. Botando a mão na massa (i) • O que é XMPP/Jabber • Trocar XMLs via rede • Autenticação e encriptação
  • 8. Botando a mão na massa (i) • O que é XMPP/Jabber • Trocar XMLs via rede • Autenticação e encriptação • Descentralizado
  • 9. Botando a mão na massa (i) • O que é XMPP/Jabber • Trocar XMLs via rede • Autenticação e encriptação • Descentralizado • Extensível
  • 10. Botando a mão na massa (ii) • Usos do XMPP
  • 11. Botando a mão na massa (ii) • Usos do XMPP • Conversar
  • 12. Botando a mão na massa (ii) • Usos do XMPP • Conversar • Web Services
  • 13. Botando a mão na massa (ii) • Usos do XMPP • Conversar • Web Services • Robôs ajudantes
  • 14. Botando a mão na massa (ii) • Usos do XMPP • Conversar • Web Services • Robôs ajudantes • Manutenção e deploy
  • 15. Botando a mão na massa (iii) • XMPP
  • 16. Botando a mão na massa (iii) • XMPP • JID
  • 17. Botando a mão na massa (iii) • XMPP • JID • Presence
  • 18. Botando a mão na massa (iii) • XMPP • JID • Presence • Messages
  • 19. Botando a mão na massa (iii) JID’s: vinibaggio@gmail.com/GTalk • XMPP vinibaggio@vinibaggio.com/Pidgin • JID • Presence • Messages
  • 20. Botando a mão na massa (iii) • XMPP • JID • Presence • Messages
  • 21. Botando a mão na massa (iii) <presence from='xxxxx@gmail.com' type='unavailable' • XMPP to='vinibaggio@gmail.com/ •JID chattyAB9DA217' xmlns='jabber:client'/> • Presence • Messages
  • 22. Botando a mão na massa (iii) • XMPP • JID • Presence • Messages
  • 23. Botando a mão na massa (iii) <message type='chat' to='xxxxxxx@gmail.com' • XMPPxmlns='jabber:client'> <body>Nao fuja!</body> •JID </message> • Presence • Messages
  • 24. Botando a mão na massa (iii) • XMPP • JID • Presence • Messages
  • 25. Botando a mão na massa (iv) • XMPP em Ruby:
  • 26. Botando a mão na massa (iv) • XMPP em Ruby: • XMPP4R
  • 27. Botando a mão na massa (iv) • XMPP em Ruby: • XMPP4R • XMPP4R::Simple
  • 28. Botando a mão na massa (iv) • XMPP em Ruby: • XMPP4R • XMPP4R::Simple • Net::XMPP
  • 29. Trocando idéias com o GoogleTalk
  • 30. Trocando idéias com o require ‘xmpp4r’ GoogleTalk include Jabber Jabber::debug = true jid = Jabber::JID.new ‘vinibaggio@gmail.com/Chatty’ password = ‘*******’ client = Jabber::Client.new jid client.connect ‘talk.google.com’ client.auth password client.send Presence.new @clients[email] = client
  • 31. Trocando idéias com o require ‘xmpp4r’ GoogleTalk include Jabber Type: Status: Jabber::debug (available) nil = true nil (available) :error :away jid = Jabber::JID.new ‘vinibaggio@gmail.com/Chatty’ :probe :chat password = ‘*******’ :subscribe :dnd :subscribed :xa client = Jabber::Client.new jid :unavailable client.connect ‘talk.google.com’ :unsubscribe client.auth password :unsubscribed client.send Presence.new @clients[email] = client
  • 32. Trocando idéias com o GoogleTalk client.add_message_callback do |msg| unless msg.type == :error or msg.body.nil? push_msg msg end end client.add_presence_callback do |presence| push_presence presence end
  • 33. Trocando idéias com o GoogleTalk def push_msg(msg) from = msg.from.bare.to_s to = msg.to.bare.to_s body = msg.body new_msg = {:body => body, :from => from} @msg_stack[to].push new_msg end
  • 34. Trocando idéias com o GoogleTalk def push_presence(presence) from = presence.from.bare.to_s to = presence.to.bare.to_s if presence.type == :unavailable status = :unavailable else status = presence.show || :available end new_presence = {:status => status, :from => from} @presence_stack[to].push new_presence end
  • 35. Trocando idéias com o GoogleTalk client.close
  • 36. Trocando idéias com o class XMPPConnector GoogleTalk include Singleton def login(email, password); ...; end; def get_presences(jid); ...; end; def get_messages(jid); ...; end; def send_message(jid, to, msg); ...; end; def set_status(jid, status); ...; end; def logout(jid); ...; end; private def check_timeout; ...; end; def push_msg(msg); ...; end; def push_presence(msg); ...; end; end
  • 37. Trocando idéias com o GoogleTalk connector = XMPPConnector.instance jid = connector.login(‘vinibaggio@gmail.com’, ‘*****’) msgs = connector.get_messages(jid) presences = connector.get_presences(jid) connector.send_message(jid, ‘xxxx@gmail.com’, ‘Oi!’) connector.set.status(jid, :dnd);
  • 38. Juntando tudo: Rails Acabou a parte do XMPP! Vamos pro Rails!!
  • 39.
  • 40. Juntando tudo: Rails require ‘xmppconnector’ class MessengerController < ApplicationController filter_parameter_logging :password def login email = params[:email] password = params[:password] xmpp = XMPPConnector.instance session[:jid] = xmpp.login(email, password) render :action => ‘chat’ end ... end
  • 42.
  • 45.
  • 46.
  • 48. Pergunta fatídica... Does it scale?
  • 49. Pergunta fatídica... Does it scale? Nope.
  • 50. Tipo de request: Login (Mongrel simples) Messenger#login(vinibaggio) MessengerController::login localhost:3000/login XMPP Layer Request joao App Rails dispatcher maria * vinibaggio localhost:3000/chat :render => quot;chatquot; OK mongrel simples
  • 51. Tipo de request: Login (mod_rails) Messenger#login(vinibaggio) MessengerController::login XMPP Layer 1 Instância joao Rails 1 maria XMPP Layer 2 Instância localhost:3000/login Request vitor Rails 2 * vinibaggio dispatcher localhost:3000/chat XMPP Layer 5 Instância pedro Rails 5 paulo :render => quot;chatquot; OK mod_rails (Passenger)
  • 52. Tipo de request: Send_msg (mod_rails) Messenger#send_msg(vinibaggio) MessengerController::send_msg XMPP Layer 1 Instância joao Rails 1 maria ERROR XMPP Layer 2 Instância localhost:3000/send_msg Request vitor Rails 2 vinibaggio dispatcher localhost:3000/timeout flash[:error] = quot;Invalid connectionquot; XMPP Layer 5 Instância pedro Rails 5 paulo mod_rails (Passenger)
  • 53. Distributed Ruby! • Remote Method Invocation (RMI) • Standard library • Access Control Lists (ACLs)
  • 55. require ‘drb’ r = DRbObject.new nil, ‘druby://localhost:6666’ while true puts r.size r << 1 puts r.size sleep 10 end Cliente
  • 56. A Tempo 0 0s 1 B 1 5s 2 2 10s 3 3 15s 4
  • 57. Arquitetura com mod_rails + DRb Instância Rails 1 RemoteXMPP Requests Instância joao Request Rails 2 maria dispatcher pedro paulo Response vitor vinibaggio Instância Rails 5 mod_rails
  • 58. require ‘drb’ include ‘xmppconnector’ DRb.start_service ‘druby://localhost:6666’, XMPPConnector.instance DRb.thread.join Servidor XMPP + DRb
  • 59. Rails + DRb require ‘xmppconnector’ class MessengerController < ApplicationController filter_parameter_logging :password def login ... end def xmpp DRbObject.new nil, ‘druby://localhost:6666’ end ... end
  • 60. That’s it! • Relembrando... • Biblioteca XMPP4R para XMPP • Rails para fazer a interface • Paralelizando a arquitetura • Distributed Ruby (DRb)
  • 61. Obrigado!!! • Perguntas?? • Contato: • vinibaggio@gmail.com • www.vinibaggio.com