Created
October 31, 2016 20:24
-
-
Save alanhoff/ada94b24cfa9e88d947cb87fe0f37446 to your computer and use it in GitHub Desktop.
This file contains 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 nsq = require('nsq') | |
const crypto = require('crypto') | |
module.exports = async (req, res) => { | |
async validarAuth(req.header.authentication) | |
// Depois de validar iniciar a escuta em uma fila única para essa request | |
const replyQueue = crypto.randomBytes(30).toString('hex') | |
nsq.on(replyQueue, data => { | |
res.json(data) | |
}) | |
// Enviar para a queue do service | |
nsq.send('fazer_algo_no_db', { | |
user_id: req.user_id, | |
reply_to: replyQueue, | |
data: req.body | |
}) | |
// timeout mal implementado :D | |
setTimeout(() => res.end(504), 2500) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment