• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Découplez votre appli en micro-APIs
 

Découplez votre appli en micro-APIs

on

  • 4,566 views

 

Statistics

Views

Total Views
4,566
Views on SlideShare
660
Embed Views
3,906

Actions

Likes
0
Downloads
1
Comments
0

8 Embeds 3,906

http://www.nicolasblanco.fr 3825
http://www.dev.localhost.com 37
http://slainer68.github.io 19
http://localhost 12
http://dev.com.local 8
http://translate.googleusercontent.com 3
https://www.google.fr 1
http://www.google.fr 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

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

    Découplez votre appli en micro-APIs Découplez votre appli en micro-APIs Presentation Transcript

    • DECOUPEZ VOTRE APPLI EN MICRO-APIS SOA ON RAILS :-) by Nicolas Blanco http://twitter.com/slainer68
    • CODE SPAGHETTI ? USINE A GAZ ?
    • THIN CONTROLER / FAT MODEL MODULES CLASSES ACTIVE MODELVOTRE PROPRE ENGINE / GEM !
    • DECOUPLAGE EN SOA ?DECOUPER UNE FONCTIONNALITE EN MICRO-API INDEPENDANCE API REST JSON STOCKAGE RAPIDE (REDIS ?) INCONVENIENTS
    • BUTREPONSE INSTANTANEE EN JSONID UNIQUE POUR CHAQUE JOB
    • EXEMPLE=> POST api.myapp.com/imports{ id: “42”, status: “scheduled”, ... }=> GET api.myapp.com/imports/42{ id: “42”, status: “finished”, result: { ... }, finished_at: ... }
    • LES GEMS SIDEKIQ REDIS GRAPEREDIS PERSISTENCE FOREMAN
    • FOREMAN web: bundle exec thin start -p $PORTworker: bundle exec sidekiq -r ./workers/import_xml.rb -c 2
    • 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
    • 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
    • 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
    • ALWAYS REFACTOR !