SlideShare a Scribd company logo
9/30/16 1
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: Internal
MICROSERVICES WITH SENECAJS
Trung Dang Session 2
9/30/16 2
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Agenda – Session 2
▪ Docker
▪ AMQP / RabbitMQ: What is it?
▪ SenecaJS transportation with AMQP
▪ Multiple service instances: PM2 or Docker?
▪ Consul - Service health checker & Configuration
▪ JWT for Auth
▪ Introducing servicebase package
▪ Q/A
9/30/16 3
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Sample source code is available at
https://github.com/immanuel192/seneca-with-rabbitmq-seminar
9/30/16 4
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: Internal
Review Session 1
9/30/16 5
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/30/16 6
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
9/30/16 7
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Microservices with Seneca, RabbitMQ, Consul, and FeathersJS
servicebase
Database Models
Service Logic
Service B
NGINX–LoadBalancer
GatewayAPI1GatewayAPI2
RabbitMQ
Configuration Storage & Health Checker
Docker
servicebase
Database Models
Service Logic
Service A
Redis
9/30/16 8
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Docker - https://www.docker.com/
9/30/16 9
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
AMQP & RabbitMQ. What is it?
• RabbitMQ is a messaging broker - an intermediary for messaging.
9/30/16 10
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Service 1
RabbitMQ - How it works
Service 2
Queue
Queue
Exchange
client
Service 1
9/30/16 11
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
docker run -d 
--hostname rabbitmq-server 
-p 5672:5672 -p 15672:15672 
--name rabbitmq-server 
-e RABBITMQ_DEFAULT_USER=username -e
RABBITMQ_DEFAULT_PASS=password 
rabbitmq:management
Docker – Start RabbitMQ
9/30/16 12
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/30/16 13
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS – Your first microservice
let seneca = require('seneca')()
seneca.add('service:math,cmd:sum', (msg, reply) => {
reply(null, { answer: (msg.left + msg.right) })
})
seneca.act({ service: 'math', cmd: 'sum', left: 1, right: 2 },
(err, result) => {
if (err) return console.error(err)
console.log(result)
}
)
9/30/16 14
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS – Pattern Matching
seneca.add('service:math,cmd:sum', (msg, reply) => {
reply(null, { answer: (msg.left + msg.right) })
})
Can this service return the result as an integer only
whenever I need?
9/30/16 15
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS – Pattern Matching - 2
seneca.add(‘service:math,cmd:sum’, function (msg,
reply) {
if (msg.integer === true){
reply(null, { answer: (parseInt(msg.left) +
parseInt(msg.right)) })
}
else{
reply(null, { answer: (msg.left + msg.right) })
}
})
9/30/16 16
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS – Pattern Matching - 3
seneca.add('service:math,cmd:sum', (msg, reply) => {
reply(null, { answer: (msg.left + msg.right) })
})
seneca.add('service:math,cmd:sum,integer:true', (msg, reply) =>
{
reply(null, {
answer: ( parseInt(msg.left) +
parseInt(msg.right)
)
})
})
9/30/16 17
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS – Pattern Matching - Recap
• Matches against top level properties of JSON message
• Patterns are unique
• Specialised patterns win over generic patterns
• Competing patterns win based on value
9/30/16 18
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS – Transport
• Seneca can work with multiple transports
• Available transports: RabbitMQ, Kafka, Redis, BeansTalk, mqp,
Mesh, SQS, NSQ, ZeroMQ, NATS, Azure Service Bus, NServiceBus,
Aliyun-MNS, Google Cloud PubSub
• HTTP/TCP is supported by default
9/30/16 19
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
9/30/16 20
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS with AMQP Transport – Server
let seneca = require('seneca')()
.use('seneca-amqp-transport')
.add('service:myService,cmd:create', function (args, done) {
console.log(`From client ${args.clientId}: ${args.i}`);
done(null, { i: args.i })
})
.listen({
type: 'amqp',
pin: 'service:myService',
url: 'amqp://username:password@rabbitmq-server:5672'
})
9/30/16 21
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS with AMQP Transport – Client
let clientId = 1
let args = process.argv.slice(2)
if (args.length > 0) {
clientId = args[0]
}
let client = require('seneca')().use('seneca-amqp-transport').client({
type: 'amqp',
pin: 'service:myService',
url: 'amqp://username:password@rabbitmq-server:5672'
})
let i = 0
setInterval(function() {
client.act(`service:myService,cmd:create,clientId:${clientId},i:${i}`,
function(err, ret) {
console.log('Client: received i = ' + ret.i);
});
i++;
}, 100)
9/30/16 22
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
SenecaJS with AMQP Transport – How it works
Consumer Queue
Queue
myServiceclient
Request
reply_to = my_client_id
correlation_id = abc
Reply
correlation_id = abc
Queue
Client Queue
Routing
pin = service:myService
Routing
pin = my_client_id
9/30/16 23
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: Internal
DEMO
9/30/16 24
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: Internal
TEA-BREAK
9/30/16 25
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
PM2
• Advanced process manager for production Node.js applications.
Load balancer, logs facility, startup script, micro service
management, at a glance.
• We can use pm2 to start our services with scale
pm2 start config-file.json
pm2 start your-app.js
pm2 scale app-name instance-number
9/30/16 26
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
PM2 - Sample JSON configuration
File start-service.json
{
apps: [
{
name: "myService",
script: "index.js",
watch: false,
env: {
"NODE_ENV": "development"
},
instances: 1
}
]
}
9/30/16 27
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Docker – Run your service in multiple container
export pwd=`pwd`
docker run -d --link=rabbitmq-server -v "$pwd":/app 
mhart/alpine-node:latest node /app/server.js
docker run -d --link=rabbitmq-server -v "$pwd":/app 
mhart/alpine-node:latest node /app/client.js 1
docker run -d --link=rabbitmq-server -v "$pwd":/app 
mhart/alpine-node:latest node /app/client.js 2
9/30/16 28
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Configuring your service
• How can we protect our configuration for production ENV?
• How can we monitor our services’s heath?
References:
• Health - Consul
https://www.consul.io/docs/agent/http/health.html
• Key / Value store - Consul
https://www.consul.io/docs/agent/http/kv.html
9/30/16 29
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
JWT for Authentication
• JWT stands for Json Web Token
• No more cookies.
• JWT has 3 parts: header.body.signature
Example:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzY290Y2guaW8iLCJleHAiOjEzMDA4MTkzODAsIm5hbWU
iOiJDaHJpcyBTZXZpbGxlamEiLCJhZG1pbiI6dHJ1ZX0.03f329983b86f7d9a9f5fef85305880101d5e302afafa20
154d094b229f75
• JWT helps to verify the sender, authorize the request, prevent man
in middle and good with CORS.
9/30/16 30
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Introducing servicebase package
https://www.npmjs.com/package/servicebase
Features :
• Listener / Client mode, with AMQP Transport or HTTP Transport
• Promisify all functions
• Use Consul as Configuration Storage & Service Health Checker
• Support multiple database adapters. Postgresql & Sqlite are build-in supported adapters
• Use Loggly as logs monitoring service
• Support Authorization when consuming the service’s action
• Error handler: no more terminating your service because of TIMEOUT or fatal$ error
• Including test helper
• Including typed-definitions file
9/30/16 31
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: Internal
DEMO
9/30/16 32
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Testing your services
• Use sqlite in-memory for integration test
• For unit-test: test your logic-class instead of test the function you
registered with seneca
• For integration-test with other services: use pm2 & rabbitmq
9/30/16 33
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Microservices are the kind of SOA. Microservices must be
independently deployable, whereas SOA services are often
implemented in deployment monoliths. Classic SOA is more platform
driven, so microservices offer more choices in all dimensions.
Torsten Winterberg (Oracle ACE Director)
Microservices vs SOA
9/30/16 34
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: Internal
Q&A
Thank you very much
9/30/16 35
CLICK TO EDIT MASTER TITLE STYLE
Security Classification: InternalSecurity Classification: Internal
Stateful / Stateless & Authorization
• Stateful means that there is memory of the past. Previous
transactions are remembered and may affect the current
transaction.
• Stateless means there is no memory of the past. Every transaction
is performed as if it were being done for the very first time.
• In Stateless service, we use JWT (Json Web Token) for
Authentication. No more Cookies.
• Authorization will be done by each service regarding to the
authenticated user.

More Related Content

What's hot (20)

PDF
Complete MVC on NodeJS
Hüseyin BABAL
 
PDF
Introducing Vault
Ramit Surana
 
PPTX
Node js training (1)
Ashish Gupta
 
PPTX
Building microservices with vert.x 3.0
Agraj Mangal
 
PPTX
Building a production ready meteor app
Ritik Malhotra
 
PDF
Vagrant for real (codemotion rome 2016)
Michele Orselli
 
PDF
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
PDF
Immutable AWS Deployments with Packer and Jenkins
Manish Pandit
 
PPT
Nodejs - Building a RESTful API
Sang Cù
 
PDF
Introduction to Ansible
Michael Bahr
 
PPTX
Building Better Backdoors with WMI - DerbyCon 2017
Alexander Polce Leary
 
PDF
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Jeff Horwitz
 
PDF
Flask jwt authentication tutorial
Katy Slemon
 
PDF
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
NAVER D2
 
PPTX
Introduction to vSphere APIs Using pyVmomi
Michael Rice
 
PDF
Using Vault to decouple MySQL Secrets
Derek Downey
 
PDF
Building Bizweb Microservices with Docker
Khôi Nguyễn Minh
 
PPTX
Owin and Katana
Ugo Lattanzi
 
PPTX
Introduction to node.js by jiban
Jibanananda Sana
 
PDF
Sails.js Intro
Nicholas Jansma
 
Complete MVC on NodeJS
Hüseyin BABAL
 
Introducing Vault
Ramit Surana
 
Node js training (1)
Ashish Gupta
 
Building microservices with vert.x 3.0
Agraj Mangal
 
Building a production ready meteor app
Ritik Malhotra
 
Vagrant for real (codemotion rome 2016)
Michele Orselli
 
Introduction to node js - From "hello world" to deploying on azure
Colin Mackay
 
Immutable AWS Deployments with Packer and Jenkins
Manish Pandit
 
Nodejs - Building a RESTful API
Sang Cù
 
Introduction to Ansible
Michael Bahr
 
Building Better Backdoors with WMI - DerbyCon 2017
Alexander Polce Leary
 
Chickens & Eggs: Managing secrets in AWS with Hashicorp Vault
Jeff Horwitz
 
Flask jwt authentication tutorial
Katy Slemon
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
NAVER D2
 
Introduction to vSphere APIs Using pyVmomi
Michael Rice
 
Using Vault to decouple MySQL Secrets
Derek Downey
 
Building Bizweb Microservices with Docker
Khôi Nguyễn Minh
 
Owin and Katana
Ugo Lattanzi
 
Introduction to node.js by jiban
Jibanananda Sana
 
Sails.js Intro
Nicholas Jansma
 

Viewers also liked (16)

PPTX
Latest Meteor JS News
Designveloper
 
PDF
Meet song nhi your virtual financial assistance
Designveloper
 
PDF
Rapid Digital Innovation: How Node.js Delivers
Richard Rodger
 
PDF
How microservices fail, and what to do about it
Richard Rodger
 
PPTX
Unity3D With Meteor
Designveloper
 
PDF
Richard rodger technical debt - web summit 2013
Richard Rodger
 
PPTX
Introducción a microservicios
Erasmo Domínguez Jiménez
 
PPTX
Multi tenancy - Wining formula for a PaaS
WSO2
 
PDF
The Seneca Pattern at EngineYard Distill 2013 Conference
Richard Rodger
 
PPTX
Building a Multi-tenanted SaaS with Node.js
Eoin Shanaghy
 
PDF
Integrating PostgreSql with RabbitMQ
Gavin Roy
 
PDF
Bizweb Microservices Architecture
Khôi Nguyễn Minh
 
PPTX
ITLC HN 14 - Bizweb Microservices Architecture
IT Expert Club
 
PPTX
Distributed Transaction in Microservice
Nghia Minh
 
PPTX
JSX Design Overview (日本語)
Kazuho Oku
 
PPTX
JSX
Kazuho Oku
 
Latest Meteor JS News
Designveloper
 
Meet song nhi your virtual financial assistance
Designveloper
 
Rapid Digital Innovation: How Node.js Delivers
Richard Rodger
 
How microservices fail, and what to do about it
Richard Rodger
 
Unity3D With Meteor
Designveloper
 
Richard rodger technical debt - web summit 2013
Richard Rodger
 
Introducción a microservicios
Erasmo Domínguez Jiménez
 
Multi tenancy - Wining formula for a PaaS
WSO2
 
The Seneca Pattern at EngineYard Distill 2013 Conference
Richard Rodger
 
Building a Multi-tenanted SaaS with Node.js
Eoin Shanaghy
 
Integrating PostgreSql with RabbitMQ
Gavin Roy
 
Bizweb Microservices Architecture
Khôi Nguyễn Minh
 
ITLC HN 14 - Bizweb Microservices Architecture
IT Expert Club
 
Distributed Transaction in Microservice
Nghia Minh
 
JSX Design Overview (日本語)
Kazuho Oku
 
Ad

Similar to Microservices with SenecaJS (part 2) (20)

PPTX
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
Javier García Magna
 
PDF
NodeJS Microservices, Built it Now, Scale it Later!
Lalit Shandilya
 
PDF
Node and Micro-Services at IBM
Dejan Glozic
 
PPTX
NATS for Modern Messaging and Microservices
Apcera
 
PPTX
NATS for Modern Messaging and Microservices
NATS
 
PPTX
Game On! Exploring Microservices with a Text-Based Adventure Game
Erin Schnabel
 
PDF
Microservices - Hitchhiker's guide to cloud native applications
Stijn Van Den Enden
 
PDF
Devops - Microservice and Kubernetes
NodeXperts
 
PPTX
Cloud Native & Service Mesh
Roi Ezra
 
PDF
Zero to scaleable in ten minutes
Matt Walters
 
PPTX
Webinar : Microservices and Containerization
Newt Global Consulting LLC
 
PDF
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Startupfest
 
PPTX
Messaging-as-a-Service Rivieradev 2017
Ulf Lilleengen
 
PDF
Newt global meetup microservices
Venkatnadhan Thirunalai
 
PPTX
From a monolith to microservices with Azure Service Fabric
Stéphane ERBRECH
 
PPTX
Microservices with Spring
Carlos Cavero Barca
 
PPTX
Microservices pros and cons dark
Andrew Siemer
 
PPTX
.NET microservices with Azure Service Fabric
Davide Benvegnù
 
PDF
Микросервисы со Spring Boot & Spring Cloud
Vitebsk DSC
 
PDF
Microservices on a budget meetup
Matthew Reynolds
 
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
Javier García Magna
 
NodeJS Microservices, Built it Now, Scale it Later!
Lalit Shandilya
 
Node and Micro-Services at IBM
Dejan Glozic
 
NATS for Modern Messaging and Microservices
Apcera
 
NATS for Modern Messaging and Microservices
NATS
 
Game On! Exploring Microservices with a Text-Based Adventure Game
Erin Schnabel
 
Microservices - Hitchhiker's guide to cloud native applications
Stijn Van Den Enden
 
Devops - Microservice and Kubernetes
NodeXperts
 
Cloud Native & Service Mesh
Roi Ezra
 
Zero to scaleable in ten minutes
Matt Walters
 
Webinar : Microservices and Containerization
Newt Global Consulting LLC
 
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Startupfest
 
Messaging-as-a-Service Rivieradev 2017
Ulf Lilleengen
 
Newt global meetup microservices
Venkatnadhan Thirunalai
 
From a monolith to microservices with Azure Service Fabric
Stéphane ERBRECH
 
Microservices with Spring
Carlos Cavero Barca
 
Microservices pros and cons dark
Andrew Siemer
 
.NET microservices with Azure Service Fabric
Davide Benvegnù
 
Микросервисы со Spring Boot & Spring Cloud
Vitebsk DSC
 
Microservices on a budget meetup
Matthew Reynolds
 
Ad

More from Designveloper (20)

PDF
Let us take care of your brand image
Designveloper
 
PDF
5 java script frameworks to watch in 2017
Designveloper
 
PDF
Happy international women's day!
Designveloper
 
PDF
Typing racer game - a nice break from work
Designveloper
 
PDF
Should we work remotely?
Designveloper
 
PDF
Why pair programming is a good idea
Designveloper
 
PDF
5 worst mistakes of diy websites
Designveloper
 
PDF
Basic glossary of web design terms for non designers (part 2)
Designveloper
 
PDF
Single page web application development using meteor js
Designveloper
 
PDF
Multiplayer game with unity3 d and meteor
Designveloper
 
PDF
Awesome free resources for learning javascript
Designveloper
 
PDF
What is the best java script frameworks to learn?
Designveloper
 
PDF
Travelling forms a young man
Designveloper
 
PDF
5 compelling reasons your website should be responsive
Designveloper
 
PDF
Reactive programming with tracker
Designveloper
 
PDF
Benefits of using single page websites
Designveloper
 
PDF
What is the best programming language for beginner?
Designveloper
 
PDF
No sql injection in meteor.js application
Designveloper
 
PDF
How to deploy and scale your meteor apps
Designveloper
 
PDF
Meetup groups you need to join if you are new to tech
Designveloper
 
Let us take care of your brand image
Designveloper
 
5 java script frameworks to watch in 2017
Designveloper
 
Happy international women's day!
Designveloper
 
Typing racer game - a nice break from work
Designveloper
 
Should we work remotely?
Designveloper
 
Why pair programming is a good idea
Designveloper
 
5 worst mistakes of diy websites
Designveloper
 
Basic glossary of web design terms for non designers (part 2)
Designveloper
 
Single page web application development using meteor js
Designveloper
 
Multiplayer game with unity3 d and meteor
Designveloper
 
Awesome free resources for learning javascript
Designveloper
 
What is the best java script frameworks to learn?
Designveloper
 
Travelling forms a young man
Designveloper
 
5 compelling reasons your website should be responsive
Designveloper
 
Reactive programming with tracker
Designveloper
 
Benefits of using single page websites
Designveloper
 
What is the best programming language for beginner?
Designveloper
 
No sql injection in meteor.js application
Designveloper
 
How to deploy and scale your meteor apps
Designveloper
 
Meetup groups you need to join if you are new to tech
Designveloper
 

Recently uploaded (20)

PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Python basic programing language for automation
DanialHabibi2
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 

Microservices with SenecaJS (part 2)

  • 1. 9/30/16 1 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal MICROSERVICES WITH SENECAJS Trung Dang Session 2
  • 2. 9/30/16 2 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Agenda – Session 2 ▪ Docker ▪ AMQP / RabbitMQ: What is it? ▪ SenecaJS transportation with AMQP ▪ Multiple service instances: PM2 or Docker? ▪ Consul - Service health checker & Configuration ▪ JWT for Auth ▪ Introducing servicebase package ▪ Q/A
  • 3. 9/30/16 3 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Sample source code is available at https://github.com/immanuel192/seneca-with-rabbitmq-seminar
  • 4. 9/30/16 4 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal Review Session 1
  • 5. 9/30/16 5 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?
  • 6. 9/30/16 6 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal
  • 7. 9/30/16 7 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Microservices with Seneca, RabbitMQ, Consul, and FeathersJS servicebase Database Models Service Logic Service B NGINX–LoadBalancer GatewayAPI1GatewayAPI2 RabbitMQ Configuration Storage & Health Checker Docker servicebase Database Models Service Logic Service A Redis
  • 8. 9/30/16 8 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Docker - https://www.docker.com/
  • 9. 9/30/16 9 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal AMQP & RabbitMQ. What is it? • RabbitMQ is a messaging broker - an intermediary for messaging.
  • 10. 9/30/16 10 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Service 1 RabbitMQ - How it works Service 2 Queue Queue Exchange client Service 1
  • 11. 9/30/16 11 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal docker run -d --hostname rabbitmq-server -p 5672:5672 -p 15672:15672 --name rabbitmq-server -e RABBITMQ_DEFAULT_USER=username -e RABBITMQ_DEFAULT_PASS=password rabbitmq:management Docker – Start RabbitMQ
  • 12. 9/30/16 12 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.
  • 13. 9/30/16 13 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS – Your first microservice let seneca = require('seneca')() seneca.add('service:math,cmd:sum', (msg, reply) => { reply(null, { answer: (msg.left + msg.right) }) }) seneca.act({ service: 'math', cmd: 'sum', left: 1, right: 2 }, (err, result) => { if (err) return console.error(err) console.log(result) } )
  • 14. 9/30/16 14 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS – Pattern Matching seneca.add('service:math,cmd:sum', (msg, reply) => { reply(null, { answer: (msg.left + msg.right) }) }) Can this service return the result as an integer only whenever I need?
  • 15. 9/30/16 15 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS – Pattern Matching - 2 seneca.add(‘service:math,cmd:sum’, function (msg, reply) { if (msg.integer === true){ reply(null, { answer: (parseInt(msg.left) + parseInt(msg.right)) }) } else{ reply(null, { answer: (msg.left + msg.right) }) } })
  • 16. 9/30/16 16 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS – Pattern Matching - 3 seneca.add('service:math,cmd:sum', (msg, reply) => { reply(null, { answer: (msg.left + msg.right) }) }) seneca.add('service:math,cmd:sum,integer:true', (msg, reply) => { reply(null, { answer: ( parseInt(msg.left) + parseInt(msg.right) ) }) })
  • 17. 9/30/16 17 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS – Pattern Matching - Recap • Matches against top level properties of JSON message • Patterns are unique • Specialised patterns win over generic patterns • Competing patterns win based on value
  • 18. 9/30/16 18 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS – Transport • Seneca can work with multiple transports • Available transports: RabbitMQ, Kafka, Redis, BeansTalk, mqp, Mesh, SQS, NSQ, ZeroMQ, NATS, Azure Service Bus, NServiceBus, Aliyun-MNS, Google Cloud PubSub • HTTP/TCP is supported by default
  • 19. 9/30/16 19 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
  • 20. 9/30/16 20 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS with AMQP Transport – Server let seneca = require('seneca')() .use('seneca-amqp-transport') .add('service:myService,cmd:create', function (args, done) { console.log(`From client ${args.clientId}: ${args.i}`); done(null, { i: args.i }) }) .listen({ type: 'amqp', pin: 'service:myService', url: 'amqp://username:password@rabbitmq-server:5672' })
  • 21. 9/30/16 21 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS with AMQP Transport – Client let clientId = 1 let args = process.argv.slice(2) if (args.length > 0) { clientId = args[0] } let client = require('seneca')().use('seneca-amqp-transport').client({ type: 'amqp', pin: 'service:myService', url: 'amqp://username:password@rabbitmq-server:5672' }) let i = 0 setInterval(function() { client.act(`service:myService,cmd:create,clientId:${clientId},i:${i}`, function(err, ret) { console.log('Client: received i = ' + ret.i); }); i++; }, 100)
  • 22. 9/30/16 22 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal SenecaJS with AMQP Transport – How it works Consumer Queue Queue myServiceclient Request reply_to = my_client_id correlation_id = abc Reply correlation_id = abc Queue Client Queue Routing pin = service:myService Routing pin = my_client_id
  • 23. 9/30/16 23 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal DEMO
  • 24. 9/30/16 24 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal TEA-BREAK
  • 25. 9/30/16 25 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal PM2 • Advanced process manager for production Node.js applications. Load balancer, logs facility, startup script, micro service management, at a glance. • We can use pm2 to start our services with scale pm2 start config-file.json pm2 start your-app.js pm2 scale app-name instance-number
  • 26. 9/30/16 26 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal PM2 - Sample JSON configuration File start-service.json { apps: [ { name: "myService", script: "index.js", watch: false, env: { "NODE_ENV": "development" }, instances: 1 } ] }
  • 27. 9/30/16 27 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Docker – Run your service in multiple container export pwd=`pwd` docker run -d --link=rabbitmq-server -v "$pwd":/app mhart/alpine-node:latest node /app/server.js docker run -d --link=rabbitmq-server -v "$pwd":/app mhart/alpine-node:latest node /app/client.js 1 docker run -d --link=rabbitmq-server -v "$pwd":/app mhart/alpine-node:latest node /app/client.js 2
  • 28. 9/30/16 28 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Configuring your service • How can we protect our configuration for production ENV? • How can we monitor our services’s heath? References: • Health - Consul https://www.consul.io/docs/agent/http/health.html • Key / Value store - Consul https://www.consul.io/docs/agent/http/kv.html
  • 29. 9/30/16 29 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal JWT for Authentication • JWT stands for Json Web Token • No more cookies. • JWT has 3 parts: header.body.signature Example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzY290Y2guaW8iLCJleHAiOjEzMDA4MTkzODAsIm5hbWU iOiJDaHJpcyBTZXZpbGxlamEiLCJhZG1pbiI6dHJ1ZX0.03f329983b86f7d9a9f5fef85305880101d5e302afafa20 154d094b229f75 • JWT helps to verify the sender, authorize the request, prevent man in middle and good with CORS.
  • 30. 9/30/16 30 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Introducing servicebase package https://www.npmjs.com/package/servicebase Features : • Listener / Client mode, with AMQP Transport or HTTP Transport • Promisify all functions • Use Consul as Configuration Storage & Service Health Checker • Support multiple database adapters. Postgresql & Sqlite are build-in supported adapters • Use Loggly as logs monitoring service • Support Authorization when consuming the service’s action • Error handler: no more terminating your service because of TIMEOUT or fatal$ error • Including test helper • Including typed-definitions file
  • 31. 9/30/16 31 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal DEMO
  • 32. 9/30/16 32 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Testing your services • Use sqlite in-memory for integration test • For unit-test: test your logic-class instead of test the function you registered with seneca • For integration-test with other services: use pm2 & rabbitmq
  • 33. 9/30/16 33 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Microservices are the kind of SOA. Microservices must be independently deployable, whereas SOA services are often implemented in deployment monoliths. Classic SOA is more platform driven, so microservices offer more choices in all dimensions. Torsten Winterberg (Oracle ACE Director) Microservices vs SOA
  • 34. 9/30/16 34 CLICK TO EDIT MASTER TITLE STYLE Security Classification: Internal Q&A Thank you very much
  • 35. 9/30/16 35 CLICK TO EDIT MASTER TITLE STYLE Security Classification: InternalSecurity Classification: Internal Stateful / Stateless & Authorization • Stateful means that there is memory of the past. Previous transactions are remembered and may affect the current transaction. • Stateless means there is no memory of the past. Every transaction is performed as if it were being done for the very first time. • In Stateless service, we use JWT (Json Web Token) for Authentication. No more Cookies. • Authorization will be done by each service regarding to the authenticated user.