Skip to content

Instantly share code, notes, and snippets.

@ynwd
Created February 13, 2022 00:01
Show Gist options
  • Save ynwd/77dbcff323854098ed22937a76b6ac82 to your computer and use it in GitHub Desktop.
Save ynwd/77dbcff323854098ed22937a76b6ac82 to your computer and use it in GitHub Desktop.
Bull Queue Hello World

Bull Queue Hello World

run redis server

docker-compose up

run consumer as listener

node consumer.js

run producer as job creator

node producer.js
const Queue = require('bull')
const q = new Queue('my-first-queue', {
redis: { port: 6379, host: "localhost" }
})
q.process((job, done) => {
done(null, 'succes')
})
q.on('completed', (job) => {
console.info(
`${job.queue.name} task has been completed with message: "${job.data.message}" on: ${new Date().toLocaleTimeString()}`
)
job.remove()
})
version: "3.9"
services:
redis:
image: redis:6-alpine
ports:
- 6379:6379
const Queue = require('bull')
const q = new Queue('my-first-queue', {
redis: { port: 6379, host: "localhost" }
})
const data = { message: "my task" }
q.add(data).then((v) => {
console.info("task has been added with message:", v.data.message)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment