Constructor
new Server(opts)
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object | Options for the server.
Properties
|
Methods
consume() → {Promise}
Start consuming from the subscribed queues. This is called by `.start`.
This can be called after the server has been started to start consuming
from additional queues.
Returns:
Promise resolved when consuming has started.
- Type
- Promise
setAllEvents(map) → {Server}
Takes a map of event exchanges and handlers and subscribes to them all.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
map |
Object.<String, function()> | A map of exchanges and task handlers.
Properties
|
Returns:
The server.
- Type
- Server
setAllTasks(map) → {Server}
Takes a map of queues and task handlers and sets them all.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
map |
Object.<String, function()> | A map of queue names and task
handlers.
Properties
|
Returns:
The server.
- Type
- Server
setEvent(exchangeName, task, optsopt) → {Server}
Assigns a task to an exchange.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
exchangeName |
String | Exchange name. | |
task |
function | Function to take a job and return a promise. | |
opts |
Object |
<optional> |
Options for the worker that performs the task. |
Returns:
The server.
- Type
- Server
setTask(queueName, task, optsopt) → {Server}
Assigns a task to a queue.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
queueName |
String | Queue name. | |
task |
function | Function to take a job and return a promise. | |
opts |
Object |
<optional> |
Options for the worker that performs the task. |
Returns:
The server.
- Type
- Server
start() → {Promise}
Starts the worker server, connects to RabbitMQ, subscribes and consumes
from all the provided queues and exchanges (tasks and events).
Returns:
Promise that resolves once the server is listening.
- Type
- Promise
stop() → {Promise}
Stops the worker server, unsubscribing and disconnecting from RabbitMQ.
Returns:
A promise that resolves when the server is stopped.
- Type
- Promise