Além da fronteira entre Java & Ruby        Creative  Commons  BY-­SA  3.0Friday, November 4, 2011
@abstractj          Java há 12 anos, Ruby n00b          TorqueBox Contributor          DynJS Contributor          Caelum &...
DISCLAIMERFriday, November 4, 2011
Java                   927 JSRS!               nooooooooooooooo!Friday, November 4, 2011
import java.util.Calendar;                           public class Beer {                             private Long beerId; ...
ENTERPRISEFriday, November 4, 2011
JAXR                         Java-FX     JAXP                           JSTL                         StAX JME             ...
Friday, November 4, 2011
Mas escala né?!Friday, November 4, 2011
Scala            Clojure                                   Jython                                    JVM                  ...
Ruby     Mais expressiva que Java      class Beer        attr_accessor :beer_id, :description, :created_at      endFriday,...
DRYFriday, November 4, 2011
JRuby                           Java + RubyFriday, November 4, 2011
JRuby    require java    pdf = com.itextpdf.text.Document.new    para = com.itextpdf.text.Paragraph.new Brought to you by ...
“You get true multithreading that                can use all your computer’s cores                from one process, plus a...
Server SideFriday, November 4, 2011
Ruby App                             Sinatra      Rails                                   Rack                            ...
Ruby App                             Sinatra      Rails                                   Rack                            ...
Ruby App                                      Sinatra      Rails                                            Rack          ...
Ruby App                                      Sinatra      Rails                                            Rack          ...
JBoss     TomcatFriday, November 4, 2011
JBoss     HornetQFriday, November 4, 2011
JBoss     QuartzFriday, November 4, 2011
JBoss     ClusteringFriday, November 4, 2011
TorqueBox                           “The power of JBoss with the                             expressiveness of Ruby”      ...
TorqueBoxFriday, November 4, 2011
Instalação                            TorqueBox do zeroFriday, November 4, 2011
➜ jruby -S gem install torquebox torquebox-capistrano-supportFriday, November 4, 2011
➜ wget http://torquebox.org/builds/LATEST/torquebox-dist-     bin.zip     ➜ unzip torquebox-dist-bin.zip     ➜ export TORQ...
Rails     rails new beer -m $TORQUEBOX_HOME/share/rails/template.rbFriday, November 4, 2011
Estrutura     Diretórios do TorqueBoxFriday, November 4, 2011
Rake tasks      rake torquebox:deploy      rake torquebox:undeploy      rake torquebox:runFriday, November 4, 2011
Deployment                           Make knobs, not WAR!Friday, November 4, 2011
beer-knob.yml     application:      root: /Users/Bruno/rubyconfbr/beer      environment: developmentFriday, November 4, 2011
Friday, November 4, 2011
AplicaçãoFriday, November 4, 2011
source "http://torquebox.org/2x/builds/584/gem-                           repo"                           source http://ru...
Web                           Rack, Sinatra, RailsFriday, November 4, 2011
Caching     class BeersController < ApplicationController        caches_action :most_popular, :expires_in => 30.seconds   ...
Friday, November 4, 2011
Clustering     ➜ torquebox run --clusteredFriday, November 4, 2011
Internals     class TorqueBoxCommand < Thor      TASK_ORDER = %w(deploy undeploy start cli env help)      map "run" => "st...
Cache distribuído!Friday, November 4, 2011
mod_clusterFriday, November 4, 2011
Infinispan                             CachingFriday, November 4, 2011
Invalidation                            Cache     Cache                           Server1   Server2Friday, November 4, 2011
Invalidation                                     Notificação                            Cache                  Cache       ...
../config/application.rb     module Beer      class Application < Rails::Application       config.cache_store = :torque_box_...
Replicated                                             Cache                                            Server2           ...
../config/application.rb     module Beer      class Application < Rails::Application       config.cache_store = :torque_box_...
Scheduling                           Agendamento de JobsFriday, November 4, 2011
Internals      public class RubyJobProxy implements Job {           @Override           public void execute(JobExecutionCo...
Internals      public class RubyJobProxy implements Job {           @Override           public void execute(JobExecutionCo...
../app/jobs     class JobDemo         def initialize          #Codigo de inicializacao         end      def run       # O ...
../config/torquebox.yml     jobs:      sync_agenda:       job: JobDemo       cron: 0 0 12 * * ?     endFriday, November 4, ...
Mensageria     Java Messaging Service + HornetQFriday, November 4, 2011
O Ministério da Saúde adverte:                      NOSQL COMO MENSAGERIA                                PODE             ...
Greenfield                                  REST + NoSQL                                  Request/Responsext               ...
Real World                                   Nobody Cares!                                    Request/Responsext          ...
../config/torquebox.yml     /topics/beerTopic     /queues/queueBeer:Friday, November 4, 2011
Tasks     class EmailerTask < TorqueBox::Messaging::Task      def send_welcome(payload)       to = "#{payload[:name]} <#{p...
Tasks     class UserController < ApplicationController      def register       user = User.new(params[:user])       Emaile...
Processors     include TorqueBox::Messaging     class PrintHandler < MessageProcessor       def on_message(body)         p...
Queues     include TorqueBox     req = Messaging::Queue.new /queues/questions     res = Messaging::Queue.new /queues/answe...
FutureFriday, November 4, 2011
Future     class EmailerTask      def send_welcome(payload)       to = "#{payload[:name]} <#{payload[:address]}>"       # ...
Future     class EmailerTask         include TorqueBox::Messaging::Backgroundable         always_background :send_welcome ...
Future       future = @emailTask.send_welcome(:send_welcome)       future.started?       future.complete?       future.err...
ServicesFriday, November 4, 2011
Services     class BeerService      def initialize       @queue = Messaging::Queue.new(“beer”)      end      def start    ...
Singleton Services                                     Clustered                           Server1                  Server...
Singleton Services                                     Clustered                           Server1                  Server...
Services     ➜ torquebox run --clustered     ../config/torquebox.yml     services:      BeerService:       singleton: true ...
CDI                           Injeção de dependênciasFriday, November 4, 2011
Pra quê?Friday, November 4, 2011
Java     package br.com.rubyconf;     public class Beer {       //gets e sets       public void say(String message) { // E...
Ruby     class BeerController < ApplicationController          include TorqueBox::Injectors          def create           ...
JNDI    class MyService     include TorqueBox::Injectors     def initialize opts={}      @factory = inject("java:comp/env/...
Destinations      class MyService       include TorqueBox::Injectors       def initialize opts={}        @inbound = inject...
Outras features     Autenticação + Websockets + XA (2PC)Friday, November 4, 2011
BackStageFriday, November 4, 2011
Stomp Box                           TorqueBox deployment supportFriday, November 4, 2011
Friday, November 4, 2011
Comunidade           irc.freenode.net #torquebox           http://torquebox.org           http://github.com/torquebox     ...
Obrigado!                                                  @abstractj                                         http://githu...
Upcoming SlideShare
Loading in...5
×

TorqueBox - Ultrapassando a fronteira entre Java e Ruby

2,213

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,213
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

TorqueBox - Ultrapassando a fronteira entre Java e Ruby

  1. 1. Além da fronteira entre Java & Ruby Creative  Commons  BY-­SA  3.0Friday, November 4, 2011
  2. 2. @abstractj Java há 12 anos, Ruby n00b TorqueBox Contributor DynJS Contributor Caelum & ConcreteSFriday, November 4, 2011
  3. 3. DISCLAIMERFriday, November 4, 2011
  4. 4. Java 927 JSRS! nooooooooooooooo!Friday, November 4, 2011
  5. 5. import java.util.Calendar; public class Beer { private Long beerId; private String description; private Calendar createdAt; public Long getBeerId() { return beerId; } public void setBeerId(Long beerId) {Expressiva? } this.beerId = beerId; public String getDescription() { return description; } public void setDescription(String description) this.description = description; } public Calendar getCreatedAt() { return createdAt; } public void setCreatedAt(Calendar createdAt) this.createdAt = createdAt; }Friday, November 4, 2011 }
  6. 6. ENTERPRISEFriday, November 4, 2011
  7. 7. JAXR Java-FX JAXP JSTL StAX JME JDOM JVM JAX-RPC EJB AWT JMX Swing EAR Struts JAAS JCP JavaBean NPE Spring JAX-WS ENTERPRISE RMI JSE JNI JNDI NIO SOA JSP JSF JAXB WAR JDO JAX-RS JPQL JAF POJO EJBQL JRE JEEFriday, November 4, 2011
  8. 8. Friday, November 4, 2011
  9. 9. Mas escala né?!Friday, November 4, 2011
  10. 10. Scala Clojure Jython JVM DynJS Rhino GroovyFriday, November 4, 2011
  11. 11. Ruby Mais expressiva que Java class Beer attr_accessor :beer_id, :description, :created_at endFriday, November 4, 2011
  12. 12. DRYFriday, November 4, 2011
  13. 13. JRuby Java + RubyFriday, November 4, 2011
  14. 14. JRuby require java pdf = com.itextpdf.text.Document.new para = com.itextpdf.text.Paragraph.new Brought to you by JRuby file = java.io.FileOutputStream.new pdf_demo.pdf com.itextpdf.text.pdf.PdfWriter.get_instance pdf, file pdf.open pdf.add para pdf.closeFriday, November 4, 2011
  15. 15. “You get true multithreading that can use all your computer’s cores from one process, plus a virtual machine that’s been tuned for a decade and a half.” Using JRuby - Bringing Ruby to JavaFriday, November 4, 2011
  16. 16. Server SideFriday, November 4, 2011
  17. 17. Ruby App Sinatra Rails Rack Passenger/Thin Apache/NginxFriday, November 4, 2011
  18. 18. Ruby App Sinatra Rails Rack Passenger/Thin Jobs Apache/Nginx crondFriday, November 4, 2011
  19. 19. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crondFriday, November 4, 2011
  20. 20. Ruby App Sinatra Rails Rack Tasks Passenger/Thin Jobs Resque/ DelayedJob Apache/Nginx crond Daemons god/monitFriday, November 4, 2011
  21. 21. JBoss TomcatFriday, November 4, 2011
  22. 22. JBoss HornetQFriday, November 4, 2011
  23. 23. JBoss QuartzFriday, November 4, 2011
  24. 24. JBoss ClusteringFriday, November 4, 2011
  25. 25. TorqueBox “The power of JBoss with the expressiveness of Ruby” Jim Crossley - MagicRuby ConferenceFriday, November 4, 2011
  26. 26. TorqueBoxFriday, November 4, 2011
  27. 27. Instalação TorqueBox do zeroFriday, November 4, 2011
  28. 28. ➜ jruby -S gem install torquebox torquebox-capistrano-supportFriday, November 4, 2011
  29. 29. ➜ wget http://torquebox.org/builds/LATEST/torquebox-dist- bin.zip ➜ unzip torquebox-dist-bin.zip ➜ export TORQUEBOX_HOME=$PWD/torquebox-2.x ➜ export JBOSS_HOME=$TORQUEBOX_HOME/jboss ➜ export JRUBY_HOME=$TORQUEBOX_HOME/jruby ➜ export PATH=$JRUBY_HOME/bin:$PATHFriday, November 4, 2011
  30. 30. Rails rails new beer -m $TORQUEBOX_HOME/share/rails/template.rbFriday, November 4, 2011
  31. 31. Estrutura Diretórios do TorqueBoxFriday, November 4, 2011
  32. 32. Rake tasks rake torquebox:deploy rake torquebox:undeploy rake torquebox:runFriday, November 4, 2011
  33. 33. Deployment Make knobs, not WAR!Friday, November 4, 2011
  34. 34. beer-knob.yml application: root: /Users/Bruno/rubyconfbr/beer environment: developmentFriday, November 4, 2011
  35. 35. Friday, November 4, 2011
  36. 36. AplicaçãoFriday, November 4, 2011
  37. 37. source "http://torquebox.org/2x/builds/584/gem- repo" source http://rubygems.org gem rails, 3.1.1 Gemfile gem activerecord-jdbcsqlite3-adapter gem jruby-openssl gem json gem jquery-rails gem "torquebox-rake-support", "2.x.incremental. 584" gem "torquebox", "2.x.incremental.584"Friday, November 4, 2011
  38. 38. Web Rack, Sinatra, RailsFriday, November 4, 2011
  39. 39. Caching class BeersController < ApplicationController caches_action :most_popular, :expires_in => 30.seconds def most_popular @popular_beers = Beer.most_popular(:limit => 25) end endFriday, November 4, 2011
  40. 40. Friday, November 4, 2011
  41. 41. Clustering ➜ torquebox run --clusteredFriday, November 4, 2011
  42. 42. Internals class TorqueBoxCommand < Thor TASK_ORDER = %w(deploy undeploy start cli env help) map "run" => "start" desc "run", "Run TorqueBox" method_option :clustered, :type => :boolean, :desc => "Run TorqueBox in clustered mode" def start setup_environment TorqueBox::DeployUtils.run_server(:clustered => options.clustered, :max_threads => options[max-threads], :bind_address => options[bind-address]) end endFriday, November 4, 2011
  43. 43. Cache distribuído!Friday, November 4, 2011
  44. 44. mod_clusterFriday, November 4, 2011
  45. 45. Infinispan CachingFriday, November 4, 2011
  46. 46. Invalidation Cache Cache Server1 Server2Friday, November 4, 2011
  47. 47. Invalidation Notificação Cache Cache Server1 Server2 NEW Cache DesatualizadoFriday, November 4, 2011
  48. 48. ../config/application.rb module Beer class Application < Rails::Application config.cache_store = :torque_box_store end endFriday, November 4, 2011
  49. 49. Replicated Cache Server2 Cache Server1 Sync Cache Sync Server2 Cache Server2Friday, November 4, 2011
  50. 50. ../config/application.rb module Beer class Application < Rails::Application config.cache_store = :torque_box_store, {:mode => replicated, :sync =>false} end endFriday, November 4, 2011
  51. 51. Scheduling Agendamento de JobsFriday, November 4, 2011
  52. 52. Internals public class RubyJobProxy implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { Ruby ruby = null; try { ruby = this.runtimePool.borrowRuntime( resolver.getComponentName() ); JobComponent job = (JobComponent)resolver.resolve( ruby ); watchDog(context); job.run(); } catch (Exception e) { throw new JobExecutionException( e ); } finally { if (ruby != null) { this.runtimePool.returnRuntime( ruby ); } } }Friday, November 4, 2011
  53. 53. Internals public class RubyJobProxy implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { Ruby ruby = null; try { ruby = this.runtimePool.borrowRuntime( resolver.getComponentName() ); JobComponent job = (JobComponent)resolver.resolve( ruby ); watchDog(context); job.run(); } catch (Exception e) { throw new JobExecutionException( e ); } finally { if (ruby != null) { this.runtimePool.returnRuntime( ruby ); } } }Friday, November 4, 2011
  54. 54. ../app/jobs class JobDemo def initialize #Codigo de inicializacao end def run # O que você quer executar end endFriday, November 4, 2011
  55. 55. ../config/torquebox.yml jobs: sync_agenda: job: JobDemo cron: 0 0 12 * * ? endFriday, November 4, 2011
  56. 56. Mensageria Java Messaging Service + HornetQFriday, November 4, 2011
  57. 57. O Ministério da Saúde adverte: NOSQL COMO MENSAGERIA PODE TRAZER DANOS A SUA SAÚDE E A DE SEUS FAMILIARESFriday, November 4, 2011
  58. 58. Greenfield REST + NoSQL Request/Responsext NoSQL RAILS APP pub/sub SINATRA APPFriday, November 4, 2011
  59. 59. Real World Nobody Cares! Request/Responsext NoSQL RAILS APP pub/sub MAINFRAMEFriday, November 4, 2011
  60. 60. ../config/torquebox.yml /topics/beerTopic /queues/queueBeer:Friday, November 4, 2011
  61. 61. Tasks class EmailerTask < TorqueBox::Messaging::Task def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # send welcome email to the user end endFriday, November 4, 2011
  62. 62. Tasks class UserController < ApplicationController def register user = User.new(params[:user]) EmailerTask.async(:send_welcome, :address => user.email, :name => user.name) end endFriday, November 4, 2011
  63. 63. Processors include TorqueBox::Messaging class PrintHandler < MessageProcessor   def on_message(body)     puts "Processing #{body} of #{message}"   end   def configure(opts)     @color = opts[color]   end endFriday, November 4, 2011
  64. 64. Queues 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 ) endFriday, November 4, 2011
  65. 65. FutureFriday, November 4, 2011
  66. 66. Future class EmailerTask def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # long running task end endFriday, November 4, 2011
  67. 67. Future class EmailerTask include TorqueBox::Messaging::Backgroundable always_background :send_welcome def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # long running task end endFriday, November 4, 2011
  68. 68. Future future = @emailTask.send_welcome(:send_welcome) future.started? future.complete? future.error? future.result future.result(10000)Friday, November 4, 2011
  69. 69. ServicesFriday, November 4, 2011
  70. 70. Services class BeerService def initialize @queue = Messaging::Queue.new(“beer”) end def start @queue.publish “Testing” end def stop # O que fazer quando o serviço receber um stop end endFriday, November 4, 2011
  71. 71. Singleton Services Clustered Server1 Server2 BeerService BeerServiceFriday, November 4, 2011
  72. 72. Singleton Services Clustered Server1 Server2 BeerService BeerServiceFriday, November 4, 2011
  73. 73. Services ➜ torquebox run --clustered ../config/torquebox.yml services: BeerService: singleton: true endFriday, November 4, 2011
  74. 74. CDI Injeção de dependênciasFriday, November 4, 2011
  75. 75. Pra quê?Friday, November 4, 2011
  76. 76. Java package br.com.rubyconf; public class Beer { //gets e sets public void say(String message) { // Execução do método } } Deploy do jar na aplicação app/ models/ views/ controllers/ lib/beer.jarFriday, November 4, 2011
  77. 77. Ruby class BeerController < ApplicationController include TorqueBox::Injectors def create beer = inject(br.com.rubyconf.Beer ) beer.say “Ruby is for Java” end endFriday, November 4, 2011
  78. 78. JNDI class MyService include TorqueBox::Injectors def initialize opts={} @factory = inject("java:comp/env/jdbc/myDB") end endFriday, November 4, 2011
  79. 79. Destinations class MyService include TorqueBox::Injectors def initialize opts={} @inbound = inject("/topic/beerpub") @outbound = inject("/queue/beer") end endFriday, November 4, 2011
  80. 80. Outras features Autenticação + Websockets + XA (2PC)Friday, November 4, 2011
  81. 81. BackStageFriday, November 4, 2011
  82. 82. Stomp Box TorqueBox deployment supportFriday, November 4, 2011
  83. 83. Friday, November 4, 2011
  84. 84. Comunidade irc.freenode.net #torquebox http://torquebox.org http://github.com/torquebox twitter: @torqueboxFriday, November 4, 2011
  85. 85. Obrigado! @abstractj http://github.com/abstractj Creative  Commons  BY-­SA  3.0Friday, November 4, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×