Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

TorqueBox at GNUnify 2012


Published on

TorqueBox - A complete Ruby Application Server
(GNUnify 2012)
HTML version -

Published in: Technology
  • An HTML version is available here
    Are you sure you want to  Yes  No
    Your message goes here

TorqueBox at GNUnify 2012

  1. 1. Presenting...Saleem Ansaritwitter: tuxdna10th February, 2012 at GNUnify
  2. 2. OutlineWhat is TorqueBox?Polyglot RevolutionTorqueBoxHow to use TorqueBox?FeaturesInstallation and setup: RVM, JRuby, TorqueBoxDeploymentFeatures contd.How to begin hacking TorqueBox?JBoss PolyglotTorqueBox
  3. 3. What is TorqueBox?Before that lets talk about Polyglot Revolution
  4. 4. Polyglot RevolutionJVM is what makes the Polyglot Revolution.
  5. 5. Polyglot Revolution cont.It becomes even more useful in enterprise software, where theprojects involve multiple technologies. As a part of PolyglotRevolution there are a bunch of projects in differentlanguages:TorqueBox (Ruby)Immutant (Clojure)Blacktie (C++)Erjang (Erlang)
  6. 6. back to TorqueBoxStarted in 2009 by Bob McWhirter @bobmcwhirterA complete Ruby Application ServerWhy?ProductivityPower and stability of Java MiddlewareScale on demand
  7. 7. TorqueBox contd.
  8. 8. Built onJRuby / RubyJBoss ASEnterprise Java ( EJB, JMS, Caching etc. )ProvidesMessagingJobsCachingServicesClustering
  9. 9. TorqueBox howto?InstallationRuby, RVM and JRuby1 yum install -y ruby rubygem-rvm2 rvm-install3 [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"4 rvm install jruby-1.6.55 rvm use jruby-1.6.5TorqueBox (prerelease/latest version)1 gem install --pre torquebox2 gem install --pre torquebox-messaging-container3 gem install --pre torquebox-naming-container4 gem install --pre torquebox-capistrano-support5 gem install --pre torquebox-rake-support6 gem install --pre torquebox-vfs7 jruby -J-Xmx1024m -w -S 8 gem install --pre torquebox-server 9 --source
  10. 10. TorqueBox howto?Installation contd.Rails (latest version)1 gem install rails2 gem install bundlerSome caveatsJDBC Drivers for ActiveRecord1 gem install activerecord-jdbcsqlite3-adapter2 gem install activerecord-jdbcmysql-adapter
  11. 11. TorqueBox howto?Create a new Rails application1 rails new rails-app2 cd rails-app3 bundle install4 rails g scaffold Person name:string5 rake db:migrateand deploy!1 torquebox run2 torquebox deploy /path/to/rails-app
  12. 12. Feature: Messaging (via HornetQJMS)Sending Messages:1 timer_queue = timer_queue.publish "Some Message"3 topic1 = topic1.publish "Some Topic"Processing Messages:Create a Message class1 include TorqueBox::Messaging2 class MyMessageHandler < MessageProcessor3 def on_message(body)4 # process the message5 end6 endAdd queue/topic to config/torquebox.yml 1 queues: 2 /queues/timer: 3 topics: 4 /topics/topic1: 5
  13. 13. 6 messaging: 7 /queues/timer: 8 MyMessageHandler: 9 concurrency: 510 /topics/topic1:11 Topic1Handler
  14. 14. Feature: JobsJobs ( Backgroundable ):include TorqueBox::Messaging::Backgroundable to any Ruby class1 class LuceneIndexJob2 include TorqueBox::Messaging::Backgroundable3 def do_index4 # very long running job5 end6 endget the future ( optionally store it in a serialized format somewhere )1 indexer = LuceneIndexJob.new2 future = indexer.background.do_index3 future.started?4 future.complete?5 future.error?6 future.status7 # store future object for later retrieval ( maybe in database )
  15. 15. Feature: Jobs contd.Scheduled Jobs:Create a class with run() method1 class MonthlyBirthdayEmailer2 def run3 # some long task here4 end5 endAdd entry on config/torquebox.yml with crontab(5) like time specification1 jobs:2 monthly_birthday_notifications:3 description: first of month4 job: MonthlyBirthdayEmailer5 cron: 0 0 0 1 * ?
  16. 16. Feature: CachingCaching ( via Infinispan ):Add gem torquebox-cache to Gemfile1 gem torquebox-cacheupdate application.rb to use torquebox cache1 class Application < Rails::Application2 config.cache_store = :torque_box_store3 endaccess the cache 1 require torquebox-cache 2 cache = :name => treasure, 3 :persist=>/data/treasure ) 4 # Put some stuff in the cache 5 cache.put(akey, "a string value" ) 6 cache.put("time", ) 7 cache.put(, user ) 8 # Get it back again 9 time = cache.get( "time" )10 user = cache.get( params[:id] )
  17. 17. Feature: ServicesCrete a class with initialize, start and stop methods 1 class TimeService 2 def initialize(opts) 3 puts "Queue Name: #{opts[queue]}" 4[queue]) 5 end 6 def start 7{run} 8 end 9 def stop10 @done=true11 end12 def run13 until @done14 @queue.publish( sleep(1)16 end17 end18 endAdd service to application configuration file1 services:2 TimeMachine:3 config:4 queue: /queue/time
  18. 18. Feature: ClusteringClustering:torquebox run --clusteredclustered deploymentclustered cacheshared web sessions etc.High Availability Singleton Services1 $JBOSS_HOME/bin/ --server-config=standalone-ha.xml2 mark the service as singleon: true in the configuration file
  19. 19. Hacking TorqueBox
  20. 20. Hacking TorqueBox
  21. 21. SummaryBuilt on Ruby / JRuby, TorqueBox is well suited for rapidapplication development in the settings where Enterprise JavaApplications are already in place.TorqueBox Provides these features out of the box, without anyhassle:Messaging, Jobs, Caching, Services and ClusteringTorqueBox / JRuby gotchas:TorqueBox gives you real threads but many existing Ruby libraries suckwith multi threading.Can invoke JavaDoes Real ThreadingFFI supportNative C extensions written for MRI Ruby dont workNative gems are not supported, except FFI.
  22. 22. Questions?IRC: #torquebox on FreeNode Web:
  23. 23. Thanks
  24. 24. ReferencesWhen Two Worlds Collide: Java and Ruby in the Enterprise talk Presentation TorqueBox ImmutantJBoss Blacktie Erjang TypeSafe: The Polyglot Revolution continues apace Scala the statically typeddynamic language Calling Java from JRuby ActiveRecord-JDBC Database Support Using RVM withTorqueBox Cuvic On Demand JRuby vs Ruby Installing TorqueBox 2.0 Rails on TorqueBox Sinatra onTorqueBox Long Running Services in TorqueBox Latency / Throughput CPU / Memory JVM LanguagesJVM Understand RVM Install RVM on Fedora JRuby on Rails with RVM ( on Fedora ) Quartz -CronTrigger Tutorial