new Broker(id, optionopt)
Broker class.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
string | A unique broker ID. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
option |
object |
<optional> |
Options. Properties
|
Members
(static, constant) State :number
An enumeration of Broker states
Type:
- number
Properties:
| Name | Type | Description |
|---|---|---|
INACTIVE |
number | Broker is inactive |
ACTIVATING |
number | Broker is activating |
ACTIVE |
number | Broker is active |
DESTROYING |
number | Broker is being destroyed |
DESTROYED |
number | Broker has been destroyed |
Methods
createWorker(workerName, optionopt, cbopt) → {Promise}
Create a worker.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
workerName |
string | Name of the worker to be created. |
|||||||||||||||||||||||||
option |
object |
<optional> |
Options. Properties
|
||||||||||||||||||||||||
cb |
Broker~createWorkerCallback |
<optional> |
Callback. |
Returns:
Returns a promise if cb is not provided.
See Broker~createWorkerCallback.
- Type
- Promise
destroy(optionopt, cbopt) → {Promise}
Destroy the broker.
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
option |
object |
<optional> |
Options. Properties
|
||||||||
cb |
Broker~destroyWorkerCallback |
<optional> |
Callback. |
Returns:
Returns a promise if cb is not provided.
See Broker~destroyWorkerCallback.
- Type
- Promise
findWorker(workerId, cbopt) → {Promise}
Find worker.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
workerId |
string | ID of a worker to find. If the worker is a dynamic worker, |
|
cb |
Broker~findWorkerCallback |
<optional> |
Callback. |
Returns:
Returns a promise if cb is not provided.
See Broker~findWorkerCallback.
- Type
- Promise
quit()
Quit redis clients.
This method is provided so that we can make sure to quit redis connections,
or to do so for testing. However, the redis clients' lifetime may be
managed by other place. Therefore, use this method with a care.
registerWorker(nameopt, ctor, optionopt) → {void}
Register a worker class.
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string |
<optional> |
Name of the worker class. If omitted, the name |
||||||||
ctor |
function | Constructor of the worker to be registered. |
|||||||||
option |
object |
<optional> |
Option. Properties
|
Returns:
- Type
- void
restart(cbopt) → {Promise}
Restart dworker. (Adminstrative purpose only)
All active workers will be removed with no recovery.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
cb |
Broker~restartCallback |
<optional> |
Callback function. |
Returns:
Returns a promise if cb is not provided.
See Broker~restartCallback.
- Type
- Promise
restartAll()
Trigger restart of all active brokers under the same namespace.
This method does not wait for completion of actual restart. This
method just signals restart command to all active brokers.
setWorkerRegistry(registry) → {void}
Set a custom worker class registry.
Parameters:
| Name | Type | Description |
|---|---|---|
registry |
object | Custom registry to be used. The object
|
Returns:
- Type
- void
start(cbopt) → {Promise}
Start this broker.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
cb |
Broker~startCallback |
<optional> |
Callback function. |
Returns:
Returns a promise if cb is not provided.
See Broker~startCallback.
- Type
- Promise
Type Definitions
createWorkerCallback(err, agent)
Callback function for Broker#createWorker.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error | Error object. |
agent |
Agent | An instance for remote Worker (called 'Agent') via which you can |
destroyWorkerCallback(err)
Callback function for Broker#destroyWorker.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error | Error object. |
findWorkerCallback(err, agent)
Callback function for Broker#findWorker.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error | Error object. |
agent |
Agent | An instance for remote Worker (called 'Agent') via which you can |
restartCallback(err, data)
Callback function for Broker.prototype.restart.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error | Error object. |
data |
object | Request data. |
startCallback(err, data)
Callback function for Broker.prototype.start.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
Error | Error object. |
data |
object | Request data. |