microservices with senecajs

Post on 19-Jan-2017

447 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

9/7/2016 1

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: Internal

MICROSERVICES WITH SENECAJSTrung Dang

9/7/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

9/7/2016 3

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: Internal

What is Microservices?

9/7/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?

9/7/2016 5

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

9/7/2016 6

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

Introducing Microservices ArchitectureThe 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

9/7/2016 7

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

Scaling an application – The Art Of Scalability

9/7/2016 8

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

9/7/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

9/7/2016 10

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: Internal

Introducing SenecaJS

9/7/2016 11

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

9/7/2016 12

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

Who’s using it

9/7/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.

9/7/2016 14

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

SenecaJS – First microservicevar 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) })

9/7/2016 15

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

SenecaJS with AMQP Transport

• seneca-amqp-transporthttps://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.

9/7/2016 16

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: InternalSecurity Classification: Internal

SenecaJS with AMQP Transport – Show me the codevar 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); });}

9/7/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

9/7/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 BNGI

NX

– Lo

ad B

alan

cer

Gate

way

API

1Ga

tew

ay A

PI 2

Rabb

itMQ

Configuration Storage & Health Checker

Post

gres

ql

Docker

servicebase

Database Models

Service Logic

Service A

9/7/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

9/7/2016 20

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: Internal

Show Me Your Code

9/7/2016 21

CLICK TO EDIT MASTER TITLE STYLE

Security Classification: Internal

Q&AThank you very much

top related