Successfully reported this slideshow.
JRuby in the Enterprise
About MeAdvisory Engineer at Constant ContactSpent several years working for Sun/Javasoft inthe distributed computing grou...
What is JRuby?Just a Ruby interpreter running on the JVMRuby 1.8.7 & 1.9.2 compatible.
Text-To-JoinDistributed appWritten in Ruby as a Rails appFour rails apps, actuallyUI, API, Console, SMS Processor.
JRUBY.ORG
Why Ruby?Ruby is…A dynamic, open source programminglanguage with a focus on simplicity andproductivity. It has an elegant ...
WHY SHOULD YOU SWITCH TO RUBY? IF YOU ARE HAPPY WITH PERL OR PYTHON, YOU DONT HAVE TO. BUT IF YOU DO FEEL THERE MUST BE A ...
Rails 3.x“Optimized for programmer happiness”.
Why Not Grails?Grails is greatNot as big of a break with JavaWanted a bigger shift to bring new ways of doingthings into p...
Why JRuby?High performance  JVM Highly TunedReal threading  Many “pure Ruby” shops using JRuby just for  thisVast array of...
Why JRuby ContinuedDeployment Options  Can deploy as a WAR fileMonitoring Options  JVM tools to monitor all availableSpeed ...
Don’t Freak the Ops     Guys Out  HTTP://UPLOAD.WIKIMEDIA.ORG/WIKIPEDIA/EN/F/F4/THE_SCREAM.JPG
http://commons.wikimedia.org/wiki/File:Everest-fromKalarPatar.jpg          Scalability
Concurrency is a Myth HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
ILYA GRIGORIK                HTTP://WWW.IGVITA.COM/ABOUT/ JRUBY IS, IN FACT, THE ONLY RUBY IMPLEMENTATIONTHAT WILL ALLOW Y...
“Enterprise” JRuby
“Enterprise” JRuby Cont.MavenLiquibaseJDBCJNDIContainersYou’re favorite commercial, open-source or home-grown library.
Let’s Begin          http://commons.wikimedia.org/wiki/File:Begin_road.JPG
http://commons.wikimedia.org/wiki/File:Panama_Canal_Locks_Construct.jpeg    Set up Ruby
Ruby Version Manager    HTTPS://RVM.BEGINRESCUEEND.COM/
Installing RVMVia git repo (preferred method)bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)Other methods at ...
Install JRuby (via rvm)rvm install jruby-1.6.3When it’s done, use it:  rvm use jruby-1.6.3List of other ruby versions to i...
JRuby Without RVMAssume Java, JRuby in your pathjruby -S gem ...
Install Railsgem install railsCan pick a specific version with a“-v” flag.
Create Your Rails AppJruby.org hosts a rails template  Sets things up to run under native ruby or JRuby  You can do this y...
Jruby.org Template
Demo
Packaging Your App   http://en.wikipedia.org/wiki/File:Distribution_differences.jpg
JRuby/Rails/WAR filesIn the Java world, WAR files are standardFortunately, we have bundler  Gem to package your Rails app as...
Install itEasy!gem install warbler
Run It             http://en.wikipedia.org/wiki/File:Jeanette_Kwakye_cropped.jpgEasy!warble war
Other Useful Optionswarble compiled    # Feature: precompile all Ruby fileswarble config      # Generate a configuration file ...
MavenIn the Java world, Maven is still pretty popular  For better or for worseYou can use Maven to invoke warbler to packa...
Database Migrationshttp://en.wikipedia.org/wiki/File:Connochaetes_taurinus_-Wildebeest_crossing_river_-East_Africa.jpg
Database MigrationsRails uses Rake for ActiveRecord migrationsNice, but  Hard to scale to multiple developers  Hard to dep...
Enterliquibase.orgVersion control for your databaseOther frameworks (Grails) will be adopting it formigrationsLanguage/Dat...
LiquibaseNothing special about using Liquibase with RailsUse ActiveRecord migrations for initial dev/testing,then migrate ...
Handy Liquibase CommandsGenerate initial changelog:java -jar liquibase.jar --classpath=mysql-connector-java-5.1.14-bin.jar...
USING LIQUIBASEWITH MAVEN
Liquibase with Rails Directlyhttps://github.com/redbeard/liquibase-railsSupposed to add “drop in” migration tasks forJRuby...
Liquibase Changeset
JNDI Database Access       DATABASE.YML
Servlet FiltersYou’ll need a custom web.xml configCopy WARBLER_HOME/web.xml.erb to  config/web.xml.erb  Look for it at ~/.rv...
web.xml.erb Filter Entry
Java IntegrationNothing special, just the usual JRuby/JavaintegrationLooks for JARs in the container classpath, WAR orin y...
Calling JavaHTTPS://GITHUB.COM/JRUBY/JRUBY/WIKI/CALLINGJAVAFROMJRUBY
Tips, Tricks and Lessons http://en.wikipedia.org/wiki/File:Coolidge_after_signing_indian_treaty.jpg
Warbler Configgenerate a warbler config filewarble config
Pre-Compile Ruby Classesconfig.features = %w(compiled)
Set Min/Max Runtimes
Set JNDI Source Name
Set Root Path for AppBy default, the root of your app is the WAR nameThis may not be what you want.
Set the Root PathCreate file jboss-web.xml in root of app directoryTell warbler to include it via warble.rb
Bundle Up Files into AGemCan be much faster to build/deploy depending onhow you do it (there are a lot of files!)Make sure ...
Make Your War ExecutableCommand Line:warble executable war In warble.rb: config.features = %w(executable)
Rails ConsoleRails has a “Console Mode” for testingGreat for trying out ActiveRecord queries, etc.Just use “rails console”...
Gem VersionsBe sure to lock down Gem versions when you’rehappy with themDon’t want any last minute “upgrades!”Use bundlerP...
Basic Versioning RulesAfter bundling, always check your Gemfile.lockinto version controlAfter updating your Gemfile, always ...
Handle Database Connection OutageThis is the “default” 500 error page.
You can Customize thisbut...You can do better
Create “Status” URLWant a well known URL that Nagios or a LoadBalancer can checkShould return something useful (and specifi...
Insert Your Own MiddlewareCreate lib/db_check.rb
Insert Your Own MiddlewareInsert it into the stack (application.rb)
You Now Have Generic Status AbilityExtend for other things useful to your application.
HTTP://TORQUEBOX.ORG/
IDEs
Resources
Books
Websiteshttp://www.jruby.org/http://jrubyconf.com/http://vimeo.com/groups/87639(talks from 2010 JRubyConf)http://www.engin...
Twitter Usershttp://twitter.com/#!/headiushttp://twitter.com/#!/nicksiegerhttp://twitter.com/#!/jruby
Questions?
Thank You!Don’t forget to fill out a session evaluation!
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
JRuby in the enterprise
Upcoming SlideShare
Loading in …5
×

JRuby in the enterprise

6,056 views

Published on

This is from a talk I gave at UberConf 2011 in Denver, CO.

Published in: Technology

JRuby in the enterprise

  1. 1. JRuby in the Enterprise
  2. 2. About MeAdvisory Engineer at Constant ContactSpent several years working for Sun/Javasoft inthe distributed computing groupEmail: jerry@gulla.comTwitter: @jerrygullaGithub: github.com/jgulla
  3. 3. What is JRuby?Just a Ruby interpreter running on the JVMRuby 1.8.7 & 1.9.2 compatible.
  4. 4. Text-To-JoinDistributed appWritten in Ruby as a Rails appFour rails apps, actuallyUI, API, Console, SMS Processor.
  5. 5. JRUBY.ORG
  6. 6. Why Ruby?Ruby is…A dynamic, open source programminglanguage with a focus on simplicity andproductivity. It has an elegant syntax that is naturalto read and easy to write.
  7. 7. WHY SHOULD YOU SWITCH TO RUBY? IF YOU ARE HAPPY WITH PERL OR PYTHON, YOU DONT HAVE TO. BUT IF YOU DO FEEL THERE MUST BE A BETTER LANGUAGE, RUBY MAY BE YOUR LANGUAGE OF CHOICE. LEARNING A NEW LANGUAGE IS HARMLESS. IT GIVES YOU NEW IDEAS AND INSIGHTS. YOU DONT HAVE TO SWITCH, JUST LEARN AND TRY IT. YOU MAY FIND YOURSELF COMFORTABLE ENOUGH WITH RUBY TO DECIDE TO SWITCH TO IT. -- YUKIHIRO MATSUMOTO (“MATZ”) HTTP://LINUXDEVCENTER.COM/PUB/A/LINUX/2001/11/29/ RUBY.HTML
  8. 8. Rails 3.x“Optimized for programmer happiness”.
  9. 9. Why Not Grails?Grails is greatNot as big of a break with JavaWanted a bigger shift to bring new ways of doingthings into perspective.
  10. 10. Why JRuby?High performance JVM Highly TunedReal threading Many “pure Ruby” shops using JRuby just for thisVast array of libraries No need to abandon Java libraries.
  11. 11. Why JRuby ContinuedDeployment Options Can deploy as a WAR fileMonitoring Options JVM tools to monitor all availableSpeed of Development.
  12. 12. Don’t Freak the Ops Guys Out HTTP://UPLOAD.WIKIMEDIA.ORG/WIKIPEDIA/EN/F/F4/THE_SCREAM.JPG
  13. 13. http://commons.wikimedia.org/wiki/File:Everest-fromKalarPatar.jpg Scalability
  14. 14. Concurrency is a Myth HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
  15. 15. ILYA GRIGORIK HTTP://WWW.IGVITA.COM/ABOUT/ JRUBY IS, IN FACT, THE ONLY RUBY IMPLEMENTATIONTHAT WILL ALLOW YOU TO NATIVELY SCALE YOUR RUBY CODE ACROSS MULTIPLE CORES. BY COMPILING RUBY TO BYTECODE AND EXECUTING IT ON THE JVM, RUBYTHREADS ARE MAPPED TO OS THREADS WITHOUT A GILIN BETWEEN - THATS AT LEAST ONE REASON TO LOOK INTO JRUBY. HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
  16. 16. “Enterprise” JRuby
  17. 17. “Enterprise” JRuby Cont.MavenLiquibaseJDBCJNDIContainersYou’re favorite commercial, open-source or home-grown library.
  18. 18. Let’s Begin http://commons.wikimedia.org/wiki/File:Begin_road.JPG
  19. 19. http://commons.wikimedia.org/wiki/File:Panama_Canal_Locks_Construct.jpeg Set up Ruby
  20. 20. Ruby Version Manager HTTPS://RVM.BEGINRESCUEEND.COM/
  21. 21. Installing RVMVia git repo (preferred method)bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)Other methods at https://rvm.beginrescueend.com/rvm/install/
  22. 22. Install JRuby (via rvm)rvm install jruby-1.6.3When it’s done, use it: rvm use jruby-1.6.3List of other ruby versions to install: rvm list knownList versions of ruby you have installed: rvm list
  23. 23. JRuby Without RVMAssume Java, JRuby in your pathjruby -S gem ...
  24. 24. Install Railsgem install railsCan pick a specific version with a“-v” flag.
  25. 25. Create Your Rails AppJruby.org hosts a rails template Sets things up to run under native ruby or JRuby You can do this yourself, but it’s handier to start this wayrails new uberconf_demo --template=http://jruby.org Works with native ruby or JRuby.
  26. 26. Jruby.org Template
  27. 27. Demo
  28. 28. Packaging Your App http://en.wikipedia.org/wiki/File:Distribution_differences.jpg
  29. 29. JRuby/Rails/WAR filesIn the Java world, WAR files are standardFortunately, we have bundler Gem to package your Rails app as a WAR fileCan even make it “Executable” for stand-alonetesting!http://caldersphere.rubyforge.org/warbler/
  30. 30. Install itEasy!gem install warbler
  31. 31. Run It http://en.wikipedia.org/wiki/File:Jeanette_Kwakye_cropped.jpgEasy!warble war
  32. 32. Other Useful Optionswarble compiled # Feature: precompile all Ruby fileswarble config # Generate a configuration file to customize your archivewarble executable # Feature: make an executable archivewarble gemjar # Feature: package gem repository inside a warwarble pluginize # Install Warbler tasks in your Rails applicationwarble version # Display version of Warblerwarble war # Create the project war filewarble war:clean # Remove the project war filewarble war:debug # Dump diagnostic information
  33. 33. MavenIn the Java world, Maven is still pretty popular For better or for worseYou can use Maven to invoke warbler to packageyour app.
  34. 34. Database Migrationshttp://en.wikipedia.org/wiki/File:Connochaetes_taurinus_-Wildebeest_crossing_river_-East_Africa.jpg
  35. 35. Database MigrationsRails uses Rake for ActiveRecord migrationsNice, but Hard to scale to multiple developers Hard to deploy to QA/Production systems without using ruby toolset Paranoid DBAs can’t see the SQL before running it.
  36. 36. Enterliquibase.orgVersion control for your databaseOther frameworks (Grails) will be adopting it formigrationsLanguage/Database agnostic.
  37. 37. LiquibaseNothing special about using Liquibase with RailsUse ActiveRecord migrations for initial dev/testing,then migrate to LiquibaseWhen ready, just take “snapshot” of DB config,then roll out new Liquibase changesets.
  38. 38. Handy Liquibase CommandsGenerate initial changelog:java -jar liquibase.jar --classpath=mysql-connector-java-5.1.14-bin.jar --url=jdbc:mysql://localhost/api_development --driver=com.mysql.jdbc.Driver --username=demo --password=password --changeLogFile=db-changelog.xml generateChangeLogDrop all tables so you can start over:dropAllRun updates against a DB:liquibase --changeLogFile=myChangeLog updateJust output SQL, don’t run: updateSQL
  39. 39. USING LIQUIBASEWITH MAVEN
  40. 40. Liquibase with Rails Directlyhttps://github.com/redbeard/liquibase-railsSupposed to add “drop in” migration tasks forJRuby/Rails.
  41. 41. Liquibase Changeset
  42. 42. JNDI Database Access DATABASE.YML
  43. 43. Servlet FiltersYou’ll need a custom web.xml configCopy WARBLER_HOME/web.xml.erb to config/web.xml.erb Look for it at ~/.rvm/gems/jruby-1.6.2/gems/ warbler-1.3.1/web.xml.erb HTTP://EN.WIKIPEDIA.ORG/WIKI/FILE:DICHROIC_FILTERS.JPG
  44. 44. web.xml.erb Filter Entry
  45. 45. Java IntegrationNothing special, just the usual JRuby/JavaintegrationLooks for JARs in the container classpath, WAR orin yourapp/lib
  46. 46. Calling JavaHTTPS://GITHUB.COM/JRUBY/JRUBY/WIKI/CALLINGJAVAFROMJRUBY
  47. 47. Tips, Tricks and Lessons http://en.wikipedia.org/wiki/File:Coolidge_after_signing_indian_treaty.jpg
  48. 48. Warbler Configgenerate a warbler config filewarble config
  49. 49. Pre-Compile Ruby Classesconfig.features = %w(compiled)
  50. 50. Set Min/Max Runtimes
  51. 51. Set JNDI Source Name
  52. 52. Set Root Path for AppBy default, the root of your app is the WAR nameThis may not be what you want.
  53. 53. Set the Root PathCreate file jboss-web.xml in root of app directoryTell warbler to include it via warble.rb
  54. 54. Bundle Up Files into AGemCan be much faster to build/deploy depending onhow you do it (there are a lot of files!)Make sure to test it
  55. 55. Make Your War ExecutableCommand Line:warble executable war In warble.rb: config.features = %w(executable)
  56. 56. Rails ConsoleRails has a “Console Mode” for testingGreat for trying out ActiveRecord queries, etc.Just use “rails console” to invoke it.
  57. 57. Gem VersionsBe sure to lock down Gem versions when you’rehappy with themDon’t want any last minute “upgrades!”Use bundlerPut Gemfile.lock under source control.
  58. 58. Basic Versioning RulesAfter bundling, always check your Gemfile.lockinto version controlAfter updating your Gemfile, always runbundle install first.When running an executable, ALWAYS usebundle exec [command] The only exception is the rails command!http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/
  59. 59. Handle Database Connection OutageThis is the “default” 500 error page.
  60. 60. You can Customize thisbut...You can do better
  61. 61. Create “Status” URLWant a well known URL that Nagios or a LoadBalancer can checkShould return something useful (and specific toyour test).
  62. 62. Insert Your Own MiddlewareCreate lib/db_check.rb
  63. 63. Insert Your Own MiddlewareInsert it into the stack (application.rb)
  64. 64. You Now Have Generic Status AbilityExtend for other things useful to your application.
  65. 65. HTTP://TORQUEBOX.ORG/
  66. 66. IDEs
  67. 67. Resources
  68. 68. Books
  69. 69. Websiteshttp://www.jruby.org/http://jrubyconf.com/http://vimeo.com/groups/87639(talks from 2010 JRubyConf)http://www.engineyard.com/open-source
  70. 70. Twitter Usershttp://twitter.com/#!/headiushttp://twitter.com/#!/nicksiegerhttp://twitter.com/#!/jruby
  71. 71. Questions?
  72. 72. Thank You!Don’t forget to fill out a session evaluation!

×