twitter: tuxdna
Before moving onto TorqueBox, let me first introduce you to the Polyglot Revolution. TorqueBox is a part of Polyglot Revolution itself as we will see later. Today there are many programming languages whose compilers or interpreters target the JVM. Those languages include JRuby, Jython, Scala, Erlang ( Erlang on JVM ), and many more. Many of these languages are dynamically typed languages (or dynamic languages).
What does this enable us to do? Well, basically it enables you to write a program in any of the JVM languages, which gets compiled to Java byte-codes. So, whenever your program written in one JVM language executes, it can also execute the bytecodes generated for any other JVM targeted language. As simple it sounds, it is a very powerful feature because you can now use all your Java code that was written and tested over the years.
TorqueBox is a Ruby Application Server. By Application Server I mean that, it is not just a web framework, but it has batteries included. It is built on top of tested and proven technologies. While JRuby provides you ability to call Java code from within your Ruby code ( and vice-versa ), TorqueBox provides the integration at the application level. It provides the ability to consume the services provided by JBoss and write your own if not avaiable.
1 yum install -y ruby rubygem-rvm
2 rvm-install
3 [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
4 rvm install jruby-1.6.5
5 rvm use jruby-1.6.5
1 gem install --pre torquebox
2 gem install --pre torquebox-messaging-container
3 gem install --pre torquebox-naming-container
4 gem install --pre torquebox-capistrano-support
5 gem install --pre torquebox-rake-support
6 gem install --pre torquebox-vfs
7 jruby -J-Xmx1024m -w -S \
8 gem install --pre torquebox-server \
9 --source http://torquebox.org/2x/builds/LATEST/gem-repo
1 gem install rails
2 gem install bundler
1 gem install activerecord-jdbcsqlite3-adapter
2 gem install activerecord-jdbcmysql-adapter
1 rails new rails-app
2 cd rails-app
3 bundle install
4 rails g scaffold Person name:string
5 rake db:migrate
1 torquebox run
2 torquebox deploy /path/to/rails-app
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"
1 include TorqueBox::Messaging
2 class MyMessageHandler < MessageProcessor
3 def on_message(body)
4 # process the message
5 end
6 end
1 queues:
2 /queues/timer:
3 topics:
4 /topics/topic1:
5
6 messaging:
7 /queues/timer:
8 MyMessageHandler:
9 concurrency: 5
10 /topics/topic1:
11 Topic1Handler
1 class LuceneIndexJob
2 include TorqueBox::Messaging::Backgroundable
3 def do_index
4 # very long running job
5 end
6 end
1 indexer = LuceneIndexJob.new
2 future = indexer.background.do_index
3 future.started?
4 future.complete?
5 future.error?
6 future.status
7 # store future object for later retrieval ( maybe in database )
1 class MonthlyBirthdayEmailer
2 def run
3 # some long task here
4 end
5 end
1 jobs:
2 monthly_birthday_notifications:
3 description: first of month
4 job: MonthlyBirthdayEmailer
5 cron: '0 0 0 1 * ?'
1 gem 'torquebox-cache'
1 class Application < Rails::Application
2 config.cache_store = :torque_box_store
3 end
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] )
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 stop
10 @done=true
11 end
12 def run
13 until @done
14 @queue.publish(Time.now)
15 sleep(1)
16 end
17 end
18 end
1 services:
2 TimeMachine:
3 config:
4 queue: /queue/time
1 $JBOSS_HOME/bin/standalone.sh --server-config=standalone-ha.xml
2 mark the service as singleon: true in the configuration file
github.com/projectodd/jboss-polyglot
github.com/torquebox/torquebox
IRC: #torquebox on FreeNode Web: torquebox.org
When Two Worlds Collide: Java and Ruby in the Enterprise talk Presentation TorqueBox Immutant JBoss Blacktie Erjang TypeSafe: The Polyglot Revolution continues apace Scala the statically typed dynamic language Calling Java from JRuby ActiveRecord-JDBC Database Support Using RVM with TorqueBox Cuvic On Demand JRuby vs Ruby Installing TorqueBox 2.0 Rails on TorqueBox Sinatra on TorqueBox Long Running Services in TorqueBox Latency / Throughput CPU / Memory JVM Languages JVM Understand RVM Install RVM on Fedora JRuby on Rails with RVM ( on Fedora ) Quartz - CronTrigger Tutorial
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |