SlideShare ist ein Scribd-Unternehmen logo
1 von 110
Downloaden Sie, um offline zu lesen
Crank Up Your Apps With




                                                           Jim Crossley
                                                              MagicRuby
Creative  Commons  BY-­SA  3.0
                                                               Feb 2011

                                                                          1
Jim  who?

• “recovering  java  architect”
• java  since  ’96,  ruby  since  ’06
• emacs  and  guitars  since  forever
• Red  Hat  Senior  Engineer  
• proud  member  of

                                        2
3
Bob  McWhirter




                 4
Agenda
 • High-­level  BS  and  Development  
   Process
 • Web,  Messaging,  Scheduling,  
   Services,  Clustering




                                         5
TorqueBox
the power of JBoss with the expressiveness of Ruby




                                                     6
TorqueBox:  what?

• A  “real”  app  server  for  Ruby
• Founded  in  2008
• Bob’s  “labor  of  love”
• 100%  open-­source,  LGPL  license
• Reflects  a  strong  commitment  to  
  Ruby  from  Red  Hat


                                          7
TorqueBox:  why?

• “Native”  support  for  Rack  apps
• Built-­in  background  processing
• Built-­in  scheduling
• Built-­in  clustering
• Easily  scalable
• Optionally  enterprisey
                                       8
JRuby
a good idea done well




                        9
JRuby:  why?

• Very  fast  runtime
• Real  threads
• Java  libraries
• Java  tools
• Healthy  community

                        10
JRuby:  why  not?

• Slower  start  up
• Native  gems
 • FFI
 • C  extension  support
• Some  Ruby  libs  not  thread-­safe

                                        11
JBoss  AS
but before we get to that...




                               12
Enterprise  Java
   misconceptions




                    13
Is it
Scary?
         14
Acronymious?
 WAR      JAXBEAR JSTL SLSB
 JSF JNLPJTA JPA   JNI JCK
  JAX-­RPC JDOM JAXP JAX-­WS
  JSE JEE JMM JTS        JWS
       NIO JDO AWT   JMX
   JLS          JAR JRE JCP  
       JSR JNDI
 JSP SAF EJB         JME POJO
JMSJDBC   JDK   JVM
                JAX-­RS JPQL
       NPE
                            15
Bloated?




           16
Bewildering?




               17
Enterprise  Java  is  all  that
        and more! but...




                                  18
I  promise...

• No  XML  
• No  Java  *
• No  war  files  *
• Only  Ruby,  YAML  and...
* Unless you really want to

                              19
JBoss  AS
the enterprisey good parts




                             20
JBoss  AS6

• Tomcat  for  web
• Infinispan  for  caching
• HornetQ  for  messaging
• Quartz  for  scheduling
• mod_cluster  for  clustering

                                 21
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


                                              22
Hot  Deployment
    $JBOSS_HOME/server/default/deploy/

•   anything  added  to  deploy/  
    will  get  deployed
•   anything  removed  from  
    deploy/  will  get  
    undeployed
•   anything  updated  in  
    deploy/  will  get  redeployed
•   TorqueBox  deployers  
    make  JBoss  grok  YAML  
    and  ruby  archives



                                         23
Hot  Deployment
    $JBOSS_HOME/server/default/deploy/

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



                                         24
Hot  Deployment
    $JBOSS_HOME/server/default/deploy/

•   anything  added  to  deploy/  
    will  get  deployed
•   anything  removed  from  
    deploy/  will  get  
    undeployed
•   anything  updated  in  
           zip  files  
    deploy/  will  get  redeployed
•         (archives)
    TorqueBox  deployers  
    make  JBoss  grok  YAML  
    and  ruby  archives



                                         25
Development  Process
    how do they work?




                        26
easy  install

$  wget  http://torquebox.org/torquebox-­dev.zip
$  unzip  torquebox-­dev.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



                                                   27
easy  install

$  wget  http://torquebox.org/torquebox-­dev.zip
$  unzip  torquebox-­dev.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



                                                   28
easy  install

$  wget  http://torquebox.org/torquebox-­dev.zip
$  unzip  torquebox-­dev.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



                                                   29
easy  install

$  wget  http://torquebox.org/torquebox-­dev.zip
$  unzip  torquebox-­dev.zip Make  sure  the  jruby  
                            found  in  your  path  is  in  
                             $JRUBY_HOME/bin.
$  export  TORQUEBOX_HOME=$PWD/torquebox-­1*
$  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss
$  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby

$  export  PATH=$JRUBY_HOME/bin:$PATH



                                                              30
easy  install


$  jruby  -­S  gem  install  bundler
$  jruby  -­S  gem  install  rails
$  jruby  -­S  gem  install  sinatra



                                       31
rake  tasks
Rakefile




require  "org.torquebox.rake-­support"




                                         32
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



                                                          33
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.



                                              34
deployment  descriptors


 torquebox:deploy  creates  
 a  deployment  descriptor  in  the  
 JBoss  deploy/  directory



                                        35
deployment  descriptors
deploy/myapp-­{rails,rack}.yml

application:
  root:    /path/to/myapp
  env:     development
web:
  context: myapp
  host:    www.yourhost.com
  static: public
  rackup: config.ru
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com


                                 36
deployment  descriptors
deploy/myapp-­{rails,rack}.yml

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


                                                          37
deployment  descriptors
deploy/myapp-­{rails,rack}.yml

application:
  root:    /path/to/myapp
  env:     development
web:
  context: myapp
  host:    www.yourhost.comThe  runtime  mode  of  
  static: public           the  app.    This  will  be  
  rackup: config.ru
environment:
                            either  RAILS_ENV  
  MAIL_HOST: mail.yourhost.comor  RACK_ENV
  REPLY_TO: you@yourhost.com


                                                           38
deployment  descriptors
                        The  app’s  context  path  
 deploy/myapp-­{rails,rack}.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
  rackup: config.ru
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com


                                                      39
deployment  descriptors
deploy/myapp-­{rails,rack}.yml

application:
  root:    /path/to/myapp      A  list  of  virtual  
  env:     development      hostnames  to  which  
web:                          to  bind  the  app.
  context: myapp
  host:    www.yourhost.com
  static: public
  rackup: config.ru
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com


                                                        40
deployment  descriptors
deploy/myapp-­{rails,rack}.yml

application:
  root:    /path/to/myapp
  env:     development
web:
                              The  location  of  the  
  context: myapp                   app’s  static  
  host:    www.yourhost.com     content,  either  
  static: public              absolute  or  relative  
  rackup: config.ru            to  the  app’s  root.
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com


                                                         41
deployment  descriptors
deploy/myapp-­{rails,rack}.yml

application:
  root:    /path/to/myapp
  env:     development
web:
                            The  name  of  the  
  context: myapp          rackup  script  used  to  
  host:    www.yourhost.com boot  your  app
  static: public
  rackup: config.ru
environment:
  MAIL_HOST: mail.yourhost.com
  REPLY_TO: you@yourhost.com


                                                       42
deployment  descriptors
deploy/myapp-­{rails,rack}.yml

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


                                                   43
deployment  descriptors

•   config/torquebox.yml  
•   internal  descriptors  have  the  
    same  structure  as  the  
    external  ones  in  deploy/
•   may  be  used  to  provide  your  
    own  reasonable  defaults


                                         44
Web
make rack, not war




                     45
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


                                             46
database  connectivity
Gemfile



gem  "activerecord-­jdbc-­adapter"

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



                                     47
rails  template

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

                                   48
my  first  rails  app

$  jruby  -­S  rails  new  myapp  -­m  
        $TORQUEBOX_HOME/share/rails/template.rb

$  cd  myapp
$  jruby  -­S  bundle  install

$  jruby  -­S  rake  torquebox:deploy




                                                  49
Messaging
 asynchronicity




                  50
lots  of  options
RabbitMQ     Resque      cron       BackgroundDRb
                            workling      CronEdit
            BackgroundJob
  Kestral                 rufus-scheduler JobFu
                  Ap4r
Amazon SQS                   async_observer
               Taskr Sparrow            Background-Fu
 beanstalkd     DelayedJob    RailsCron
                                           Open4
                            Conveyor
  WorkerQueue daemons                 rake
                                           ActiveMQ
   starling     Spawn ActiveMessaging

                                                        51
TorqueBox::Messaging


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




                                    52
TorqueBox::Messaging

•   Task
•   Backgroundable
•   MessageProcessor
•   Queue
•   Topic

                       53
TorqueBox::Messaging
• No  extra  tables  in  your  database
• No  external  system  to  manage
• Little  to  no  config  required  at  all
• No  redeploy  necessary  in  dev  mode
• Efficient  loading  of  rails  environment
• Automatic  load  balancing  and  retries
• Works  on  Windows,  if  you  care
                                               54
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  payload[:person]  
        person  ||=  Person.find_by_id(payload[:id])
        if  person
            #  send  the  email
            person.welcomed  =  true
            person.save!
        end
    end
end



                                                       55
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  payload[:person]  
        person  ||=  Person.find_by_id(payload[:id])
        if  person
            #  send  the  email
            person.welcomed  =  true
            person.save!
        end
    end
end



                                                       56
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  payload[:person]  
        person  ||=  Person.find_by_id(payload[:id])
        if  person
            #  send  the  email
            person.welcomed  =  true
            person.save!
        end
    end
end



                                                       57
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  payload[:person]  
        person  ||=  Person.find_by_id(payload[:id])
        if  person
            #  send  the  email
            person.welcomed  =  true
            person.save!
        end
    end
end



                                                       58
Tasks
app/tasks/email_task.rb

class  EmailTask  <  TorqueBox::Messaging::Task
    def  welcome(payload)
        person  =  payload[:person]  
        person  ||=  Person.find_by_id(payload[:id])
        if  person
            #  send  the  email
            person.welcomed  =  true
            person.save!
        end
    end
end



                                                       59
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




                                                                 60
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




                                                                 61
Tasks

Call  them  from  your  
controllers,  models,  and  
observers,  or  even  other  
tasks.  Even  in  non-­Rails  
apps!


                                 62
Backgroundable

Inspired  by  DelayedJob’s  
handle_asynchronously,  
it’s  trivial  to  create  implicit  
background  Tasks.


                                        63
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


                                  64
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


                                  65
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


                                  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
app/models/slow_poke.rb


class  SlowPoke  <  ActiveRecord::Base
    def  takes_forever;;  end
    def  might_take_awhile;;  end
end

SlowPoke.always_background  :takes_forever

@slowpoke.takes_forever
@slowpoke.background.might_take_awhile



                                             68
Queues
Tasks  are  built  on  top  of  
Queues.    Of  course,  you  may  
build  your  own  “MOM”  apps  
by  defining  your  own  Queues,  
Topics,  and  their  message  
Processors  yourself.


                                     69
Queues
config/queues.yml


/queues/questions:

/queues/answers:
    durable:  false


                      70
Processors

You  can  create  a  processor  
class  to  receive  messages  
from  a  Topic  or  Queue



                                   71
Processors
config/messaging.yml

/topics/print: PrintHandler
/queues/popular:
  - PopularHandler
  - AdultObserver:
      filter: "age >= 18"
      concurrency: 5
/queues/students:
  PrintHandler:
    config:
      color: true


                              72
Processors
config/messaging.yml

/topics/print: PrintHandler
/queues/popular:
  - PopularHandler
  - AdultObserver:
      filter: "age >= 18"
      concurrency: 5
/queues/students:
  PrintHandler:
    config:
      color: true


                              73
Processors
config/messaging.yml

/topics/print: PrintHandler
/queues/popular:
  - PopularHandler
  - AdultObserver:
      filter: "age >= 18"
      concurrency: 5
/queues/students:
  PrintHandler:
    config:
      color: true


                              74
Processors
config/messaging.yml

/topics/print: PrintHandler
/queues/popular:
  - PopularHandler
  - AdultObserver:
      filter: "age >= 18"
      concurrency: 5
/queues/students:
  PrintHandler:
    config:
      color: true


                              75
Processors
app/models/print_handler.rb

include  TorqueBox::Messaging

class  PrintHandler  <  MessageProcessor
    def  on_message(body)
        puts  "Processing  #{body}  of  #{message}"
    end
    def  configure(opts)
        @color  =  opts['color']
    end
end



                                                      76
Queues  (again)


 But  how  do  you  send  a  
 message?



                                77
Queues
example

include  TorqueBox
req  =  Messaging::Queue.new  '/queues/questions'
res  =  Messaging::Queue.new  '/queues/answers'
  
Thread.new  do
    req.publish  "What  time  is  it?"
    puts  res.receive(  :timeout  =>  1000  )
end
  
puts  req.receive
res.publish  Time.now



                                                    78
Queues
example

include  TorqueBox
req  =  Messaging::Queue.new  '/queues/questions'
res  =  Messaging::Queue.new  '/queues/answers'
  
Thread.new  do
    req.publish  "What  time  is  it?"
    puts  res.receive(  :timeout  =>  1000  )
end
  
puts  req.receive
res.publish  Time.now



                                                    79
Queues
example

include  TorqueBox
req  =  Messaging::Queue.new  '/queues/questions'
res  =  Messaging::Queue.new  '/queues/answers'
  
Thread.new  do
    req.publish  "What  time  is  it?"
    puts  res.receive(  :timeout  =>  1000  )
end
  
puts  req.receive
res.publish  Time.now



                                                    80
Queues
example

include  TorqueBox
req  =  Messaging::Queue.new  '/queues/questions'
res  =  Messaging::Queue.new  '/queues/answers'
  
Thread.new  do
    req.publish  "What  time  is  it?"
    puts  res.receive(  :timeout  =>  1000  )
end
  
puts  req.receive
res.publish  Time.now



                                                    81
Queues
“on  the  fly”



include  TorqueBox

queue  =  Messaging::Queue.new  '/queues/foo'
queue.create
    ...  
queue.destroy




                                                82
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.yml  to  define  topics
•   use  TorqueBox::Messaging::Topic


                                                   83
Scheduling
get regular later




                    84
Jobs
app/jobs/newsletter_sender.rb

class  NewsletterSender
  
    def  run()
        subscriptions  =  Subscription.find(:all)
        subscriptions.each  do  |e|
            send_newsletter(  e  )
        end
    end
  
end



                                                    85
Jobs
config/jobs.yml

monthly_newsletter:
    description:  first  of  month
    job:  NewsletterSender
    cron:  ‘0  0  0  1  *  ?’

sandbox:
    job:  Sandbox
    cron:  ‘*/5  *  *  *  *  ?’


                                     86
Jobs
 “Fire  every  half  hour  from  10am  until  1pm  
     on  the  third  Friday  of  each  month”

  0      */30 10-13        ?      *      FRI#3

Seconds Minutes   Hours   DOM    Month   DOW     Year

                                          1-7
                                 1-12            1970-
                          1-31           SUN-
 0-59    0-59     0-23           JAN-            2099
                          ?LW            SAT
                                 DEC             empty
                                         ?L#


                                                         87
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  rails  environment  loaded  and  
    available.


                                                 88
Services
run along, lil’ daemon




                         89
Services

Long-­running,  non-­web  
“daemons”  that  share  the  
runtime  environment  and  
deployment  lifecycle  of  
your  app.


                                90
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.yml


                                                 91
Services
config/services.yml


IrcBot:
    server:  freenode.net
    channel:  #torquebox
    publish:  /topics/irc

MyMudServer:

SomeOtherService:



                            92
Services
app/{models,etc}/my_service.rb

class  MyService
    def  initialize  opts={}
        name  =  opts[:publish]
        @queue  =  Messaging::Queue.new(name)
    end
    def  start  
        Thread.new  {  run  }  
    end
    def  stop  
        @done  =  true
    end
end


                                                93
Services
app/{models,etc}/my_service.rb

class  MyService
    def  initialize  opts={}
        name  =  opts[:publish]
        @queue  =  Messaging::Queue.new(name)
    end
    def  start  
        Thread.new  {  run  }  
    end
    def  stop  
        @done  =  true
    end
end


                                                94
Services
app/{models,etc}/my_service.rb

class  MyService
    def  initialize  opts={}
        name  =  opts[:publish]
        @queue  =  Messaging::Queue.new(name)
    end
    def  start  
        Thread.new  {  run  }  
    end
    def  stop  
        @done  =  true
    end
end


                                                95
Services
app/{models,etc}/my_service.rb

class  MyService
    def  initialize  opts={}
        name  =  opts[:publish]
        @queue  =  Messaging::Queue.new(name)
    end
    def  start  
        Thread.new  {  run  }  
    end
    def  stop  
        @done  =  true
    end
end


                                                96
Services
app/{models,etc}/my_service.rb


class  MyService
    def  run
        until  @done
            @queue.publish(Time.now)
            sleep(1)  
        end
    end
end



                                       97
Services
app/{models,etc}/my_service.rb


class  MyService
    def  run
        until  @done
            @queue.publish(Time.now)
            sleep(1)  
        end
    end
end



                                       98
Services
app/services/evented_service.rb

class  EventedService
    def  initialize  opts={}
        @opts  =  opts
    end
    def  start  
        Thread.new  {  EventMachine.run  {...}  }
    end
    def  stop  
        EventMachine.stop
    end
end


                                                    99
Clustering
less failure faster




                      100
out-­of-­the-­box
• JBoss  provides
 • session  replication
 • load-­balanced  messaging
• mod_cluster  provides
 • session  affinity
 • intelligent  load-­balanced  web
 • failover
                                      101
JBOSS_CONF
TorqueBox  ships  with  two  
JBoss  server  configurations:  
default  (not  clustered)  and  all  
(clustered).  To  enable  
clustering...

$  export  JBOSS_CONF=all

                                        102
deploy  and  run


$  export  JBOSS_CONF=all
$  jruby  -­S  rake  torquebox:deploy
$  jruby  -­S  rake  torquebox:run



                                        103
mod_cluster
A  reverse  proxy  implemented  
as  an  Apache  module  with  
JBoss  awareness.  Constantly  
gathers  load  statistics  and  
deployment  availability  for  
intelligent  request  distribution.


                                      104
mod_cluster




              105
mod_cluster

• Dynamic  configuration
• Server-­side  load  factor  calculation
• Fine-­grained  web  app  lifecycle
• AJP  (Apache  JServ  Protocol)  is  
  optional.  HTTP[S]  is  also  supported.



                                             106
Future
coming soon




              107
Future
• Performance  benchmarking  and  
  optimization
• Infinispan  for  ActiveSupport::Cache  
  and  NoSQL  persistence
• JBoss  SSO,  HASingleton,  logging
• CDI  injection  of  Java  components  into  
  Ruby
• More  JavaEE  bridged  to  Ruby  where  
  it  makes  sense,  e.g.  BPM,  Drools,  
  Transactions,  etc.

                                                 108
Resources

• http://torquebox.org
• #torquebox  on  freenode
• https://github.com/torquebox
• http://twitter.com/torquebox
• http://projectodd.org

                                 109
Thanks!
questions?




             110

Weitere ähnliche Inhalte

Was ist angesagt?

Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010Arun Gupta
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stackKris Buytaert
 
Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)Stoyan Zhekov
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
Java EE Servlet JSP Tutorial- Cookbook 1
Java EE Servlet JSP Tutorial- Cookbook 1Java EE Servlet JSP Tutorial- Cookbook 1
Java EE Servlet JSP Tutorial- Cookbook 1billdigman
 
Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2billdigman
 
Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Arun Gupta
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django ArchitectureRami Sayar
 
Developing web applications in 2010
Developing web applications in 2010Developing web applications in 2010
Developing web applications in 2010Ignacio Coloma
 
Resin Outperforms NginX
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginXbilldigman
 
Enterprise Maven Repository BOF
Enterprise Maven Repository BOFEnterprise Maven Repository BOF
Enterprise Maven Repository BOFMax Andersen
 
What is Rack Hijacking API
What is Rack Hijacking APIWhat is Rack Hijacking API
What is Rack Hijacking APINomo Kiyoshi
 
Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Shaer Hassan
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring RailsJonathan Weiss
 
Merb The Super Bike Of Frameworks
Merb The Super Bike Of FrameworksMerb The Super Bike Of Frameworks
Merb The Super Bike Of FrameworksRowan Hick
 
A web perf dashboard up & running in 90 minutes presentation
A web perf dashboard up & running in 90 minutes presentationA web perf dashboard up & running in 90 minutes presentation
A web perf dashboard up & running in 90 minutes presentationJustin Dorfman
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Arun Gupta
 

Was ist angesagt? (20)

Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
Getting Started with Rails on GlassFish (Hands-on Lab) - Spark IT 2010
 
Scaling Django
Scaling DjangoScaling Django
Scaling Django
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stack
 
Ruby off Rails (english)
Ruby off Rails (english)Ruby off Rails (english)
Ruby off Rails (english)
 
How Flipkart scales PHP
How Flipkart scales PHPHow Flipkart scales PHP
How Flipkart scales PHP
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
Java EE Servlet JSP Tutorial- Cookbook 1
Java EE Servlet JSP Tutorial- Cookbook 1Java EE Servlet JSP Tutorial- Cookbook 1
Java EE Servlet JSP Tutorial- Cookbook 1
 
Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2Java EE Servlet/JSP Tutorial- Cookbook 2
Java EE Servlet/JSP Tutorial- Cookbook 2
 
Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010
 
Scalable Django Architecture
Scalable Django ArchitectureScalable Django Architecture
Scalable Django Architecture
 
Developing web applications in 2010
Developing web applications in 2010Developing web applications in 2010
Developing web applications in 2010
 
Resin Outperforms NginX
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginX
 
Enterprise Maven Repository BOF
Enterprise Maven Repository BOFEnterprise Maven Repository BOF
Enterprise Maven Repository BOF
 
What is Rack Hijacking API
What is Rack Hijacking APIWhat is Rack Hijacking API
What is Rack Hijacking API
 
Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring Rails
 
Merb The Super Bike Of Frameworks
Merb The Super Bike Of FrameworksMerb The Super Bike Of Frameworks
Merb The Super Bike Of Frameworks
 
A web perf dashboard up & running in 90 minutes presentation
A web perf dashboard up & running in 90 minutes presentationA web perf dashboard up & running in 90 minutes presentation
A web perf dashboard up & running in 90 minutes presentation
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014
 

Ähnlich wie Crank Up Your Apps With TorqueBox

Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Lance Ball
 
Jaoo Michael Neale 09
Jaoo Michael Neale 09Jaoo Michael Neale 09
Jaoo Michael Neale 09Michael Neale
 
JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloudelliando dias
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudHiro Asari
 
JRuby in the enterprise
JRuby in the enterpriseJRuby in the enterprise
JRuby in the enterpriseJerry Gulla
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 
A jar-nORM-ous Task
A jar-nORM-ous TaskA jar-nORM-ous Task
A jar-nORM-ous TaskErin Dees
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Nilesh Panchal
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the worldHiroshi SHIBATA
 
JVMs in Containers - Best Practices
JVMs in Containers - Best PracticesJVMs in Containers - Best Practices
JVMs in Containers - Best PracticesDavid Delabassee
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaKeith Bennett
 
JBoss Developer Webinar: Cloud: BoxGrinder & SteamCannon
JBoss Developer Webinar: Cloud: BoxGrinder & SteamCannonJBoss Developer Webinar: Cloud: BoxGrinder & SteamCannon
JBoss Developer Webinar: Cloud: BoxGrinder & SteamCannonbobmcwhirter
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Coursepeter_marklund
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With RpmMartin Jackson
 
Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?Adam Hodowany
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentationasync_io
 

Ähnlich wie Crank Up Your Apps With TorqueBox (20)

Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011Torquebox Asheville.rb April 2011
Torquebox Asheville.rb April 2011
 
Jaoo Michael Neale 09
Jaoo Michael Neale 09Jaoo Michael Neale 09
Jaoo Michael Neale 09
 
JBoss, Rails and the cloud
JBoss, Rails and the cloudJBoss, Rails and the cloud
JBoss, Rails and the cloud
 
JRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the CloudJRuby, Ruby, Rails and You on the Cloud
JRuby, Ruby, Rails and You on the Cloud
 
JVMs in Containers
JVMs in ContainersJVMs in Containers
JVMs in Containers
 
JRuby in the enterprise
JRuby in the enterpriseJRuby in the enterprise
JRuby in the enterprise
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
A jar-nORM-ous Task
A jar-nORM-ous TaskA jar-nORM-ous Task
A jar-nORM-ous Task
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the world
 
JVMs in Containers - Best Practices
JVMs in Containers - Best PracticesJVMs in Containers - Best Practices
JVMs in Containers - Best Practices
 
Jruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
 
Play framework
Play frameworkPlay framework
Play framework
 
JBoss Developer Webinar: Cloud: BoxGrinder & SteamCannon
JBoss Developer Webinar: Cloud: BoxGrinder & SteamCannonJBoss Developer Webinar: Cloud: BoxGrinder & SteamCannon
JBoss Developer Webinar: Cloud: BoxGrinder & SteamCannon
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
 
Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?Ruby on Rails and Docker - Why should I care?
Ruby on Rails and Docker - Why should I care?
 
Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
 

Crank Up Your Apps With TorqueBox

  • 1. Crank Up Your Apps With Jim Crossley MagicRuby Creative  Commons  BY-­SA  3.0 Feb 2011 1
  • 2. Jim  who? • “recovering  java  architect” • java  since  ’96,  ruby  since  ’06 • emacs  and  guitars  since  forever • Red  Hat  Senior  Engineer   • proud  member  of 2
  • 3. 3
  • 5. Agenda • High-­level  BS  and  Development   Process • Web,  Messaging,  Scheduling,   Services,  Clustering 5
  • 6. TorqueBox the power of JBoss with the expressiveness of Ruby 6
  • 7. TorqueBox:  what? • A  “real”  app  server  for  Ruby • Founded  in  2008 • Bob’s  “labor  of  love” • 100%  open-­source,  LGPL  license • Reflects  a  strong  commitment  to   Ruby  from  Red  Hat 7
  • 8. TorqueBox:  why? • “Native”  support  for  Rack  apps • Built-­in  background  processing • Built-­in  scheduling • Built-­in  clustering • Easily  scalable • Optionally  enterprisey 8
  • 9. JRuby a good idea done well 9
  • 10. JRuby:  why? • Very  fast  runtime • Real  threads • Java  libraries • Java  tools • Healthy  community 10
  • 11. JRuby:  why  not? • Slower  start  up • Native  gems • FFI • C  extension  support • Some  Ruby  libs  not  thread-­safe 11
  • 12. JBoss  AS but before we get to that... 12
  • 13. Enterprise  Java misconceptions 13
  • 15. Acronymious? WAR JAXBEAR JSTL SLSB JSF JNLPJTA JPA   JNI JCK JAX-­RPC JDOM JAXP JAX-­WS JSE JEE JMM JTS JWS NIO JDO AWT   JMX JLS JAR JRE JCP   JSR JNDI JSP SAF EJB JME POJO JMSJDBC   JDK JVM JAX-­RS JPQL NPE 15
  • 16. Bloated? 16
  • 18. Enterprise  Java  is  all  that and more! but... 18
  • 19. I  promise... • No  XML   • No  Java  * • No  war  files  * • Only  Ruby,  YAML  and... * Unless you really want to 19
  • 20. JBoss  AS the enterprisey good parts 20
  • 21. JBoss  AS6 • Tomcat  for  web • Infinispan  for  caching • HornetQ  for  messaging • Quartz  for  scheduling • mod_cluster  for  clustering 21
  • 22. 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 22
  • 23. Hot  Deployment $JBOSS_HOME/server/default/deploy/ • anything  added  to  deploy/   will  get  deployed • anything  removed  from   deploy/  will  get   undeployed • anything  updated  in   deploy/  will  get  redeployed • TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives 23
  • 24. Hot  Deployment $JBOSS_HOME/server/default/deploy/ • deployment   anything  added  to  deploy/   will  get  deployed descriptors • anything  removed  from   deploy/  will  get   undeployed • anything  updated  in   deploy/  will  get  redeployed • TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives 24
  • 25. Hot  Deployment $JBOSS_HOME/server/default/deploy/ • anything  added  to  deploy/   will  get  deployed • anything  removed  from   deploy/  will  get   undeployed • anything  updated  in   zip  files   deploy/  will  get  redeployed • (archives) TorqueBox  deployers   make  JBoss  grok  YAML   and  ruby  archives 25
  • 26. Development  Process how do they work? 26
  • 27. easy  install $  wget  http://torquebox.org/torquebox-­dev.zip $  unzip  torquebox-­dev.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 27
  • 28. easy  install $  wget  http://torquebox.org/torquebox-­dev.zip $  unzip  torquebox-­dev.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 28
  • 29. easy  install $  wget  http://torquebox.org/torquebox-­dev.zip $  unzip  torquebox-­dev.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 29
  • 30. easy  install $  wget  http://torquebox.org/torquebox-­dev.zip $  unzip  torquebox-­dev.zip Make  sure  the  jruby   found  in  your  path  is  in   $JRUBY_HOME/bin. $  export  TORQUEBOX_HOME=$PWD/torquebox-­1* $  export  JBOSS_HOME=$TORQUEBOX_HOME/jboss $  export  JRUBY_HOME=$TORQUEBOX_HOME/jruby $  export  PATH=$JRUBY_HOME/bin:$PATH 30
  • 31. easy  install $  jruby  -­S  gem  install  bundler $  jruby  -­S  gem  install  rails $  jruby  -­S  gem  install  sinatra 31
  • 33. 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 33
  • 34. 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. 34
  • 35. deployment  descriptors torquebox:deploy  creates   a  deployment  descriptor  in  the   JBoss  deploy/  directory 35
  • 36. deployment  descriptors deploy/myapp-­{rails,rack}.yml application: root: /path/to/myapp env: development web: context: myapp host: www.yourhost.com static: public rackup: config.ru environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com 36
  • 37. deployment  descriptors deploy/myapp-­{rails,rack}.yml application: root: /path/to/myapp env: development web: context: myapp The  fully-­qualified   host: www.yourhost.com path  to  the  app.     static: public This  will  be  the  value   rackup: config.ru environment: of  either   RAILS_ROOT  or   MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com RACK_ROOT 37
  • 38. deployment  descriptors deploy/myapp-­{rails,rack}.yml application: root: /path/to/myapp env: development web: context: myapp host: www.yourhost.comThe  runtime  mode  of   static: public the  app.    This  will  be   rackup: config.ru environment: either  RAILS_ENV   MAIL_HOST: mail.yourhost.comor  RACK_ENV REPLY_TO: you@yourhost.com 38
  • 39. deployment  descriptors The  app’s  context  path   deploy/myapp-­{rails,rack}.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 rackup: config.ru environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com 39
  • 40. deployment  descriptors deploy/myapp-­{rails,rack}.yml application: root: /path/to/myapp A  list  of  virtual   env: development hostnames  to  which   web: to  bind  the  app. context: myapp host: www.yourhost.com static: public rackup: config.ru environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com 40
  • 41. deployment  descriptors deploy/myapp-­{rails,rack}.yml application: root: /path/to/myapp env: development web: The  location  of  the   context: myapp app’s  static   host: www.yourhost.com content,  either   static: public absolute  or  relative   rackup: config.ru to  the  app’s  root. environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com 41
  • 42. deployment  descriptors deploy/myapp-­{rails,rack}.yml application: root: /path/to/myapp env: development web: The  name  of  the   context: myapp rackup  script  used  to   host: www.yourhost.com boot  your  app static: public rackup: config.ru environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com 42
  • 43. deployment  descriptors deploy/myapp-­{rails,rack}.yml application: root: /path/to/myapp env: development Any  environment   web: variables  required   context: myapp by  the  app. host: www.yourhost.com static: public rackup: config.ru environment: MAIL_HOST: mail.yourhost.com REPLY_TO: you@yourhost.com 43
  • 44. deployment  descriptors • config/torquebox.yml   • internal  descriptors  have  the   same  structure  as  the   external  ones  in  deploy/ • may  be  used  to  provide  your   own  reasonable  defaults 44
  • 46. 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 46
  • 47. database  connectivity Gemfile gem  "activerecord-­jdbc-­adapter" gem  "jdbc-­postgres" #  gem  "jdbc-­sqlite3" #  gem  "jdbc-­mysql" 47
  • 48. rails  template • Adds  TorqueBox  rake  tasks • Adds  the  JDBC  sqlite3  gems • Adds  TorqueBox  session_store • Adds  Backgroundable  module 48
  • 49. my  first  rails  app $  jruby  -­S  rails  new  myapp  -­m          $TORQUEBOX_HOME/share/rails/template.rb $  cd  myapp $  jruby  -­S  bundle  install $  jruby  -­S  rake  torquebox:deploy 49
  • 51. lots  of  options RabbitMQ Resque cron BackgroundDRb workling CronEdit BackgroundJob Kestral rufus-scheduler JobFu Ap4r Amazon SQS async_observer Taskr Sparrow Background-Fu beanstalkd DelayedJob RailsCron Open4 Conveyor WorkerQueue daemons rake ActiveMQ starling Spawn ActiveMessaging 51
  • 52. TorqueBox::Messaging • JMS  (Java  Message  Service)   is  an  API  for  messaging • implementation HornetQ  is  the  JBoss  JMS   52
  • 53. TorqueBox::Messaging • Task • Backgroundable • MessageProcessor • Queue • Topic 53
  • 54. TorqueBox::Messaging • No  extra  tables  in  your  database • No  external  system  to  manage • Little  to  no  config  required  at  all • No  redeploy  necessary  in  dev  mode • Efficient  loading  of  rails  environment • Automatic  load  balancing  and  retries • Works  on  Windows,  if  you  care 54
  • 55. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  payload[:person]          person  ||=  Person.find_by_id(payload[:id])        if  person            #  send  the  email            person.welcomed  =  true            person.save!        end    end end 55
  • 56. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  payload[:person]          person  ||=  Person.find_by_id(payload[:id])        if  person            #  send  the  email            person.welcomed  =  true            person.save!        end    end end 56
  • 57. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  payload[:person]          person  ||=  Person.find_by_id(payload[:id])        if  person            #  send  the  email            person.welcomed  =  true            person.save!        end    end end 57
  • 58. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  payload[:person]          person  ||=  Person.find_by_id(payload[:id])        if  person            #  send  the  email            person.welcomed  =  true            person.save!        end    end end 58
  • 59. Tasks app/tasks/email_task.rb class  EmailTask  <  TorqueBox::Messaging::Task    def  welcome(payload)        person  =  payload[:person]          person  ||=  Person.find_by_id(payload[:id])        if  person            #  send  the  email            person.welcomed  =  true            person.save!        end    end end 59
  • 60. 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 60
  • 61. 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 61
  • 62. Tasks Call  them  from  your   controllers,  models,  and   observers,  or  even  other   tasks.  Even  in  non-­Rails   apps! 62
  • 63. Backgroundable Inspired  by  DelayedJob’s   handle_asynchronously,   it’s  trivial  to  create  implicit   background  Tasks. 63
  • 64. 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 64
  • 65. 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 65
  • 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 66
  • 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 67
  • 68. Backgroundable app/models/slow_poke.rb class  SlowPoke  <  ActiveRecord::Base    def  takes_forever;;  end    def  might_take_awhile;;  end end SlowPoke.always_background  :takes_forever @slowpoke.takes_forever @slowpoke.background.might_take_awhile 68
  • 69. Queues Tasks  are  built  on  top  of   Queues.    Of  course,  you  may   build  your  own  “MOM”  apps   by  defining  your  own  Queues,   Topics,  and  their  message   Processors  yourself. 69
  • 71. Processors You  can  create  a  processor   class  to  receive  messages   from  a  Topic  or  Queue 71
  • 72. Processors config/messaging.yml /topics/print: PrintHandler /queues/popular: - PopularHandler - AdultObserver: filter: "age >= 18" concurrency: 5 /queues/students: PrintHandler: config: color: true 72
  • 73. Processors config/messaging.yml /topics/print: PrintHandler /queues/popular: - PopularHandler - AdultObserver: filter: "age >= 18" concurrency: 5 /queues/students: PrintHandler: config: color: true 73
  • 74. Processors config/messaging.yml /topics/print: PrintHandler /queues/popular: - PopularHandler - AdultObserver: filter: "age >= 18" concurrency: 5 /queues/students: PrintHandler: config: color: true 74
  • 75. Processors config/messaging.yml /topics/print: PrintHandler /queues/popular: - PopularHandler - AdultObserver: filter: "age >= 18" concurrency: 5 /queues/students: PrintHandler: config: color: true 75
  • 76. Processors app/models/print_handler.rb include  TorqueBox::Messaging class  PrintHandler  <  MessageProcessor    def  on_message(body)        puts  "Processing  #{body}  of  #{message}"    end    def  configure(opts)        @color  =  opts['color']    end end 76
  • 77. Queues  (again) But  how  do  you  send  a   message? 77
  • 78. Queues example include  TorqueBox req  =  Messaging::Queue.new  '/queues/questions' res  =  Messaging::Queue.new  '/queues/answers'   Thread.new  do    req.publish  "What  time  is  it?"    puts  res.receive(  :timeout  =>  1000  ) end   puts  req.receive res.publish  Time.now 78
  • 79. Queues example include  TorqueBox req  =  Messaging::Queue.new  '/queues/questions' res  =  Messaging::Queue.new  '/queues/answers'   Thread.new  do    req.publish  "What  time  is  it?"    puts  res.receive(  :timeout  =>  1000  ) end   puts  req.receive res.publish  Time.now 79
  • 80. Queues example include  TorqueBox req  =  Messaging::Queue.new  '/queues/questions' res  =  Messaging::Queue.new  '/queues/answers'   Thread.new  do    req.publish  "What  time  is  it?"    puts  res.receive(  :timeout  =>  1000  ) end   puts  req.receive res.publish  Time.now 80
  • 81. Queues example include  TorqueBox req  =  Messaging::Queue.new  '/queues/questions' res  =  Messaging::Queue.new  '/queues/answers'   Thread.new  do    req.publish  "What  time  is  it?"    puts  res.receive(  :timeout  =>  1000  ) end   puts  req.receive res.publish  Time.now 81
  • 82. Queues “on  the  fly” include  TorqueBox queue  =  Messaging::Queue.new  '/queues/foo' queue.create    ...   queue.destroy 82
  • 83. 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.yml  to  define  topics • use  TorqueBox::Messaging::Topic 83
  • 85. Jobs app/jobs/newsletter_sender.rb class  NewsletterSender      def  run()        subscriptions  =  Subscription.find(:all)        subscriptions.each  do  |e|            send_newsletter(  e  )        end    end   end 85
  • 86. Jobs config/jobs.yml monthly_newsletter:    description:  first  of  month    job:  NewsletterSender    cron:  ‘0  0  0  1  *  ?’ sandbox:    job:  Sandbox    cron:  ‘*/5  *  *  *  *  ?’ 86
  • 87. Jobs “Fire  every  half  hour  from  10am  until  1pm   on  the  third  Friday  of  each  month” 0 */30 10-13 ? * FRI#3 Seconds Minutes Hours DOM Month DOW Year 1-7 1-12 1970- 1-31 SUN- 0-59 0-59 0-23 JAN- 2099 ?LW SAT DEC empty ?L# 87
  • 88. 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  rails  environment  loaded  and   available. 88
  • 90. Services Long-­running,  non-­web   “daemons”  that  share  the   runtime  environment  and   deployment  lifecycle  of   your  app. 90
  • 91. 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.yml 91
  • 92. Services config/services.yml IrcBot:    server:  freenode.net    channel:  #torquebox    publish:  /topics/irc MyMudServer: SomeOtherService: 92
  • 93. Services app/{models,etc}/my_service.rb class  MyService    def  initialize  opts={}        name  =  opts[:publish]        @queue  =  Messaging::Queue.new(name)    end    def  start          Thread.new  {  run  }      end    def  stop          @done  =  true    end end 93
  • 94. Services app/{models,etc}/my_service.rb class  MyService    def  initialize  opts={}        name  =  opts[:publish]        @queue  =  Messaging::Queue.new(name)    end    def  start          Thread.new  {  run  }      end    def  stop          @done  =  true    end end 94
  • 95. Services app/{models,etc}/my_service.rb class  MyService    def  initialize  opts={}        name  =  opts[:publish]        @queue  =  Messaging::Queue.new(name)    end    def  start          Thread.new  {  run  }      end    def  stop          @done  =  true    end end 95
  • 96. Services app/{models,etc}/my_service.rb class  MyService    def  initialize  opts={}        name  =  opts[:publish]        @queue  =  Messaging::Queue.new(name)    end    def  start          Thread.new  {  run  }      end    def  stop          @done  =  true    end end 96
  • 97. Services app/{models,etc}/my_service.rb class  MyService    def  run        until  @done            @queue.publish(Time.now)            sleep(1)          end    end end 97
  • 98. Services app/{models,etc}/my_service.rb class  MyService    def  run        until  @done            @queue.publish(Time.now)            sleep(1)          end    end end 98
  • 99. Services app/services/evented_service.rb class  EventedService    def  initialize  opts={}        @opts  =  opts    end    def  start          Thread.new  {  EventMachine.run  {...}  }    end    def  stop          EventMachine.stop    end end 99
  • 101. out-­of-­the-­box • JBoss  provides • session  replication • load-­balanced  messaging • mod_cluster  provides • session  affinity • intelligent  load-­balanced  web • failover 101
  • 102. JBOSS_CONF TorqueBox  ships  with  two   JBoss  server  configurations:   default  (not  clustered)  and  all   (clustered).  To  enable   clustering... $  export  JBOSS_CONF=all 102
  • 103. deploy  and  run $  export  JBOSS_CONF=all $  jruby  -­S  rake  torquebox:deploy $  jruby  -­S  rake  torquebox:run 103
  • 104. mod_cluster A  reverse  proxy  implemented   as  an  Apache  module  with   JBoss  awareness.  Constantly   gathers  load  statistics  and   deployment  availability  for   intelligent  request  distribution. 104
  • 105. mod_cluster 105
  • 106. mod_cluster • Dynamic  configuration • Server-­side  load  factor  calculation • Fine-­grained  web  app  lifecycle • AJP  (Apache  JServ  Protocol)  is   optional.  HTTP[S]  is  also  supported. 106
  • 108. Future • Performance  benchmarking  and   optimization • Infinispan  for  ActiveSupport::Cache   and  NoSQL  persistence • JBoss  SSO,  HASingleton,  logging • CDI  injection  of  Java  components  into   Ruby • More  JavaEE  bridged  to  Ruby  where   it  makes  sense,  e.g.  BPM,  Drools,   Transactions,  etc. 108
  • 109. Resources • http://torquebox.org • #torquebox  on  freenode • https://github.com/torquebox • http://twitter.com/torquebox • http://projectodd.org 109

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. easy JEE integration\nreplacement for JSF\n
  14. \n
  15. Can also apply ruby tools, e.g. Cucumber and RSpec, to java.\n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. Hot deployment, clustering, caching, messaging, scheduling, transactions, lifecycle management, etc.\n
  70. \n
  71. \n
  72. \n
  73. \n
  74. Ensure you have Java 6 installed\n
  75. Ensure you have Java 6 installed\n
  76. Ensure you have Java 6 installed\n
  77. Ensure you have Java 6 installed\n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. Not imposing JEE arbitrary packaging conventions on ruby just to enjoy the JEE services.\n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. Or integrate with a legacy Java app through its queues.\n
  145. \n
  146. \n
  147. destinations on the left, processors on the right!\n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. Ruby messages being Base64-encoded over JMS String-type messages\n
  158. \n
  159. \n
  160. \n
  161. \n
  162. Should reside beneath app/jobs\nOnly a run() method is required\n
  163. \n
  164. \n
  165. The last day of the month\nThe last weekday of the month\nThe weekday closest to the 15th\n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. \n
  174. \n
  175. \n
  176. \n
  177. \n
  178. Recent articles posted on torquebox.org detailing clustering config\n
  179. reverse proxy / load balancer\n
  180. \n
  181. \n
  182. \n
  183. \n
  184. As server nodes join and leave the cluster, the balancer (mod_cluster) is aware of these changes.\n
  185. \n
  186. \n
  187. \n
  188. \n
  189. \n
  190. \n
  191. \n
  192. \n
  193. \n
  194. *.bat equivalents\nwindows service config\n
  195. \n
  196. \n