Your SlideShare is downloading. ×
0
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
TorqueBox at GNUnify 2012
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

TorqueBox at GNUnify 2012

1,262

Published on

TorqueBox - A complete Ruby Application Server …

TorqueBox - A complete Ruby Application Server
(GNUnify 2012)
HTML version - http://tuxdna.in/files/presentations/torquebox-intro.html

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
  • An HTML version is available here http://tuxdna.in/files/presentations/torquebox-intro.html
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
1,262
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Presenting...Saleem Ansaritwitter: tuxdna10th February, 2012 at GNUnify
  • 2. OutlineWhat is TorqueBox?Polyglot RevolutionTorqueBoxHow to use TorqueBox?FeaturesInstallation and setup: RVM, JRuby, TorqueBoxDeploymentFeatures contd.How to begin hacking TorqueBox?JBoss PolyglotTorqueBox
  • 3. What is TorqueBox?Before that lets talk about Polyglot Revolution
  • 4. Polyglot RevolutionJVM is what makes the Polyglot Revolution.
  • 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. back to TorqueBoxStarted in 2009 by Bob McWhirter @bobmcwhirterA complete Ruby Application ServerWhy?ProductivityPower and stability of Java MiddlewareScale on demand
  • 7. TorqueBox contd.
  • 8. Built onJRuby / RubyJBoss ASEnterprise Java ( EJB, JMS, Caching etc. )ProvidesMessagingJobsCachingServicesClustering
  • 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 http://torquebox.org/2x/builds/LATEST/gem-repo
  • 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. 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. Feature: Messaging (via HornetQJMS)Sending Messages:1 timer_queue = TorqueBox::Messaging::Queue.new(/queues/timer)2 timer_queue.publish "Some Message"3 topic1 = TorqueBox::Messaging::Topic.new(/topics/topic1)4 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. 6 messaging: 7 /queues/timer: 8 MyMessageHandler: 9 concurrency: 510 /topics/topic1:11 Topic1Handler
  • 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. 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. 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 = TorqueBox::Infinispan::Cache.new( :name => treasure, 3 :persist=>/data/treasure ) 4 # Put some stuff in the cache 5 cache.put(akey, "a string value" ) 6 cache.put("time", Time.now ) 7 cache.put(user.id, user ) 8 # Get it back again 9 time = cache.get( "time" )10 user = cache.get( params[:id] )
  • 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=TorqueBox::Messaging::Queue.new(opts[queue]) 5 end 6 def start 7 Thread.new{run} 8 end 9 def stop10 @done=true11 end12 def run13 until @done14 @queue.publish(Time.now)15 sleep(1)16 end17 end18 endAdd service to application configuration file1 services:2 TimeMachine:3 config:4 queue: /queue/time
  • 18. Feature: ClusteringClustering:torquebox run --clusteredclustered deploymentclustered cacheshared web sessions etc.High Availability Singleton Services1 $JBOSS_HOME/bin/standalone.sh --server-config=standalone-ha.xml2 mark the service as singleon: true in the configuration file
  • 19. Hacking TorqueBox
  • 20. Hacking TorqueBox contd.JBoss-Polyglotgithub.com/projectodd/jboss-polyglotTorqueBoxgithub.com/torquebox/torquebox
  • 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. Questions?IRC: #torquebox on FreeNode Web: torquebox.org
  • 23. Thanks
  • 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

×