Created
May 9, 2017 07:30
-
-
Save dashersw/806713d7c100920f56ed09468f9c0584 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.Responder({ 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