Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Microservices With SenecaJS

1,725 views

Published on

Microservices With SenecaJS
Websites: https://www.designveloper.com
Visit our blog https://www.designveloper.com/blog
Like Facebook page https://www.facebook.com/designveloper/

Published in: Technology

Microservices With SenecaJS

  1. 1. 9/19/2016 1 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal MICROSERVICES WITH SENECAJS Trung Dang
  2. 2. 9/19/2016 2 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Agenda  What is microservices?  Factors affect when building up the system with microservices  Introducing SenecaJS  SenecaJS with RabbitMQ  Integrate with Consul, RabbitMQ  Talk is cheap – Show me the code ------ DEMO TIME  Q/A
  3. 3. 9/19/2016 3 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal What is Microservices?
  4. 4. 9/19/2016 4 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Monolithic Application Model 1. How to scale this application to serve more customer requests? 2. The Payments Module is taking very long time to process the requests. Is there any solution with cheap cost?
  5. 5. 9/19/2016 5 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal
  6. 6. 9/19/2016 6 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Introducing Microservices Architecture The Benefits of Microservices • Faster and simpler deployments and rollbacks • Elimination of long-term commitment to a single technology stack • Improved fault isolation • Independently scalable services • Technology diversity • Ability to write new features as plugins The Drawbacks of Microservices • Increased network communication • Serialization between microservices • Additional complexity in testing a distributed system • Increased complexity in deployment
  7. 7. 9/19/2016 7 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Scaling an application – The Art Of Scalability
  8. 8. 9/19/2016 8 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal
  9. 9. 9/19/2016 9 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Main factors need to review when building up microservices system?  API Gateway OR Direct Client to Microservice Communication  Stateless / Stateful  Invoking / Consuming service’s action  Serialization between microservices  Service Discovery  Transaction  Eventual consistency  CI / CD, configuration deployment  Service Health check
  10. 10. 9/19/2016 10 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal Introducing SenecaJS
  11. 11. 9/19/2016 11 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal
  12. 12. 9/19/2016 12 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Who’s using it
  13. 13. 9/19/2016 13 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS Philosophy • Pattern Matching: instead of fragile service discovery, you just let the world know what sort of messages you are about. • Transport Independence: you can send messages between services in many ways, all hidden from your business logic.
  14. 14. 9/19/2016 14 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS – First microservice var seneca = require('seneca')() seneca.add('role:math,cmd:sum', (msg, reply) => { reply(null, { answer: (msg.left + msg.right) }) }) seneca.act({ role: 'math', cmd: 'sum', left: 1, right: 2 }, (err, result) => { if (err) return console.error(err) console.log(result) } )
  15. 15. 9/19/2016 15 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS with AMQP Transport • seneca-amqp-transport https://github.com/seneca-contrib/seneca-amqp-transport • It is a plugin to allow seneca listeners and clients to communicate over AMQP • Currently support AMQP 0.9.1 • For AMQP 1.0, please use seneca-servicebus-transport • It use customized RPC (Remote Procedure Call) to implement the transportation.
  16. 16. 9/19/2016 16 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS with AMQP Transport – Show me the code var seneca = require('seneca')() .use('seneca-amqp-transport') .add('role:create,foo:1', function (args, done) { console.log(“Server: with i = " + args.zed); done(null, { zed: args.zed, bar: args.zed + 1}) }) .listen({ type: 'amqp', pin: ‘module:test', url: 'amqp://trungdt:123absoft.vn@pm.absoft.vn:5672’ }); var client = seneca .client({ type: 'amqp', pin: ‘module:test’ url: 'amqp://trungdt:123absoft.vn@pm.absoft.vn:5672’ }); for (var i = 0; i < 10; i++) { client.act('role:create,foo:1,zed:' + i , function (err, ret) { console.log(‘Client: with i = ‘ + ret.zed); }); }
  17. 17. 9/19/2016 17 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS with AMQP Transport – How it works Routing by topic: module:test Consumer Queue Individual Queue created by each Client
  18. 18. 9/19/2016 18 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Microservices using SenecaJS, RabbitMQ, Consul, SequelizeJS and FeathersJS servicebase Database Models Service Logic Service B NGINX–LoadBalancer GatewayAPI1GatewayAPI2 RabbitMQ Configuration Storage & Health Checker Postgresql Docker servicebase Database Models Service Logic Service A
  19. 19. 9/19/2016 19 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Introducing package servicebase https://bitbucket.org/trungdang_apium/microservices_servicebase Features : • Listener / Client mode, with AMQP Transport or HTTP Transport • Promisify all functions • Use Consul as Configuration Storage & Service Health Checher • Support multiple database adapters (Sequelize). Postgresql & Sqlite are build-in support • Loggly logs monitoring • Support Authorization when consuming the service’s action • Error handler: no more terminating your service because of TIMEOUT or fatal$ error • Including unit-test helper • Including typed-definitions file
  20. 20. 9/19/2016 20 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal Show Me Your Code
  21. 21. 9/19/2016 21 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal Q&A Thank you very much

×