SlideShare ist ein Scribd-Unternehmen logo
1 von 110
Downloaden Sie, um offline zu lesen
Toby Crawley
                                     Raleigh.rb
Creative  Commons  BY-­SA  3.0
                                     April 2011
whoami

• @tcrawley
• C  >  Java  >  PHP  >  Java  >  Ruby  >  
  Java?
• Red  Hat  Senior  Engineer  
• member  of
Goal

To  have  you  downloading  
TorqueBox  right  after  this  
talk.
TorqueBox
the power of JBoss with the expressiveness of Ruby
TorqueBox:  what?

• A  “real”  app  server  for  Ruby
• Founded  in  2008
• 100%  open-­source,  LGPL  license
• Based  on  JBoss  AS  and  JRuby
• Just  released  1.0.0.CR1!
Yes,  it's  Java
I  promise...

• No  XML  
• No  Java  *
• No  war  files  *
• Only  Ruby  and  YAML
* Unless you really want to
TorqueBox:  why?
 • “Native”  support  for  Rack  apps
 • Built-­in:  
  • background  processing
  • scheduling
  • daemons  (services)
  • clustering
 • Easily  scalable
 • Optionally  enterprisey
JRuby
a good idea done well
JRuby:  why?

• Very  fast  runtime
• Real  threads
• Java  libraries
• Java  tools
• Healthy  community
JBoss  AS
the good parts
The  Competition

Unicorn,  Thin,  Passenger,  
Trinidad,  Warbler...

...all  address  only  the  web  
question.
AS  =  Application  Server

• Not  just  “web  server  +  interpreter”
• More  like  initd  than  httpd
• Can  host  multiple,  disparate  apps  
  simultaneously
• Provides  basic  services  to  all  the  
  apps  it  hosts
JBoss  AS6

• Tomcat  for  web
• Infinispan  for  caching
• HornetQ  for  messaging
• Quartz  for  scheduling
• PicketBox  for  authentication
• mod_cluster  for  clustering
Setting  Up  TorqueBox
      in 3 easy steps!
Easy  Install
(download  1.0.0.CR1  from  torquebox.org)

$  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip

$  export  TORQUEBOX_HOME=$PWD/torquebox-­1*
$  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss
$  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby

$  export  PATH=$JRUBY_HOME/bin:$PATH
Easy  Install
(download  1.0.0.CR1  from  torquebox.org)

$  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip

$  export  TORQUEBOX_HOME=$PWD/torquebox-­1*
$  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss
$  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby

$  export  PATH=$JRUBY_HOME/bin:$PATH
Easy  Install
(download  1.0.0.CR1  from  torquebox.org)

$  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip

$  export  TORQUEBOX_HOME=$PWD/torquebox-­1*
$  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss
$  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby

$  export  PATH=$JRUBY_HOME/bin:$PATH
Easy  Install
(download  1.0.0.CR1  from  torquebox.org)

$  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip

$  export  TORQUEBOX_HOME=$PWD/torquebox-­1*
$  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss
$  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby

$  export  PATH=$JRUBY_HOME/bin:$PATH
Easy  Install
(download  1.0.0.CR1  from  torquebox.org)

$  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip
                               Make  sure  the  jruby  
                             found  in  your  path  is  in  
$  export  TORQUEBOX_HOME=$PWD/torquebox-­1*
                              $JRUBY_HOME/bin.
$  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss
$  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby

$  export  PATH=$JRUBY_HOME/bin:$PATH
Easy  Install
(download  1.0.0.CR1  from  torquebox.org)

$  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip
                               Make  sure  the  jruby  
                             found  in  your  path  is  in  
$  export  TORQUEBOX_HOME=$PWD/torquebox-­1*
                              $JRUBY_HOME/bin.
$  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss
$  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby

$  export  PATH=$JRUBY_HOME/bin:$PATH
Easy  Install


$  jruby  -­S  gem  install  bundler
$  jruby  -­S  gem  install  rails
$  jruby  -­S  gem  install  sinatra
Rake  Tasks
Rakefile




require  "torquebox-­rake-­support"
Database  Connectivity
Gemfile



gem  "activerecord-­jdbc-­adapter"

gem  "jdbc-­postgres"
#  gem  "jdbc-­sqlite3"
#  gem  "jdbc-­mysql"
Rails  Template

• Adds  TorqueBox  rake  tasks
• Adds  the  JDBC  sqlite3  gems
• Adds  TorqueBox  session_store
• Adds  Backgroundable  module
Rake  Tasks

rake  torquebox:run
        Run  TorqueBox  server

rake  torquebox:deploy[context_path]
        Deploy  the  app  in  the  current  directory

rake  torquebox:undeploy
        Undeploy  the  app  in  the  current  directory
Rake  Tasks

Start  torquebox:run  in  its  own  
shell  and  leave  it  running.  Instead  
of  script/server  or  shotgun  
or  thin  or  whatever  else,  
use  torquebox:deploy.
Deployment  Descriptors


 torquebox:deploy  creates  
 a  deployment  descriptor  in  the  
 $TORQUEBOX_HOME/apps/  
 directory
Hot  Deployment
    $TORQUEBOX_HOME/apps/

•   anything  added  to  apps/  
    will  get  deployed
•   anything  removed  from  
    apps/  will  get  undeployed
•   anything  updated  in  apps/  
    will  get  redeployed
•   TorqueBox  deployers  
    make  JBoss  grok  YAML  
    and  ruby  archives
Hot  Deployment
    $TORQUEBOX_HOME/apps/
    deployment  
     descriptors
•   anything  added  to  apps/  
    will  get  deployed
•   anything  removed  from  
    apps/  will  get  undeployed
•   anything  updated  in  apps/  
    will  get  redeployed
•   TorqueBox  deployers  
    make  JBoss  grok  YAML  
    and  ruby  archives
Hot  Deployment
    $TORQUEBOX_HOME/apps/
    deployment  
     descriptors
•   anything  added  to  apps/  
    will  get  deployed
•   anything  removed  from  
    apps/  will  get  undeployed
•   anything  updated  in  apps/  
    will  get  redeployed
•   TorqueBox  deployers  
    make  JBoss  grok  YAML  
    and  ruby  archives
Hot  Deployment
    $TORQUEBOX_HOME/apps/

•   anything  added  to  apps/  
    will  get  deployed
•   anything  removed  from  
    apps/  will  get  undeployed
knob  files  (zip  
• anything  updated  in  apps/  
  archives)
  will  get  redeployed
•   TorqueBox  deployers  
    make  JBoss  grok  YAML  
    and  ruby  archives
Hot  Deployment
    $TORQUEBOX_HOME/apps/

•   anything  added  to  apps/  
    will  get  deployed
•   anything  removed  from  
    apps/  will  get  undeployed
knob  files  (zip  
• anything  updated  in  apps/  
  archives)
  will  get  redeployed
•   TorqueBox  deployers  
    make  JBoss  grok  YAML  
    and  ruby  archives
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp
  env:     development
web:
  context: myapp
  host:    www.yourhost.com
  static: public
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp
  env:     development
web:                      The  fully-­qualified  
  context: myapp
  host:    www.yourhost.com
                            path  to  the  app.    
  static: public         This  will  be  the  value  
environment:                    of  either  
                           RAILS_ROOT  or  
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com RACK_ROOT
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp
  env:     development
web:                      The  fully-­qualified  
  context: myapp
  host:    www.yourhost.com
                            path  to  the  app.    
  static: public         This  will  be  the  value  
environment:                    of  either  
                           RAILS_ROOT  or  
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com RACK_ROOT
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp
  env:     development
web:
  context: myapp         The  runtime  mode  of  
  host:    www.yourhost.com
  static: public
                          the  app.    This  will  be  
environment:               either  RAILS_ENV  
                             or  RACK_ENV
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp
  env:     development
web:
  context: myapp         The  runtime  mode  of  
  host:    www.yourhost.com
  static: public
                          the  app.    This  will  be  
environment:               either  RAILS_ENV  
                             or  RACK_ENV
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
                      The  app’s  context  path  
 apps/myapp-­knob.yml (or  “sub  URI”):
                 http://localhost:8080/myapp
application:            Can  be  set  via  rake:
  root:         rake  torquebox:deploy[myapp]
           /path/to/myapp
  env:     development The  default  is  root:
web:               http://localhost:8080/
  context: myapp
  host:    www.yourhost.com
  static: public
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
                      The  app’s  context  path  
 apps/myapp-­knob.yml (or  “sub  URI”):
                 http://localhost:8080/myapp
application:            Can  be  set  via  rake:
  root:         rake  torquebox:deploy[myapp]
           /path/to/myapp
  env:     development The  default  is  root:
web:               http://localhost:8080/
  context: myapp
  host:    www.yourhost.com
  static: public
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
                             A  list  of  virtual  
  root:    /path/to/myapp
  env:     development
                          hostnames  to  which  
web:                        to  bind  the  app.
  context: myapp
  host:    www.yourhost.com
  static: public
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
                             A  list  of  virtual  
  root:    /path/to/myapp
  env:     development
                          hostnames  to  which  
web:                        to  bind  the  app.
  context: myapp
  host:    www.yourhost.com
  static: public
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp
  env:     development      The  location  of  the  
web:                             app’s  static  
  context: myapp              content,  either  
  host:    www.yourhost.com
                            absolute  or  relative  
  static: public
environment:                 to  the  app’s  root.
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp
  env:     development      The  location  of  the  
web:                             app’s  static  
  context: myapp              content,  either  
  host:    www.yourhost.com
                            absolute  or  relative  
  static: public
environment:                 to  the  app’s  root.
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp Any  environment  
  env:     development
web:                     variables  required  
  context: myapp            by  the  app.
  host:    www.yourhost.com
  static: public
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors
apps/myapp-­knob.yml

application:
  root:    /path/to/myapp Any  environment  
  env:     development
web:                     variables  required  
  context: myapp            by  the  app.
  host:    www.yourhost.com
  static: public
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com
Deployment  Descriptors

•   config/torquebox.yml  
•   internal  descriptors  have  the  
    same  structure  as  the  
    external  ones  in  apps/
•   may  be  used  to  provide  your  
    own  reasonable  defaults
Components
Put 'em together, and you have an AS
Web
make rack, not war
jruby-­rack
• All  rack-­based  frameworks  
  supported:  rails,  sinatra,  etc
• No  packaging  required:  apps  deploy  
  from  where  they  sit  on  disk
• No  redeploy  necessary  to  see  
  changes  when  using  rack  reloading  
    or  rails  development  mode
•   We  use  it  inside  Tomcat
Scheduling
get regular later
Jobs
app/jobs/newsletter_sender.rb

class  NewsletterSender
  
    def  run()
        subscriptions  =  Subscription.find(:all)
        subscriptions.each  do  |e|
            send_newsletter(  e  )
        end
    end
  
end
Jobs
config/torquebox.yml

jobs:
    monthly_newsletter:
        description:  first  of  month
        job:  NewsletterSender
        cron:  ‘0  0  0  1  *  ?’
    
    process_tps_reports:
        job:  TPSReportProcessor
        cron:  ‘0  0  0  0  MON  ?’
Jobs
• More  portable.  What  is  the  first  day  
  of  the  week  on  BSD  again?    What’s  
    cron  on  Windows?
•   Self  contained  within  the  app.    No  
    external  systems  to  manage  and  
    keep  in  sync.
•   Full  application  environment  loaded  
    and  available.
Messaging
 asynchronicity
TorqueBox::Messaging


• JMS  (Java  Message  Service)  
  is  an  API  for  messaging
• implementation
  HornetQ  is  the  JBoss  JMS  
Background  Processing



• Tasks
• Backgroundable  methods
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  Person.find_by_id(payload[:id])
        person.send_welcome_spam  if  person
    end
end
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  Person.find_by_id(payload[:id])
        person.send_welcome_spam  if  person
    end
end
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  Person.find_by_id(payload[:id])
        person.send_welcome_spam  if  person
    end
end
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  Person.find_by_id(payload[:id])
        person.send_welcome_spam  if  person
    end
end
Tasks
app/controllers/people_controller.rb


class  PeopleController  <  ApplicationController
    def  create
        @person  =  Person.new(params[:person])
        respond_to  do  |format|
            if  @person.save
                EmailTask.async(:welcome,  :id  =>  person.id)
                #  respond  appropriately
            end
        end
    end
end
Tasks
app/controllers/people_controller.rb


class  PeopleController  <  ApplicationController
    def  create
        @person  =  Person.new(params[:person])
        respond_to  do  |format|
            if  @person.save
                EmailTask.async(:welcome,  :id  =>  person.id)
                #  respond  appropriately
            end
        end
    end
end
Backgroundable

Inspired  by  DelayedJob’s  
handle_asynchronously,  
it’s  trivial  to  create  implicit  
background  Tasks.
Backgroundable
lib/something.rb

include  TorqueBox::Messaging  

class  Something
    include  Backgroundable
    always_background  :foo
    def  foo;;  end
    def  bar;;  end
end
...
@something.foo
@something.background.bar
Backgroundable
lib/something.rb

include  TorqueBox::Messaging  

class  Something
    include  Backgroundable
    always_background  :foo
    def  foo;;  end
    def  bar;;  end
end
...
@something.foo
@something.background.bar
Backgroundable
lib/something.rb

include  TorqueBox::Messaging  

class  Something
    include  Backgroundable
    always_background  :foo
    def  foo;;  end
    def  bar;;  end
end
...
@something.foo
@something.background.bar
Backgroundable
lib/something.rb

include  TorqueBox::Messaging  

class  Something
    include  Backgroundable
    always_background  :foo
    def  foo;;  end
    def  bar;;  end
end
...
@something.foo
@something.background.bar
Background  Processing

 Call  it  from  your  
 controllers,  models,  and  
 observers,  or  even  other  
 tasks.  Even  in  non-­Rails  
 apps!
Background  Procssing
• No  extra  tables  in  your  database
• No  external  system  to  manage
• Little  to  no  config  required  at  all
• System  gets  redeployed  w/app
• Efficient  loading  of  rails  environment
• Automatic  load  balancing  and  retries
• Works  on  Windows,  if  you  care
Queues
Tasks  and  Backgroundable  are  
built  on  top  of  Queues.    Of  
course,  you  may  build  your  
own  messaging  based  apps  by  
defining  your  own  Queues,  
Topics,  and  their  message  
Processors  yourself.
Queues
config/torquebox.yml

queues:
    /queues/questions:

    /queues/answers:
        durable:  false
Topics

• behavior  is  different,  but  interface  is  
  the  same.
• all  subscribers  of  a  topic  see  each  
  message,  but  only  one  subscriber  
    will  see  any  message  from  a  queue  
•   use  topics:  section  of  
    torquebox.yml  to  define  topics
Processors

You  can  create  a  processor  
class  to  receive  messages  
from  a  Topic  or  Queue
Processors
app/models/print_handler.rb

include  TorqueBox::Messaging

class  PrintHandler  <  MessageProcessor
    def  initialize(opts)
        @printer  =  opts['printer']  ||  default
    end
    def  on_message(body)
        puts  "Processing  #{body}  of  #{message}"
    end
end
Processors
config/torquebox.yml

messaging:
  /topics/orders:
    - PrintHandler
    - ShoutHandler
  /queues/receipts:
    PrintHandler:
      concurrency: 5
      config:
        printer: the_little_one
Processors
config/torquebox.yml

messaging:
  /topics/orders:
    - PrintHandler
    - ShoutHandler
  /queues/receipts:
    PrintHandler:
      concurrency: 5
      config:
        printer: the_little_one
Processors
config/torquebox.yml

messaging:
  /topics/orders:
    - PrintHandler
    - ShoutHandler
  /queues/receipts:
    PrintHandler:
      concurrency: 5
      config:
        printer: the_little_one
Processors
config/torquebox.yml

messaging:
  /topics/orders:
    - PrintHandler
    - ShoutHandler
  /queues/receipts:
    PrintHandler:
      concurrency: 5
      config:
        printer: the_little_one
Processors
app/models/print_handler.rb

include  TorqueBox::Messaging

class  PrintHandler  <  MessageProcessor
    def  initialize(opts)
        @printer  =  opts['printer']  ||  default
    end
    def  on_message(body)
        puts  "Processing  #{body}  of  #{message}"
    end
end
Queues  (again)


 But  how  do  you  send  a  
 message?
Queues
contrived  example

questions  =  Queue.new('/queues/questions')
answers  =  Queue.new('/queues/answers')
  
Thread.new  do
    questions.publish  "What  time  is  it?"
    puts  answers.receive(  :timeout  =>  1000  )
end
  
puts  questions.receive
answers.publish  Time.now
Queues
contrived  example

questions  =  Queue.new('/queues/questions')
answers  =  Queue.new('/queues/answers')
  
Thread.new  do
    questions.publish  "What  time  is  it?"
    puts  answers.receive(  :timeout  =>  1000  )
end
  
puts  questions.receive
answers.publish  Time.now
Queues
contrived  example

questions  =  Queue.new('/queues/questions')
answers  =  Queue.new('/queues/answers')
  
Thread.new  do
    questions.publish  "What  time  is  it?"
    puts  answers.receive(  :timeout  =>  1000  )
end
  
puts  questions.receive
answers.publish  Time.now
Queues
contrived  example

questions  =  Queue.new('/queues/questions')
answers  =  Queue.new('/queues/answers')
  
Thread.new  do
    questions.publish  "What  time  is  it?"
    puts  answers.receive(  :timeout  =>  1000  )
end
  
puts  questions.receive
answers.publish  Time.now
Services
run along, lil’ daemon
Services

Long-­running,  non-­web  
“daemons”  that  share  the  
runtime  environment  and  
deployment  lifecycle  of  
your  app.
Services
• Represented  as  a  class  with  
  optional  initialize(Hash),  
    start()  and  stop()  methods,  
    which  should  each  return  quickly.
•   Typically  will  start  a  long-­running  
    loop  in  a  thread  and  respond  to  
    external  events.
•   Configured  via  services:  section  in  
    torquebox.yml
Services
config/torquebox.yml


services:
    TimeMachine:
        queue:  /queue/morris_day

    MyMudServer:

    SomeOtherService:
Services
 app/services/time_machine.rb

class  TimeMachine
    def  initialize(opts)
        @queue  =  Queue.new(opts['queue'])
    end

    def  start  
        Thread.new  do
              until  @done
                  @queue.publish(Time.now)
                  sleep(1)  
              end
          end
    end

    def  stop;;  @done  =  true;;  end
end
Services
 app/services/time_machine.rb

class  TimeMachine
    def  initialize(opts)
        @queue  =  Queue.new(opts['queue'])
    end

    def  start  
        Thread.new  do
              until  @done
                  @queue.publish(Time.now)
                  sleep(1)  
              end
          end
    end

    def  stop;;  @done  =  true;;  end
end
Services
 app/services/time_machine.rb

class  TimeMachine
    def  initialize(opts)
        @queue  =  Queue.new(opts['queue'])
    end

    def  start  
        Thread.new  do
              until  @done
                  @queue.publish(Time.now)
                  sleep(1)  
              end
          end
    end

    def  stop;;  @done  =  true;;  end
end
Services
 app/services/time_machine.rb

class  TimeMachine
    def  initialize(opts)
        @queue  =  Queue.new(opts['queue'])
    end

    def  start  
        Thread.new  do
              until  @done
                  @queue.publish(Time.now)
                  sleep(1)  
              end
          end
    end

    def  stop;;  @done  =  true;;  end
end
Caching
save a little for later
Caching
config/application.rb


config.cache_store  =  
:torque_box_store,  :mode  =>  :local

#  or

config.cache_store  =  
ActiveSupport::Cache::TorqueBoxStore.new
(  :mode  =>  :local  )
Runtime  Options
   shorts or sweats?
Runtime  Options
config/torquebox.yml


#per  app!
ruby:
    version:  1.9  
    compile_mode:  jit
Clustering
less failure faster
Web

• session  replication
• intelligent  load-­balancing  (via  
  mod_cluster)
• failover  (via  mod_cluster)
Messaging

HornetQ  clusters  
automatically,  giving  you  
message  processing  
capability  that  grows  with  
the  cluster.
Services

A  service  runs  on  every  
cluster  node,  unless  
marked  as  a  singleton.
Jobs

A  job  runs  on  every  cluster  
node,  unless  marked  as  a  
singleton  (just  like  
services).
Caching

Infinispan  clusters  
automatically,  "distributing"  
your  cache.  
BENchmarks
Real-­world  Rails  application:
Redmine
Comparisons:
TorqueBox,  Trinidad,  Passenger,  
Unicorn,  Glassfish,  Thin
Runtimes:
JRuby,  MRI,  RubyEE
Roadmap
May  -­  1.0.0.Final
Then...
    AS7
    Authentication
    Mobicents
    ???  -­  you  tell  us
Resources

• http://torquebox.org
• irc:  #torquebox  on  freenode
• https://github.com/torquebox
• http://twitter.com/torquebox
Thanks!
questions?

Weitere ähnliche Inhalte

Was ist angesagt?

TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyistsbobmcwhirter
 
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 Torqueboxrockyjaiswal
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on InfinispanLance Ball
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyBruno Oliveira
 
Introducing Immutant
Introducing Immutant Introducing Immutant
Introducing Immutant Jim Crossley
 
Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Lance Ball
 
Spring into rails
Spring into railsSpring into rails
Spring into railsHiro Asari
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxClaus Ibsen
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosBruno Oliveira
 
Apache Camel - FUSE community day London 2010 presentation
Apache Camel - FUSE community day London 2010 presentationApache Camel - FUSE community day London 2010 presentation
Apache Camel - FUSE community day London 2010 presentationClaus Ibsen
 
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013Puppet
 
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013Puppet
 
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsSymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsPablo Godel
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
 

Was ist angesagt? (20)

Immutant
ImmutantImmutant
Immutant
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
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
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
 
JRuby and You
JRuby and YouJRuby and You
JRuby and You
 
TorqueBox - When Java meets Ruby
TorqueBox - When Java meets RubyTorqueBox - When Java meets Ruby
TorqueBox - When Java meets Ruby
 
Introducing Immutant
Introducing Immutant Introducing Immutant
Introducing Immutant
 
Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Torquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundosTorquebox - O melhor dos dois mundos
Torquebox - O melhor dos dois mundos
 
Apache Camel - FUSE community day London 2010 presentation
Apache Camel - FUSE community day London 2010 presentationApache Camel - FUSE community day London 2010 presentation
Apache Camel - FUSE community day London 2010 presentation
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
Testing for Ops: Going Beyond the Manifest - PuppetConf 2013
 
Perl in Teh Cloud
Perl in Teh CloudPerl in Teh Cloud
Perl in Teh Cloud
 
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
 
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsSymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
 
First Day With J Ruby
First Day With J RubyFirst Day With J Ruby
First Day With J Ruby
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 

Ähnlich wie Torquebox @ Raleigh.rb - April 2011

Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceQuinlan Jung
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With RpmMartin Jackson
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Hyun-Mook Choi
 
Composer for Busy Developers - php|tek13
Composer for Busy Developers - php|tek13Composer for Busy Developers - php|tek13
Composer for Busy Developers - php|tek13Rafael Dohms
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftWan Muzaffar Wan Hashim
 
Minimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestrationMinimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestrationOutlyer
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf Conference
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
DCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best PracticesDCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best PracticesDocker, Inc.
 
Instruction: dev environment
Instruction: dev environmentInstruction: dev environment
Instruction: dev environmentSoshi Nemoto
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
DockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesDockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesTibor Vass
 
DCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best PracticesDCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best PracticesDocker, Inc.
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 

Ähnlich wie Torquebox @ Raleigh.rb - April 2011 (20)

Hosting Your Own OTA Update Service
Hosting Your Own OTA Update ServiceHosting Your Own OTA Update Service
Hosting Your Own OTA Update Service
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Composer for Busy Developers - php|tek13
Composer for Busy Developers - php|tek13Composer for Busy Developers - php|tek13
Composer for Busy Developers - php|tek13
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in Swift
 
Minimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestrationMinimum Viable Docker: our journey towards orchestration
Minimum Viable Docker: our journey towards orchestration
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
DCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best PracticesDCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best Practices
 
Instruction: dev environment
Instruction: dev environmentInstruction: dev environment
Instruction: dev environment
 
Composer
ComposerComposer
Composer
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
DockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesDockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best Practices
 
DCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best PracticesDCEU 18: Dockerfile Best Practices
DCEU 18: Dockerfile Best Practices
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Core Android
Core AndroidCore Android
Core Android
 

Torquebox @ Raleigh.rb - April 2011

  • 1. Toby Crawley Raleigh.rb Creative  Commons  BY-­SA  3.0 April 2011
  • 2. whoami • @tcrawley • C  >  Java  >  PHP  >  Java  >  Ruby  >   Java? • Red  Hat  Senior  Engineer   • member  of
  • 3.
  • 4. Goal To  have  you  downloading   TorqueBox  right  after  this   talk.
  • 5. TorqueBox the power of JBoss with the expressiveness of Ruby
  • 6. TorqueBox:  what? • A  “real”  app  server  for  Ruby • Founded  in  2008 • 100%  open-­source,  LGPL  license • Based  on  JBoss  AS  and  JRuby • Just  released  1.0.0.CR1!
  • 8. I  promise... • No  XML   • No  Java  * • No  war  files  * • Only  Ruby  and  YAML * Unless you really want to
  • 9. TorqueBox:  why? • “Native”  support  for  Rack  apps • Built-­in:   • background  processing • scheduling • daemons  (services) • clustering • Easily  scalable • Optionally  enterprisey
  • 10. JRuby a good idea done well
  • 11. JRuby:  why? • Very  fast  runtime • Real  threads • Java  libraries • Java  tools • Healthy  community
  • 13. The  Competition Unicorn,  Thin,  Passenger,   Trinidad,  Warbler... ...all  address  only  the  web   question.
  • 14. AS  =  Application  Server • Not  just  “web  server  +  interpreter” • More  like  initd  than  httpd • Can  host  multiple,  disparate  apps   simultaneously • Provides  basic  services  to  all  the   apps  it  hosts
  • 15. JBoss  AS6 • Tomcat  for  web • Infinispan  for  caching • HornetQ  for  messaging • Quartz  for  scheduling • PicketBox  for  authentication • mod_cluster  for  clustering
  • 16. Setting  Up  TorqueBox in 3 easy steps!
  • 17. Easy  Install (download  1.0.0.CR1  from  torquebox.org) $  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip $  export  TORQUEBOX_HOME=$PWD/torquebox-­1* $  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss $  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby $  export  PATH=$JRUBY_HOME/bin:$PATH
  • 18. Easy  Install (download  1.0.0.CR1  from  torquebox.org) $  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip $  export  TORQUEBOX_HOME=$PWD/torquebox-­1* $  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss $  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby $  export  PATH=$JRUBY_HOME/bin:$PATH
  • 19. Easy  Install (download  1.0.0.CR1  from  torquebox.org) $  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip $  export  TORQUEBOX_HOME=$PWD/torquebox-­1* $  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss $  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby $  export  PATH=$JRUBY_HOME/bin:$PATH
  • 20. Easy  Install (download  1.0.0.CR1  from  torquebox.org) $  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip $  export  TORQUEBOX_HOME=$PWD/torquebox-­1* $  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss $  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby $  export  PATH=$JRUBY_HOME/bin:$PATH
  • 21. Easy  Install (download  1.0.0.CR1  from  torquebox.org) $  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip Make  sure  the  jruby   found  in  your  path  is  in   $  export  TORQUEBOX_HOME=$PWD/torquebox-­1* $JRUBY_HOME/bin. $  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss $  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby $  export  PATH=$JRUBY_HOME/bin:$PATH
  • 22. Easy  Install (download  1.0.0.CR1  from  torquebox.org) $  unzip  torquebox-­dist-­1.0.0.CR1-­bin.zip Make  sure  the  jruby   found  in  your  path  is  in   $  export  TORQUEBOX_HOME=$PWD/torquebox-­1* $JRUBY_HOME/bin. $  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss $  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby $  export  PATH=$JRUBY_HOME/bin:$PATH
  • 23. Easy  Install $  jruby  -­S  gem  install  bundler $  jruby  -­S  gem  install  rails $  jruby  -­S  gem  install  sinatra
  • 25. Database  Connectivity Gemfile gem  "activerecord-­jdbc-­adapter" gem  "jdbc-­postgres" #  gem  "jdbc-­sqlite3" #  gem  "jdbc-­mysql"
  • 26. Rails  Template • Adds  TorqueBox  rake  tasks • Adds  the  JDBC  sqlite3  gems • Adds  TorqueBox  session_store • Adds  Backgroundable  module
  • 27. Rake  Tasks rake  torquebox:run        Run  TorqueBox  server rake  torquebox:deploy[context_path]        Deploy  the  app  in  the  current  directory rake  torquebox:undeploy        Undeploy  the  app  in  the  current  directory
  • 28. Rake  Tasks Start  torquebox:run  in  its  own   shell  and  leave  it  running.  Instead   of  script/server  or  shotgun   or  thin  or  whatever  else,   use  torquebox:deploy.
  • 29. Deployment  Descriptors torquebox:deploy  creates   a  deployment  descriptor  in  the   $TORQUEBOX_HOME/apps/   directory
  • 30. Hot  Deployment $TORQUEBOX_HOME/apps/ • anything  added  to  apps/   will  get  deployed • anything  removed  from   apps/  will  get  undeployed • anything  updated  in  apps/   will  get  redeployed • TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives
  • 31. Hot  Deployment $TORQUEBOX_HOME/apps/ deployment   descriptors • anything  added  to  apps/   will  get  deployed • anything  removed  from   apps/  will  get  undeployed • anything  updated  in  apps/   will  get  redeployed • TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives
  • 32. Hot  Deployment $TORQUEBOX_HOME/apps/ deployment   descriptors • anything  added  to  apps/   will  get  deployed • anything  removed  from   apps/  will  get  undeployed • anything  updated  in  apps/   will  get  redeployed • TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives
  • 33. Hot  Deployment $TORQUEBOX_HOME/apps/ • anything  added  to  apps/   will  get  deployed • anything  removed  from   apps/  will  get  undeployed knob  files  (zip   • anything  updated  in  apps/   archives) will  get  redeployed • TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives
  • 34. Hot  Deployment $TORQUEBOX_HOME/apps/ • anything  added  to  apps/   will  get  deployed • anything  removed  from   apps/  will  get  undeployed knob  files  (zip   • anything  updated  in  apps/   archives) will  get  redeployed • TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives
  • 35. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp env: development web: context: myapp host: www.yourhost.com static: public environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 36. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp env: development web: The  fully-­qualified   context: myapp host: www.yourhost.com path  to  the  app.     static: public This  will  be  the  value   environment: of  either   RAILS_ROOT  or   MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com RACK_ROOT
  • 37. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp env: development web: The  fully-­qualified   context: myapp host: www.yourhost.com path  to  the  app.     static: public This  will  be  the  value   environment: of  either   RAILS_ROOT  or   MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com RACK_ROOT
  • 38. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp env: development web: context: myapp The  runtime  mode  of   host: www.yourhost.com static: public the  app.    This  will  be   environment: either  RAILS_ENV   or  RACK_ENV MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 39. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp env: development web: context: myapp The  runtime  mode  of   host: www.yourhost.com static: public the  app.    This  will  be   environment: either  RAILS_ENV   or  RACK_ENV MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 40. Deployment  Descriptors The  app’s  context  path   apps/myapp-­knob.yml (or  “sub  URI”): http://localhost:8080/myapp application: Can  be  set  via  rake: root: rake  torquebox:deploy[myapp] /path/to/myapp env: development The  default  is  root: web: http://localhost:8080/ context: myapp host: www.yourhost.com static: public environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 41. Deployment  Descriptors The  app’s  context  path   apps/myapp-­knob.yml (or  “sub  URI”): http://localhost:8080/myapp application: Can  be  set  via  rake: root: rake  torquebox:deploy[myapp] /path/to/myapp env: development The  default  is  root: web: http://localhost:8080/ context: myapp host: www.yourhost.com static: public environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 42. Deployment  Descriptors apps/myapp-­knob.yml application: A  list  of  virtual   root: /path/to/myapp env: development hostnames  to  which   web: to  bind  the  app. context: myapp host: www.yourhost.com static: public environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 43. Deployment  Descriptors apps/myapp-­knob.yml application: A  list  of  virtual   root: /path/to/myapp env: development hostnames  to  which   web: to  bind  the  app. context: myapp host: www.yourhost.com static: public environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 44. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp env: development The  location  of  the   web: app’s  static   context: myapp content,  either   host: www.yourhost.com absolute  or  relative   static: public environment: to  the  app’s  root. MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 45. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp env: development The  location  of  the   web: app’s  static   context: myapp content,  either   host: www.yourhost.com absolute  or  relative   static: public environment: to  the  app’s  root. MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 46. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp Any  environment   env: development web: variables  required   context: myapp by  the  app. host: www.yourhost.com static: public environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 47. Deployment  Descriptors apps/myapp-­knob.yml application: root: /path/to/myapp Any  environment   env: development web: variables  required   context: myapp by  the  app. host: www.yourhost.com static: public environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com
  • 48. Deployment  Descriptors • config/torquebox.yml   • internal  descriptors  have  the   same  structure  as  the   external  ones  in  apps/ • may  be  used  to  provide  your   own  reasonable  defaults
  • 49. Components Put 'em together, and you have an AS
  • 51. jruby-­rack • All  rack-­based  frameworks   supported:  rails,  sinatra,  etc • No  packaging  required:  apps  deploy   from  where  they  sit  on  disk • No  redeploy  necessary  to  see   changes  when  using  rack  reloading   or  rails  development  mode • We  use  it  inside  Tomcat
  • 53. Jobs app/jobs/newsletter_sender.rb class  NewsletterSender      def  run()        subscriptions  =  Subscription.find(:all)        subscriptions.each  do  |e|            send_newsletter(  e  )        end    end   end
  • 54. Jobs config/torquebox.yml jobs:    monthly_newsletter:        description:  first  of  month        job:  NewsletterSender        cron:  ‘0  0  0  1  *  ?’        process_tps_reports:        job:  TPSReportProcessor        cron:  ‘0  0  0  0  MON  ?’
  • 55. Jobs • More  portable.  What  is  the  first  day   of  the  week  on  BSD  again?    What’s   cron  on  Windows? • Self  contained  within  the  app.    No   external  systems  to  manage  and   keep  in  sync. • Full  application  environment  loaded   and  available.
  • 57. TorqueBox::Messaging • JMS  (Java  Message  Service)   is  an  API  for  messaging • implementation HornetQ  is  the  JBoss  JMS  
  • 58. Background  Processing • Tasks • Backgroundable  methods
  • 59. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  Person.find_by_id(payload[:id])        person.send_welcome_spam  if  person    end end
  • 60. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  Person.find_by_id(payload[:id])        person.send_welcome_spam  if  person    end end
  • 61. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  Person.find_by_id(payload[:id])        person.send_welcome_spam  if  person    end end
  • 62. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  Person.find_by_id(payload[:id])        person.send_welcome_spam  if  person    end end
  • 63. Tasks app/controllers/people_controller.rb class  PeopleController  <  ApplicationController    def  create        @person  =  Person.new(params[:person])        respond_to  do  |format|            if  @person.save                EmailTask.async(:welcome,  :id  =>  person.id)                #  respond  appropriately            end        end    end end
  • 64. Tasks app/controllers/people_controller.rb class  PeopleController  <  ApplicationController    def  create        @person  =  Person.new(params[:person])        respond_to  do  |format|            if  @person.save                EmailTask.async(:welcome,  :id  =>  person.id)                #  respond  appropriately            end        end    end end
  • 65. Backgroundable Inspired  by  DelayedJob’s   handle_asynchronously,   it’s  trivial  to  create  implicit   background  Tasks.
  • 66. Backgroundable lib/something.rb include  TorqueBox::Messaging   class  Something    include  Backgroundable    always_background  :foo    def  foo;;  end    def  bar;;  end end ... @something.foo @something.background.bar
  • 67. Backgroundable lib/something.rb include  TorqueBox::Messaging   class  Something    include  Backgroundable    always_background  :foo    def  foo;;  end    def  bar;;  end end ... @something.foo @something.background.bar
  • 68. Backgroundable lib/something.rb include  TorqueBox::Messaging   class  Something    include  Backgroundable    always_background  :foo    def  foo;;  end    def  bar;;  end end ... @something.foo @something.background.bar
  • 69. Backgroundable lib/something.rb include  TorqueBox::Messaging   class  Something    include  Backgroundable    always_background  :foo    def  foo;;  end    def  bar;;  end end ... @something.foo @something.background.bar
  • 70. Background  Processing Call  it  from  your   controllers,  models,  and   observers,  or  even  other   tasks.  Even  in  non-­Rails   apps!
  • 71. Background  Procssing • No  extra  tables  in  your  database • No  external  system  to  manage • Little  to  no  config  required  at  all • System  gets  redeployed  w/app • Efficient  loading  of  rails  environment • Automatic  load  balancing  and  retries • Works  on  Windows,  if  you  care
  • 72. Queues Tasks  and  Backgroundable  are   built  on  top  of  Queues.    Of   course,  you  may  build  your   own  messaging  based  apps  by   defining  your  own  Queues,   Topics,  and  their  message   Processors  yourself.
  • 73. Queues config/torquebox.yml queues:    /queues/questions:    /queues/answers:        durable:  false
  • 74. Topics • behavior  is  different,  but  interface  is   the  same. • all  subscribers  of  a  topic  see  each   message,  but  only  one  subscriber   will  see  any  message  from  a  queue   • use  topics:  section  of   torquebox.yml  to  define  topics
  • 75. Processors You  can  create  a  processor   class  to  receive  messages   from  a  Topic  or  Queue
  • 76. Processors app/models/print_handler.rb include  TorqueBox::Messaging class  PrintHandler  <  MessageProcessor    def  initialize(opts)        @printer  =  opts['printer']  ||  default    end    def  on_message(body)        puts  "Processing  #{body}  of  #{message}"    end end
  • 77. Processors config/torquebox.yml messaging: /topics/orders: - PrintHandler - ShoutHandler /queues/receipts: PrintHandler: concurrency: 5 config: printer: the_little_one
  • 78. Processors config/torquebox.yml messaging: /topics/orders: - PrintHandler - ShoutHandler /queues/receipts: PrintHandler: concurrency: 5 config: printer: the_little_one
  • 79. Processors config/torquebox.yml messaging: /topics/orders: - PrintHandler - ShoutHandler /queues/receipts: PrintHandler: concurrency: 5 config: printer: the_little_one
  • 80. Processors config/torquebox.yml messaging: /topics/orders: - PrintHandler - ShoutHandler /queues/receipts: PrintHandler: concurrency: 5 config: printer: the_little_one
  • 81. Processors app/models/print_handler.rb include  TorqueBox::Messaging class  PrintHandler  <  MessageProcessor    def  initialize(opts)        @printer  =  opts['printer']  ||  default    end    def  on_message(body)        puts  "Processing  #{body}  of  #{message}"    end end
  • 82. Queues  (again) But  how  do  you  send  a   message?
  • 83. Queues contrived  example questions  =  Queue.new('/queues/questions') answers  =  Queue.new('/queues/answers')   Thread.new  do    questions.publish  "What  time  is  it?"    puts  answers.receive(  :timeout  =>  1000  ) end   puts  questions.receive answers.publish  Time.now
  • 84. Queues contrived  example questions  =  Queue.new('/queues/questions') answers  =  Queue.new('/queues/answers')   Thread.new  do    questions.publish  "What  time  is  it?"    puts  answers.receive(  :timeout  =>  1000  ) end   puts  questions.receive answers.publish  Time.now
  • 85. Queues contrived  example questions  =  Queue.new('/queues/questions') answers  =  Queue.new('/queues/answers')   Thread.new  do    questions.publish  "What  time  is  it?"    puts  answers.receive(  :timeout  =>  1000  ) end   puts  questions.receive answers.publish  Time.now
  • 86. Queues contrived  example questions  =  Queue.new('/queues/questions') answers  =  Queue.new('/queues/answers')   Thread.new  do    questions.publish  "What  time  is  it?"    puts  answers.receive(  :timeout  =>  1000  ) end   puts  questions.receive answers.publish  Time.now
  • 88. Services Long-­running,  non-­web   “daemons”  that  share  the   runtime  environment  and   deployment  lifecycle  of   your  app.
  • 89. Services • Represented  as  a  class  with   optional  initialize(Hash),   start()  and  stop()  methods,   which  should  each  return  quickly. • Typically  will  start  a  long-­running   loop  in  a  thread  and  respond  to   external  events. • Configured  via  services:  section  in   torquebox.yml
  • 90. Services config/torquebox.yml services:    TimeMachine:        queue:  /queue/morris_day    MyMudServer:    SomeOtherService:
  • 91. Services app/services/time_machine.rb class  TimeMachine    def  initialize(opts)        @queue  =  Queue.new(opts['queue'])    end    def  start          Thread.new  do              until  @done                  @queue.publish(Time.now)                  sleep(1)                end          end    end    def  stop;;  @done  =  true;;  end end
  • 92. Services app/services/time_machine.rb class  TimeMachine    def  initialize(opts)        @queue  =  Queue.new(opts['queue'])    end    def  start          Thread.new  do              until  @done                  @queue.publish(Time.now)                  sleep(1)                end          end    end    def  stop;;  @done  =  true;;  end end
  • 93. Services app/services/time_machine.rb class  TimeMachine    def  initialize(opts)        @queue  =  Queue.new(opts['queue'])    end    def  start          Thread.new  do              until  @done                  @queue.publish(Time.now)                  sleep(1)                end          end    end    def  stop;;  @done  =  true;;  end end
  • 94. Services app/services/time_machine.rb class  TimeMachine    def  initialize(opts)        @queue  =  Queue.new(opts['queue'])    end    def  start          Thread.new  do              until  @done                  @queue.publish(Time.now)                  sleep(1)                end          end    end    def  stop;;  @done  =  true;;  end end
  • 96. Caching config/application.rb config.cache_store  =   :torque_box_store,  :mode  =>  :local #  or config.cache_store  =   ActiveSupport::Cache::TorqueBoxStore.new (  :mode  =>  :local  )
  • 97. Runtime  Options shorts or sweats?
  • 98. Runtime  Options config/torquebox.yml #per  app! ruby:    version:  1.9      compile_mode:  jit
  • 100. Web • session  replication • intelligent  load-­balancing  (via   mod_cluster) • failover  (via  mod_cluster)
  • 101. Messaging HornetQ  clusters   automatically,  giving  you   message  processing   capability  that  grows  with   the  cluster.
  • 102. Services A  service  runs  on  every   cluster  node,  unless   marked  as  a  singleton.
  • 103. Jobs A  job  runs  on  every  cluster   node,  unless  marked  as  a   singleton  (just  like   services).
  • 104. Caching Infinispan  clusters   automatically,  "distributing"   your  cache.  
  • 105. BENchmarks Real-­world  Rails  application: Redmine Comparisons: TorqueBox,  Trinidad,  Passenger,   Unicorn,  Glassfish,  Thin Runtimes: JRuby,  MRI,  RubyEE
  • 106.
  • 107.
  • 108. Roadmap May  -­  1.0.0.Final Then...    AS7    Authentication    Mobicents    ???  -­  you  tell  us
  • 109. Resources • http://torquebox.org • irc:  #torquebox  on  freenode • https://github.com/torquebox • http://twitter.com/torquebox