Subscribe to our list to receive the latest updates on Node on Fire

Class: Worker


new Worker(connection, workerName, models, workers)

The worker class. See App#worker.

Name Type Description
connection AMQP.Connection

The connection to the message queueing system.

workerName String

The name of the worker. By default the name of the worker is used as the queue it's consuming on and publishing to.

models Models

The models module.

workers Workers

The workers module.



The run method is invoked when a continuous worker may start working. Implementation should override this method e.g.:

app.worker(function MyWorker() { = function() {
        // Start calculating here.



Consumes a single message received from the message queue.

This method returns a promise. If the promise is resolved, the message is acknowledged. If the promise is rejected, the message is not acknowledged and thus will be re-published to the queue at a later time (depending on the exact implementation).

Name Type Description
messageMap Dictionary

A map with key methodName and params. The methodName is a string with the name of the method to invoke on the worker object and params a list of arguments passed to the worker's method.

createTask(methodName, params)

Creates a task from a process to a worker process and invoked the method with name methodName on the worker process with the arguments in params.

Name Type Description
methodName String

The name of the method to invoke.

params Array

An array of arguments.


A worker is considered continuousn


Returns true if this worker is task-based, returns false otherwise.

A task-based worker consumes tasks from a work queue and wait until it receives messages. A worker is considered task-based if does not contain a run method.



Starts consuming messages from the message queue. Whenever a message is received it's passed to Worker#consumeMessage.

Do you have any questions or comments on this page? Start a discussion below.

comments powered by Disqus
Subscribe to our list to receive the latest updates on Node on Fire