Created
May 9, 2017 07:26
-
-
Save dashersw/4b6c8ba067f449e717da7ecc4c1304d4 to your computer and use it in GitHub Desktop.
Hassle-free microservices with cote.js — conversion-service.js with updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cote = require('cote'); | |
const responder = new cote.Requester({ name: 'currency conversion responder' }); | |
const subscriber = new cote.Subscriber({ name: 'arbitration subscriber' }); | |
const rates = { usd_eur: 0.91, eur_usd: 1.10 }; | |
subscriber.on('update rate', (update) => { | |
rates[update.currencies] = update.rate; | |
}); | |
responder.on('convert', (req, cb) => { | |
cb(req.amount * rates[`${req.from}_${req.to}`]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment