Your SlideShare is downloading. ×
0
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Découplez votre appli en micro-APIs

8,193

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,193
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
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. DECOUPEZ VOTRE APPLI EN MICRO-APIS SOA ON RAILS :-) by Nicolas Blanco http://twitter.com/slainer68
  • 2. CODE SPAGHETTI ? USINE A GAZ ?
  • 3. THIN CONTROLER / FAT MODEL MODULES CLASSES ACTIVE MODELVOTRE PROPRE ENGINE / GEM !
  • 4. DECOUPLAGE EN SOA ?DECOUPER UNE FONCTIONNALITE EN MICRO-API INDEPENDANCE API REST JSON STOCKAGE RAPIDE (REDIS ?) INCONVENIENTS
  • 5. BUTREPONSE INSTANTANEE EN JSONID UNIQUE POUR CHAQUE JOB
  • 6. EXEMPLE=> POST api.myapp.com/imports{ id: “42”, status: “scheduled”, ... }=> GET api.myapp.com/imports/42{ id: “42”, status: “finished”, result: { ... }, finished_at: ... }
  • 7. LES GEMS SIDEKIQ REDIS GRAPEREDIS PERSISTENCE FOREMAN
  • 8. FOREMAN web: bundle exec thin start -p $PORTworker: bundle exec sidekiq -r ./workers/import_xml.rb -c 2
  • 9. MODEL IMPORTmodule Models class Import include Redis::Persistence property :state, default: "scheduled" property :created_at property :finished_at property :fail_message property :result, default: {} def start! update_attributes(state: "started") end def finish! update_attributes(state: "finished", finished_at: Time.now) end def fail_with!(message) update_attributes(state: "failed", fail_message: message) end end end
  • 10. class API < Grape::API version v1, using: :header, vendor: "pluriporter" format :json resources :imports do desc "Creates new import from XML data" params do requires :xml, type: String, desc: "XML data" end post do Models::Import.create(created_at: Time.now).tap do |import| Workers::Import.perform_async(import.id, params[:xml]) end endend
  • 11. WORKERmodule Workers class Import include Sidekiq::Worker def perform(import_id, xml) require File.expand_path("../../models/import", __FILE__) import = Models::Import.find(import_id) import.start! begin # ... end rescue => e import.fail_with!(e.to_s) raise e end import.finish! end
  • 12. ALWAYS REFACTOR !

×