Railsconf2014

 Railsconf2014

Rails as an SOA client - Railsconf 2014

Fe6b81005d1553accd6b2a28f6a2bef1?s=128

Pete Hodgson

April 23, 2014
Tweet

Transcript

  1. RAILS AS 
 AN SOA CLIENT Pete Hodgson | @ph1

    | phodgson@thoughtworks.com
  2. @ph1 rails DB DB rails app

  3. @ph1 rails a service a service DB DB rails app

  4. @ph1 rails a service a service a service a service

    DB DB rails app
  5. @ph1 rails a service a service a service a service

    rails app
  6. me me me Pete Hodgson Consultant at ThoughtWorks @ph1 blog.thepete.net

  7. @ph1 ACT ONE INDEPENDENCE CO-DEPENDENCE and

  8. @ph1 a service rails app a service

  9. @ph1 SELECTION OF DEALS ARRAY OF ENTICING PRODUCT CATEGORIES

  10. @ph1 rails app product service deals service

  11. @ph1 rails app

  12. @ph1 rails app product service deals service RED TEAM GREEN

    TEAM BLUE TEAM
  13. @ph1 CONWAY’S LAW

  14. @ph1 SYSTEM ARCHITECTURE HOW PEOPLE WORK TOGETHER AFFECTS

  15. @ph1 HOW PEOPLE WORK TOGETHER AFFECTS SYSTEM ARCHITECTURE

  16. @ph1 rails app product service deals service RED TEAM GREEN

    TEAM BLUE TEAM
  17. @ph1 WHO’S BUG IS IT ANYWAY?

  18. @ph1 rails app deals service product service

  19. @ph1 fake service fake service rails BOUNDED INTEGRATION
 TESTS rails

    app
  20. @ph1 IN PROCESS OUT-OF-PROCESS vcr webmock mimic moco stubby montebank

  21. @ph1 deals service product service rails product service deals service

    ✓ ? ? rails app
  22. @ph1 CONTRACT TESTS

  23. @ph1 rails app product service deals service

  24. @ph1 product service deals service rails app

  25. @ph1 (or minitest, or whatever) plain old rspec pacto pact

  26. END-TO-END TESTS UNIT TESTS BOUNDED INTEGRATION TESTS SERVICE A CONTRACT

    TESTS SERVICE B CONTRACT TESTS SERVICE D CONTRACT TESTS SERVICE C CONTRACT TESTS FUNCTIONAL TESTS
  27. END-TO-END TESTS UNIT TESTS BOUNDED INTEGRATION TESTS SERVICE A CONTRACT

    TESTS SERVICE B CONTRACT TESTS SERVICE D CONTRACT TESTS SERVICE C CONTRACT TESTS FUNCTIONAL TESTS
  28. @ph1 ACT TWO SERVICE GATEWAYS

  29. @ph1 faraday

  30. @ph1 rack

  31. CACHING AUTHENTICATION HTTP SERVER COOKIES LOGGING rack

  32. @ph1 use Rack::Sendfile use ActionDispatch::Static use Rack::Lock use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x000000029a0838> use

    Rack::Runtime use Rack::MethodOverride use ActionDispatch::RequestId use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use ActionDispatch::RemoteIp use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::Migration::CheckPending use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache use ActionDispatch::Cookies use ActionDispatch::Session::CookieStore use ActionDispatch::Flash use ActionDispatch::ParamsParser use Rack::Head use Rack::ConditionalGet use Rack::ETag run MyApp::Application.routes
  33. @ph1 CACHING AUTHENTICATION HTTP CLIENT SERIALIZATION faraday

  34. @ph1 class BikeStationGateway STATIONS_PATH = '/stations/json' ! def initialize( base_url

    = 'http://bayareabikeshare.com' ) @conn = Faraday.new(:url => base_url ) do |faraday| faraday.use :instrumentation faraday.response :json faraday.request :encode_json faraday.response :follow_redirects faraday.response :logger faraday.adapter Faraday.default_adapter end end ! def stations response = @conn.get(STATIONS_PATH) # ... parse response.body into a list of stations end end
  35. @ph1 class BikeStationGateway STATIONS_PATH = '/stations/json' ! def initialize( base_url

    = 'http://bayareabikeshare.com' ) @conn = Faraday.new(:url => base_url ) do |faraday| faraday.use :instrumentation faraday.response :json faraday.request :encode_json faraday.response :follow_redirects faraday.response :logger faraday.adapter Faraday.default_adapter end end ! def stations response = @conn.get(STATIONS_PATH) # ... parse response.body into a list of stations end end
  36. @ph1 a service a service service gateways

  37. @ph1 hexagonal 
 architecture

  38. @ph1 CACHING AUTHENTICATION HTTP CLIENT SERIALIZATION

  39. @ph1 { “JSON”: “parsing” } ! <xml> <parsing/> </xml>

  40. @ph1 { "meta": { "response-time": "141", "server": "http://foo.com", ... },

    "product": { "uid": "151231511315083", "summary": { "title": "A Book Of Things", "shortDescription": “.....", ... }, "author": { "firstName": "Bob", "lastName": "Smith", ... }, ... } }
  41. @ph1 hashie lazy_doc embedded_doc representable

  42. @ph1 CACHING AUTHENTICATION HTTP CLIENT SERIALIZATION

  43. @ph1 rails app product service pricing service

  44. @ph1 cache the crap out of this! /prod-images/15123_front.png

  45. @ph1 cache the crap out of this too! /products/15123.json

  46. @ph1 CACHING AUTHENTICATION HTTP CLIENT SERIALIZATION

  47. @ph1 CACHING AUTHENTICATION HTTP CLIENT SERIALIZATION

  48. @ph1 class BikeStationGateway STATIONS_PATH = '/stations/json' ! def initialize( base_url

    = 'http://bayareabikeshare.com' ) @conn = Faraday.new(:url => base_url ) do |faraday| faraday.use :instrumentation faraday.response :json faraday.request :encode_json faraday.response :follow_redirects faraday.response :logger ! faraday.use FaradayMiddleware::RackCompatible, Rack::Cache::Context, :metastore => "file:#{cache_dir}/faraday/meta", :entitystore => “file:#{cache_dir}/faraday/body", :ignore_headers => %w[Set-Cookie X-Content-Digest] ! ! faraday.adapter Faraday.default_adapter end end end
  49. @ph1 on the web
 OF the web

  50. @ph1 EPILOGUE SOME
 PRINCIPLES

  51. @ph1 CONWAY’S LAW

  52. @ph1 DOMAIN DRIVEN DESIGN

  53. @ph1 POSTEL’S LAW

  54. @ph1 HEXAGONAL ARCHITECTURE

  55. @ph1 EMBRACE
 THE WEB

  56. THANKS! Pete Hodgson @ph1
 phodgson@thoughtworks.com

  57. 57 SLIDES => Pete Hodgson @ph1
 phodgson@thoughtworks.com