Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created October 31, 2016 20:24
Show Gist options
  • Save alanhoff/ada94b24cfa9e88d947cb87fe0f37446 to your computer and use it in GitHub Desktop.
Save alanhoff/ada94b24cfa9e88d947cb87fe0f37446 to your computer and use it in GitHub Desktop.
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