Asynchronous Microservices in nodejs
-
Upload
bruno-pedro -
Category
Engineering
-
view
4.488 -
download
1
Transcript of Asynchronous Microservices in nodejs
Bruno PedroNovember 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
HTTP
HTTP
HTTP
HTTP
Synchronous
Latency
Asynchronous
Asynchronous
Complexity
SMTPA
A
Broker
SMTPA
BC
D
E
AB
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
AMQP
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
AMQP
amqplibvar 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’ConnorLead 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.
Get in touch!
Bruno Pedro
Thank you