KEMBAR78
Asynchronous Microservices in nodejs | PDF
Bruno Pedro
November 2015
Asynchronous
Microservices
in node.js
Summary
• why microservices

• synchronous vs asynchronous topologies

• broker approach

• code examples

• patterns
Why Microservices
• organised around business capabilities

• following a decentralised governance

• and a decentralised data management

• automated infrastructure

• designed for failure
in Martin Fowler, "Microservices"
Microservices
• loosely coupled

• with a specific responsibility

• designed around business needs

• connected through a common interface
H
TTP
HTTP
HTTP
HTTP
Synchronous
Latency
Asynchronous
Asynchronous
Complexity
SMTP
A
A
Broker
SMTP
A
B
C
D
E
A
B
D C
E
Really?
AMQP
• Advanced Message Queueing Protocol

• interoperable: loosely coupled clients and servers

• advanced publish and subscribe

• transactional, if needed

• supported by node.js
AMQP
AMQP
amqplib
amqplib
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'hello';
ch.assertQueue(q, {durable: false});
ch.sendToQueue(q, new Buffer('Hello World!'));
console.log(" [x] Sent 'Hello World!'");
});
});
in RabbitMQ Tutorials
amqplib
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'hello';
ch.assertQueue(q, {durable: false});
console.log(" [*] Waiting for messages in %s.", q);
ch.consume(q, function(msg) {
console.log(" [x] Received %s”,
msg.content.toString());
}, {noAck: true});
});
});
in RabbitMQ Tutorials
AMQP HTTP
Webhook
Patterns
• work queue
• pubsub system

• webhook
• message routing
• backpressure

• RPC
Asynchronous Microservices
• loosely coupled

• agile to changes

• event based

• organised around business capabilities

• connected through the message broker
AMQP
Wrap-up
• microservices advantages

• asynchronous over synchronous

• broker approach

• easy to implement

• patterns
+
Sean O’Connor
Lead Engineer
It's great to see a tool like API Changelog
come along. (…) as an API provider, it's always
a challenge to communicate to users when
changes happen.
bpedro@apichangelog.com
Get in touch!
Bruno Pedro
Thank you

Asynchronous Microservices in nodejs