Torquebox

  • 546 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
546
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
5
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Torquebox 2 Przemysław Wróblewski
  • 2. Co to jest Torquebox ?● Torquebox to zmodyfikowany JBoss AS 7, który integruje środowisko JEE ze środowiskiem Rubiego.● Dostarcza interfejsy Ruby do usług dostarczanych przez server aplikacji● pozwala uruchamiać Jave i Ruby w tym samym kontenerze aplikacji● umożliwia szybkie i proste sklastrowanie aplikacji
  • 3. JRuby• połączenie Ruby i JVM• Java i Ruby mogą się integrowaćrequire javajava.lang.System.setProperty(key,value)java_import java.util.HashMaphashmap = HashMap.newhashmap[key] = value
  • 4. JRuby
  • 5. Torquebox - co jest w środku ?
  • 6. Kolejki
  • 7. Workery - konfiguracjaconfig/torquebox.yml:queues: /queues/raw_offer: durable: falsemessaging: default_message_encoding: marshal /queues/raw_offer: RawOfferMessageProcessor: concurrency: 18
  • 8. Workeryclass RawOfferMessageProcessor < TorqueBox::Messaging::MessageProcessor include TorqueBox::Injectors include AirbrakeReportable def on_message(body) out_msg = OfferChecker.new.check body if out_msg queue = inject(/queues/offer) queue.publish(out_msg) end end def on_error(error) notify_airbrake(error, {parameters: {message: @message.decode}}) endend
  • 9. Backgroundablestandardowa klasa + blokujące wywołanieclass Something def foo sleep 5 endendsomething = Something.newsomething.foo
  • 10. Backgroundablewywołanie nie blokująceclass Something include TorqueBox::Messaging::Backgroundable def foo sleep 5 endendsomething = Something.newsomething.background.foo
  • 11. Backgroundablesprawdz stan zadania nieblokującegosomething = Something.newfuture = something.background.foofuture.started?future.complete?future.error?future.result
  • 12. Backgroundablesprawdz stan zadania nieblokującegoclass Something def foo ... count+=1 future.status=count ... end something = Something.newend future = something.background.foo future.status_changed? future.status #=>42
  • 13. Cronconfig/torquebox.yml:jobs: data_import: description: "Import danych z importu 2.0" job: DataImportJob cron: 0 10 18 * * ? singleton: true
  • 14. Cronapp/jobs/data_import_job.rb:class DataImportJob def initialize dump_directory = File.join(Date.today.to_s(:number)) @importer = DataImporter.new(dump_directory) end def run ... endend
  • 15. Usługiapp/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 ...end
  • 16. Usługiconfig/torquebox.yml:services: TimeMachine: config: queue: /queue/time
  • 17. Resource Injectionapp/controllers/my_contoller.rb:class MyController < ApplicationController include TorqueBox::Injectors def stop # Service defined with a unique name in torquebox.yml the_torque_service = inject( service:TimeMachine ) the_torque_service.stop endend
  • 18. Resource Injectionmetodyinject_cdi(...)Injects CDI resources by literal class name.inject_queue(...)Injects a messaging queue by literal name.inject_topic(...)Injects a messaging topic by literal name.inject_naming(...)Injects JNDI resources by literal name.inject_msc(...)Injects MSC services by literal name.inject_service(...)Injects a TorqueBox application service component
  • 19. Cache
  • 20. CacheRailsCachingconfig/application.rb:module MyApp class Application < Rails::Application ... config.cache_store=:torque_box_store endend
  • 21. Cachebezpośredni dostep do własnej przestrzeniinclude ActiveSupport::Cachemy_cache = TorqueBoxStore.new(:name=>MyCache, :mode=>:replicated, :sync=>true)my_cache.put(klucz,wartość)my_cache.put_if_absent(klucz,inna wartość)my_cache.replace(klucz,jeszcze inna wartość)Torquebox.transaction do my_cache.remove( klucz )endmy_cache.transaction do my_cache.put_if_absent(klucz,zupełnie inna wartość)end
  • 22. Cachetryby pracyLocalDomyślny, wszystko jest trzymane w ramach pojedyńczego nodea, odpowiedniktrzymania w pamięci ale pozwala na zapewnienie persystencji, daje transakcjeInvalidationDomyślny w trybie clustra, nie wysyla zmian do innych nodeów tylko komunikaty oprzedawnieniu klucza. Dobrze sprawuje sie do cacheowania widoków i innychszybkich do odtworzenia wartościReplicatedKopiuje zawartość klucza do kazdego nodea, odczyty będą wykonywane jużlokalnieDistributedczyli sharding + replikacja, memcache, redis schowajcie sie :-P
  • 23. Cache noSQL data mapperrequire dm-corerequire datamapper/dm-infinispan-adapterclass Beer include DataMapper::Resource property :id, Serial property :name, String property :desc, Text property :likes, Integer property :created_at, DateTimeendDataMapper.setup(:default, :adapter=>infinispan, :persist=>db/infinispan)DataMapper::Model.raise_on_save_failure = trueDataMapper.finalizeBeer.create(:name=>Catawba White Zombie Ale, :description=>A Belgium white ale made with coriander, orange peel, and wheat.This beer is refreshing and tasty with a sweet and shimmering frothy head., :created_at=>Time.now)beers = Beer.all(:desc.like => "%belgium%", :name.like => "%ale%")
  • 24. monitoring
  • 25. monitoring
  • 26. monitoring
  • 27. jboss2:8080/monitoring
  • 28. Torquebox 2 http://torquebox.org/TorqueBox – moc Javy, piękno Rubiego – Marek Goldmann Wideo: http://video-it.pl/2011/07/torquebox-moc-javy-piekno-rubiego-marek-goldmann/ Slajdy: http://www.slideshare.net/marekgoldmann/torquebox-moc-javy-pikno-rubiego Demo: https://github.com/goldmann/confitura-2011-torquebox-demo