The document discusses TorqueBox, an application server for Ruby that is built on JBoss Application Server 7 and uses JRuby. It allows Ruby applications to take advantage of features typically found in Java application servers like clustering, caching, messaging, and more. Key features highlighted include support for Ruby web frameworks like Rails and Sinatra, background processing using Resque or DelayedJob, messaging using JMS, long running services, and resource injection. Web sockets support is provided using STOMP and the Stilts framework. The document outlines goals of TorqueBox and provides examples of configuration and usage.
24. Clustering: mod_cluster
A reverse proxy implemented as
an Apache module with JBoss
awareness.
Constantly gathers load statistics
and deployment availability for
intelligent request distribution.
54. Topics
•interface is different, but
behavior
is the same.
•each message, of a only one
all subscribers
but
topic see
subscriber will see any message
from a queue
• use TorqueBox::Messaging::Topic
57. Services
•methods, which shouldstop()
A class with start() and
each
return quickly. Optionally
provide initialize(Hash).
•running loop startthread and
Typically will
in a
a long-
respond to external events.
63. Services
app/services/time_machine.rb
class TimeMachine
def initialize(opts)
@queue = Queue.new(opts['queue'])
end
def start
Thread.new { run }
end
def stop
@done = true
end
def run
until @done
@queue.publish(Time.now)
sleep(1)
end
end
end
76. Web Sockets
app/stomplets/broadcast_stomplet.rb
require 'torquebox-stomp'
class BroadcastStomplet
def on_subscribe(subscriber)
@subscribers << subscriber
end
def on_unsubscribe(subscriber)
@subscribers.delete( subscriber )
end
def on_message(stomp_message, session)
@subscribers.each do |subscriber|
subscriber.send( stomp_message )
end
end
end
77. Web Sockets
app/stomplets/broadcast_stomplet.rb
require 'torquebox-stomp'
class BroadcastStomplet
def on_subscribe(subscriber)
@subscribers << subscriber
end
def on_unsubscribe(subscriber)
@subscribers.delete( subscriber )
end
def on_message(stomp_message, session)
@subscribers.each do |subscriber|
subscriber.send( stomp_message )
end
end
end
78. Web Sockets
app/stomplets/broadcast_stomplet.rb
require 'torquebox-stomp'
class BroadcastStomplet
def on_subscribe(subscriber)
@subscribers << subscriber
end
def on_unsubscribe(subscriber)
@subscribers.delete( subscriber )
end
def on_message(stomp_message, session)
@subscribers.each do |subscriber|
subscriber.send( stomp_message )
end
end
end
79. Web Sockets
app/stomplets/broadcast_stomplet.rb
require 'torquebox-stomp'
class BroadcastStomplet
def on_subscribe(subscriber)
@subscribers << subscriber
end
def on_unsubscribe(subscriber)
@subscribers.delete( subscriber )
end
def on_message(stomp_message, session)
@subscribers.each do |subscriber|
subscriber.send( stomp_message )
end
end
end
81. JMS Stomplet
app/stomplets/irc_stomplet.rb
class IrcStomplet < TorqueBox::Stomp::JmsStomplet
include TorqueBox::Messaging
def configure(config)
@destination = Queue.new( config['destination'] )
end
def on_subscribe(subscriber)
# subscribe the client to a JMS message queue
subscribe_to( subscriber, @destination )
# send a message to the queue
send_to( @destination, "TorqueBoxBot in da house",
:sender => :system, :timestamp => Time.now.ctime )
end
end
82. IRC Bot Service
app/services/irc_bot_service.rb
class IrcBotService
include TorqueBox::Messaging
def start
@bot = configure_bot
@bot_thread = Thread.new { @bot.connect }
end
def configure_bot
# ...
# Log all channel messages to the queue
bot.on :channel do |event_data|
@destination.publish( event_data[:message],
:properties =>
{:sender=>event_data[:nick], :timestamp=>Time.now.ctime} )
end
bot
end
end
95. Installation & Deployment
$ gem install torquebox-server --pre
--source http://torquebox.org/2x/builds/LATEST/gem-repo/
$ torquebox
Tasks:
torquebox deploy ROOT # Deploy an application to TorqueBox
torquebox undeploy ROOT # Undeploy an application from TorqueBox
torquebox run # Run TorqueBox
torquebox cli # Run the JBoss AS7 CLI
torquebox help [TASK] # Describe available tasks or one specific task
100. Thanks!
Questions?
Image attributions:
Soccer Youth Goal Keeper by Torsten Bolten http://en.wikipedia.org/wiki/File:Soccer_Youth_Goal_Keeper.jpg
Series of tubes by ritingon http://www.flickr.com/photos/ritingonthewall/2579076693/
Yawning is danger! by dj badly http://www.flickr.com/photos/djbadly/2052098189/
EuroFoo Schedule by silent-penguin http://www.flickr.com/photos/silent-penguin/232394/
Sink. by _Fidelio_ http://www.flickr.com/photos/photogaby/4129740673/ CC BY 2.0
Telegraph Practice Set from Popular Science, Feb 1947 http://books.google.com/books?id=uyUDAAAAMBAJ&lpg=PA65&pg=PT83#v=onepage&q&f=false
Service as a Strategy Celebration at NCVS 2011 by Be The Change, Inc http://www.flickr.com/photos/bethechangeinc/5816393052/ CC BY-NC 2.0
Cash by ROSS HONG KONG http://www.flickr.com/photos/rossap/2716531616/ CC BY-NC-SA 2.0
Injection by Dr Case http://www.flickr.com/photos/justin_case/3252846177/ CC BY-NC 2.0
IMG_1478 by akshaydavis http://www.flickr.com/photos/akshaydavis/166391476/ CC BY-NC-SA 2.0
Rainforest by Chris.Gray http://www.flickr.com/photos/chriscgray/3946304802/ CC BY-NC-SA 2.0
Community by niallkennedy http://www.flickr.com/photos/niallkennedy/40727794/ CC BY-NC 2.0
Notas del editor
\n
\n
\n
What? JBoss? Isn&#x2019;t that Java?\n
to provide all we do, we have to be tightly integrated.\nwhich means no glassfish/websphere/whatever\n
First class ruby\n\n
java developers know what an app server is\n
\n
\n
redeploy\n
Target Audience for TorqueBox\n
\n
We write Java so you don&#x2019;t have to\n
Parity with existing ruby options.\n
Expose what an AS can provide.\n
TorqueBox brings that all together\norange is ruby, red is java\n
components - start with Web - a series of tubes\n
in development mode\n
\n
Where supported. Live editing isn&#x2019;t enabled in Sinatra by default anymore\n
from a rubyists perspective\nminimum requirement for ruby development. It's expected.\n
\n
\n
As server nodes join and leave the cluster, the balancer (mod_cluster) is aware of these changes.\n
anyone using infinispan?\n\n
we make it easy to use from rails, or anything using the ActiveSupport library\n
\n
\n
we provide TorqueBoxStore, which has the same api as the memcached store\n
Scheduled Jobs\n
Only a run() method is required\n
Jobs run on every node unless singleton: true\n\nSeconds - Minutes - Hours - Day of Month - Month - Day of Week - Year\n\n\n
Asynchronous tasks\n
\n
\n
\n
returns immediately\nguts execute on a separate thread\n
\n
returns immediately\nguts execute on a separate thread\n
allows you to monitor the async execution\n
\n
\n
uses messaging underneath (queues)\n
Messaging\nwe expose those messaging abstractions\n
\n
created at deploy time\n
shows publish and receive\n\n
\n
\n
\n
be sure to destroy\n
\n
Ruby messages are Marshaled and Base64-encoded\n
same semantics\n
Services\n
demons!\n
\n
!!!singleton!\n
\n
\n
\n
\n
\n
Resource Injection\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
How does it perform?\nIs it the car or the truck?\ncomparing against other ruby stacks is easy \nbut comparing java to ruby it's hard to get anything meaningful\n
10 minute warmup, load increasing every 10 minutes thereafter\n
\n
Good blog post on torquebox.org\n
The TorqueBox Ecosystem\n
deploy to TB\ninspect & manage queues, message processors, ruby runtimes, services, jobs\n
\n
\n
\n
\n
\n
which is no surprise to java devs, but often is to rubyists\n
we have a few other things, but you tell us\n
OSS (LGPL) - letter, but not modern intent\nactive in mailing lists and irc\nDocumentation with most features on push\ndistributed team - irc tech discussions\nwe offer the process as ONE example, and welcome feedback!\nhowever you do it, focus on your community!\n