Skip to content

Queue PubSub

Grant Carthew edited this page Sep 19, 2016 · 12 revisions

Description

Thanks to the change feed technology build into RethinkDB, rethinkdb-job-queue can be a distributed system. Depending on how you configure the Queue object you can have Publisher nodes or Subscriber nodes running on the same host or spread across multiple hosts.

The configuration for a Publisher or Subscriber Queue object is very similar. The only difference is the subscriber has the Queue.process method call passing your handler function.

This document describes the configuration for both a Publisher and Subscriber Queue object.

Publisher Queue Object

To create a Publisher you need to create the Queue object using the Queue Constructor. Two things define the Queue object as a Publisher; It adds jobs to the queue, and does not have a process handler.

This example creates a Queue object named pub used for adding jobs to the queue. It will not process jobs.

const Queue = require('rethinkdb-job-queue')

const cxnOptions = {
  host: 'db01.domain.com',
  port: 12345,
  db: 'JobQueue'
}

const qOptions = {
  name: 'Registration',
  changeFeed: false
}

const pub = new Queue(cxnOptions, qOptions)

// Elsewhere in your code

const job = pub.createJob({ timeout: 10000 })
job.registrationData = 'Important Job Info'

pub.addJob(job).catch((err) => {
  console.error(err)
})

Here are some points of interest in the example above.

  • The RethinkDB instance is located on a server called db01.domain.com at port 12345.
  • The database name is JobQueue
  • The queue name is Registration
  • Change feeds are disabled for the Publisher. They can be enabled if needed.
  • Jobs have a registrationData property.
  • Jobs are being added to the queue.

Subscriber Queue Object

Main

How It Works

Contributing

API

Queue Methods

Queue Properties

Queue Events

Job Methods

Job Properties

Documentation

Clone this wiki locally