26
When Ruby Meets Java The Power of Torquebox Monday 26 March 12

When Ruby Meets Java - The Power of Torquebox

Embed Size (px)

DESCRIPTION

Slides from @arunagw and rockyj.in 's talk from Ruby Conf India 2012.

Citation preview

Page 1: When Ruby Meets Java - The Power of Torquebox

When Ruby Meets Java

T h e P o w e r o f T o r q u e b o x

Monday 26 March 12

Page 2: When Ruby Meets Java - The Power of Torquebox

About UsA r u n A g r a w a l - 2 8 0 + c o m m i t s i n R a i l s c o r e - M o n g o i d c o r e t e a m m e m b e r - C r e a t o r o f o m n i a u t h - t w i t t e r - C o d i n g o n R a i l s s i n c e 2 0 0 7 - a g r a w a l a r u n . c o m / @ a r u n a g w

R o c k y J a i s w a l - C o d i n g s i n c e 1 9 9 5 - K n o w b i t s o f J a v a & R u b y - E n j o y u s i n g J R u b y - r o c k y j . i n / @ w h a t s u p r o c k y

Monday 26 March 12

Page 3: When Ruby Meets Java - The Power of Torquebox

ToDo- T h e E n t e r p r i s e- W h a t i s T o r q u e b o x- D e m o - S c h e d u l i n g - S e r v i c e s - M e s s a g i n g - B a c k g r o u n d a b l e - C l u s t e r i n g & C a c h i n g - P e r f o r m a n c e & S u m m a r y

- S u r p r i s e ! !

Monday 26 March 12

Page 4: When Ruby Meets Java - The Power of Torquebox

Coolest Thing About JRuby(1.6) ?

Pop Quiz

Monday 26 March 12

Page 5: When Ruby Meets Java - The Power of Torquebox

The Enterprise

Monday 26 March 12

Page 6: When Ruby Meets Java - The Power of Torquebox

What If...Wouldn’t it be great if

- I could use the power of Java libraries with the ease of Ruby

- I could use the power of a proven Java Server without writing any XML

- I could deploy my JRuby app and test it without rebuilding it and restarting the server

Monday 26 March 12

Page 7: When Ruby Meets Java - The Power of Torquebox

TORQUEBOX

Built upon JBoss 7Built using JRuby (1.6.7)Supports Rack, Rails, SinatraEverything in one box

Monday 26 March 12

Page 8: When Ruby Meets Java - The Power of Torquebox

TORQUEBOX

Monday 26 March 12

Page 9: When Ruby Meets Java - The Power of Torquebox

Installation- Download the distribution from torquebox.org

OR

- rvm jruby (1.6.7) jruby -J-Xmx1024m -S gem install torquebox-server --pre

Monday 26 March 12

Page 10: When Ruby Meets Java - The Power of Torquebox

Our Sh***y App

Monday 26 March 12

Page 11: When Ruby Meets Java - The Power of Torquebox

SchedulingUses the battle-tested Quartz Java library

Zero XML

Minimal configuration

No manual thread / process management

No messing with cron

Monday 26 March 12

Page 12: When Ruby Meets Java - The Power of Torquebox

Schedulingconfig/torquebox.yml

jobs: mail_notifier: job: MailNotifier cron: '*/5 * * * * ?' description: Deliver reminder email

class MailNotifier

def run send_reminder_notification end

def send_reminder_notification puts "Sending mail ..." #UserMailer.reminder_email(User.find(1)).deliver end

end

Monday 26 March 12

Page 13: When Ruby Meets Java - The Power of Torquebox

ServicesLong running services with 3 line configuration

Full access to the Rails environment

JVM threads!

Monday 26 March 12

Page 14: When Ruby Meets Java - The Power of Torquebox

Servicesconfig/torquebox.ymlservices: MessageNotifier: config: name: hello

class MessageNotifier def initialize(opts={}) @name = opts['name'] end def start Thread.new { run } end def stop @done = true end def run until @done do_something #todo sleep(5) end endend

Monday 26 March 12

Page 15: When Ruby Meets Java - The Power of Torquebox

MessagingJMS supported out-of-the-box (HornetQ)

Advanced Messaging Queuing Protocol (AMQP)- RabbitMQ

Supports STOMP out of the box

Monday 26 March 12

Page 16: When Ruby Meets Java - The Power of Torquebox

AMQP

Monday 26 March 12

Page 17: When Ruby Meets Java - The Power of Torquebox

MessagingIn a long running service -...def do_something puts "Checking the queue for messages ..."

bunny = Bunny.new(:logging => false)

# start a communication session with the amqp server bunny.start

# declare a queue q = bunny.queue(@name)

# get message from the queue msg = q.pop[:payload]

puts "This is the message: " + msg.to_s

# close the connection bunny.stopend

Monday 26 March 12

Page 18: When Ruby Meets Java - The Power of Torquebox

BackgroundableAs easy as A, B, C ...

class User < ActiveRecord::Base include TorqueBox::Messaging::Backgroundable

always_background :send_signup_notification

validates_confirmation_of : ...

def send_signup_notification(user) UserMailer.welcome_email(user).deliver end end

Monday 26 March 12

Page 19: When Ruby Meets Java - The Power of Torquebox

Clusteringtorquebox run --clustered

Does everything

Servers in a LAN are automatically clustered

Top it up with mod_cluster from JBoss

Monday 26 March 12

Page 20: When Ruby Meets Java - The Power of Torquebox

CachingTorqueBox provides an implementation of the Rails 3.x ActiveSupport::Cache::Store that exposes your application to the Infinispan data grid.

Uses Infinispan by default

Can utilize the cluster with minimal config

Share the cache across the cluster - FTW!

Monday 26 March 12

Page 21: When Ruby Meets Java - The Power of Torquebox

Performance

Monday 26 March 12

Page 22: When Ruby Meets Java - The Power of Torquebox

Performance

Monday 26 March 12

Page 23: When Ruby Meets Java - The Power of Torquebox

Risks- Version 2 is quite stable but still at RC1

- Upgrading JRuby will not help sometimes

- You will be on a cutting edge open-source technology but documentation is great, help is available online and on IRC

Monday 26 March 12

Page 24: When Ruby Meets Java - The Power of Torquebox

Surprise!!!

Monday 26 March 12

Page 25: When Ruby Meets Java - The Power of Torquebox

Questions?

Monday 26 March 12

Page 26: When Ruby Meets Java - The Power of Torquebox

Thank You

Monday 26 March 12