When Two Worlds Collide: Java and Ruby in the Enterprise
Upcoming SlideShare
Loading in...5
×
 

When Two Worlds Collide: Java and Ruby in the Enterprise

on

  • 3,068 views

 

Statistics

Views

Total Views
3,068
Slideshare-icon Views on SlideShare
1,788
Embed Views
1,280

Actions

Likes
2
Downloads
18
Comments
0

8 Embeds 1,280

http://torquebox.org 1156
http://www.jboss.org 74
http://localhost 34
http://staging.torquebox.org 7
http://a0.twimg.com 5
http://planet.jboss.org 2
http://translate.googleusercontent.com 1
http://digg.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • Several of us are employed by Red Hat and work on TorqueBox full time but most aren’t.\n
  • Since this is a JBoss User Group, hopefully most attendees either already use JBoss or are open to the idea of moving to JBoss. So, what this really means is ->\n
  • \n
  • \n
  • Ask any Rubyist why they use the language and “Because with Ruby I’m more productive than when using X” will likely be one of their reasons\n
  • Give your developers several tools to choose from and let them pick which is the best for each job\n
  • \n
  • \n
  • Ruby running on top of the JVM\n
  • A few examples of Java library usage from JRuby\n
  • JRuby has real threads and real concurrency\n
  • \n
  • TorqueBox is additive to JBoss AS7 - it’s still JBoss AS7 underneath and you can still deploy Java applications to TorqueBox\nTorqueBox just adds on the Ruby support\n
  • \n
  • warbler, jruby-rack\n
  • \n
  • \n
  • no bundling or compilation step, no redeploying or restarting server\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • This download includes a full JBoss AS7 w/ TorqueBox and a bundled JRuby runtime\n
  • JRuby 1.6.6 and onwards won’t require passing Xmx to the gem install command\n
  • $TORQUEBOX_HOME/jboss/bin/standalone.sh if you prefer\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Clustered sessions, Infinispan cache, HornetQ destinations, HA Singletons\njust runs standalone.sh -server-config standalone-ha.xml underneath\n
  • \n
  • \n
  • \n
  • :decode => false since we’re receiving from Java and not using a standard TorqueBox encoding when sending\n
  • PicketLink is included in JBoss AS 7\nYou can authenticate against configured AS7 security domains in Ruby\n
  • \n
  • \n
  • \n

When Two Worlds Collide: Java and Ruby in the Enterprise When Two Worlds Collide: Java and Ruby in the Enterprise Presentation Transcript

  • When Two Worlds Collide: Java and Ruby in the Enterprise Ben BrowningCreative Commons BY-SA 3.0 ATL JBUG Jan 31 2012
  • Ben Browning•TorqueBox Core Contributor•Red Hat Senior Engineer•twitter.com/bbrowning•github.com/bbrowning
  • TorqueBox Extended Team
  • Ruby and Java in the Enterprise
  • TorqueBox in the Enterprise
  • Why Ruby?
  • Why Ruby?•Productivity
  • Why Ruby?•Productivity•Choice
  • Why Ruby?
  • JRuby•Marriage of the JVM and Ruby•the library level integrate at Lets Java and Ruby
  • JRubyrequire ‘java’java.lang.System.setProperty(‘key’, ‘value’)java_import java.util.HashMaphashmap = HashMap.newhashmap[‘key’] = ‘value’
  • JRubyrequire ‘java’java_import java.util.concurrent.CountDownLatchjava_import java.util.concurrent.TimeUnitlatch = CountDownLatch.new(1)Thread.new { sleep 5 latch.count_down}latch.await(15, TimeUnit::SECONDS)
  • TorqueBox
  • TorqueBox•Marriage of JBoss AS7 and JRuby•the application levelintegrate at Lets Java and Ruby•in the same application server Run Java and Ruby applications
  • But Can’t I Already Run JRubyApps in My Java App Server?
  • But Can’t I Already Run JRubyApps in My Java App Server?Yes, if you don’t mind disguising your Ruby application as a Java application
  • So Why TorqueBox?
  • So Why TorqueBox?Ruby as a first-class citizen in the enterprise
  • Familiar to Ruby DevsMake changes then refresh the browser
  • Familiar to Java Devs Just JBoss AS7 underneath
  • So Why TorqueBox?Ruby interfaces to services provided by the application server
  • Ruby!APIs!/!Programming!Models Java!APIs!/!Programming!Models Message Processors Polyglot WebSockets InjectionSinatra Rails Jobs STOMP POJO REST Servlet Rack Daemons Tasks Spring JMS JavaEE JRuby!Component!Deployers!&!Gems Java!Enterprise!Services JBoss Web Messaging Infinispan Cache TorqueBox HornetQ Transactions Core Quartz Security TorqueBox Core PicketLink JRuby with JIT Managed Services Container Java Virtual Machine
  • TorqueBox•applications & Rack Rails, Sinatra,
  • TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
  • Installation For Java Devswget http://torquebox.org/release/org/torquebox/torquebox-dist/2.0.0.beta3/torquebox-dist-2.0.0.beta3-bin.zipunzip torquebox-dist-2.0.0.beta3-bin.zipexport TORQUEBOX_HOME=`pwd`/torquebox-2.0.0.beta3export PATH=$TORQUEBOX_HOME/jruby/bin:$PATH
  • Installation For Ruby Devsrvm install jruby-1.6.5.1rvm use jruby-1.6.5.1jruby -J-Xmx1024m -S gem install torquebox-server--pre
  • Usagetorquebox deploy ~/my_ruby_apptorquebox run
  • TorqueBox•applications & Rack Rails, Sinatra,•More than just web •Messaging •Jobs •Services •Caching
  • Messaging
  • Message Processorsapp/models/print_handler.rbinclude TorqueBox::Messagingclass PrintHandler < MessageProcessor  def on_message(body)    puts "Processing #{body} of #{message}"  endend
  • Message Processorsconfig/torquebox.ymlqueues: /queues/receipts:messaging: /queues/receipts: PrintHandler: concurrency: 5
  • Backgroundable
  • Regular Classclass Something def foo sleep 5 endend
  • Blocking Invocationssomething = Something.newsomething.foo
  • Backgroundableclass Something include TorqueBox::Messaging::Backgroundable def foo end def bar endend
  • Non-Blocking Invocationssomething = Something.newsomething.background.foo
  • See The Futuresomething = Something.newfuture = something.background.foo
  • See The Futurefuture.started?future.complete?future.error?future.result
  • See The Futureclass Something def foo ... count += 1 future.status = count ... endend
  • See The Future# on the client sidefuture.status_changed?future.status # => 42
  • Scheduled Jobs
  • Scheduled Jobsapp/jobs/newsletter_sender.rbclass NewsletterSender   def run    subscriptions = Subscription.find(:all)    subscriptions.each do |e|      send_newsletter(e)    end  end end
  • Scheduled Jobsconfig/torquebox.ymljobs: monthly_newsletter: description: first of month job: NewsletterSender cron: ‘0 0 0 1 * ?’
  • Services
  • Servicesapp/services/time_machine.rbclass TimeMachine def initialize(opts) @queue = Queue.new(opts[queue]) end def start Thread.new { run } end def stop @done = true endend
  • Servicesapp/services/time_machine.rbclass TimeMachine def run until @done @queue.publish(Time.now) sleep(1) end endend
  • Servicesconfig/torquebox.ymlservices: TimeMachine: config: queue: /queue/time
  • Caching
  • Rails Caching config/application.rbmodule MyApp class Application < Rails::Application ... config.cache_store = :torque_box_store endend
  • Explicit Cachinginclude ActiveSupport::CachemyCache = TorqueBoxStore.new(:name => MyCache, :mode => :replicated, :sync => true)
  • Clusteringtorquebox run --clustered
  • Better Java Integration•Deploy Java and Ruby side-by-side•Injection of Java components - CDI, objects bound to JNDI, etc•Send JMS messages in vice-versa consume in Ruby and Java to•Share caches between Java and Ruby•PicketLink authentication in Ruby•Java Management Tools
  • Java Component Injection# messaging destinationsinject(‘/queues/something’)# CDI resourcesinject(com.mycorp.MyJavaService)# JNDI entriesinject(‘java:comp/env/that_thing’)# JBoss MSC Servicesinject(‘jboss.web’)
  • Java & Ruby Messaging producer.javaInitialContext ic = new InitialContext();ConnectionFactory cf = (ConnectionFactory) ic.lookup(“/ConnectionFactory”);Queue queue = (Queue) ic.lookup(“/queues/my_queue”);Connection connection = cf.createConnection();Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);MessageProducer producer = session.createProducer(queue);TextMessage message = session.createTextMessage(“hi”);producer.send(message);
  • Java & Ruby Messagingconsumer.rbqueue = inject(‘/queues/my_queue’)message = queue.receive(:decode => false)puts message.text# prints “hi”
  • PicketLink & Rubyauthenticator = TorqueBox::Authenticator[‘jmx-console’]authenticator.authenticate(‘username’, ‘password’) do some_authenticated_actionend
  • Java Management
  • Resources•http://torquebox.org•https://github.com/torquebox•#torquebox on FreeNode•@torquebox on Twitter
  • Questions? Don’t Be ShyImage Attributions:Tools - http://www.flickr.com/photos/jrvogt81/4264575563/Mailboxes - http://www.flickr.com/photos/joanet/5094833752/Now and Laters - http://www.flickr.com/photos/jcorduroy/3725077603/Hand Calendar - http://www.flickr.com/photos/joelanman/366190064/Cruise Ship Staff - http://www.flickr.com/photos/maethlin/2547037443/