This version has reached end-of-life. It is no longer maintained. For the latest stable version, click here.

Context

Context

new Context(broker, action)

Context class for action calls

Properties

Property Type Default Description
id String - Context ID
broker ServiceBroker - Broker instance
action Action - Action definition
nodeID - Node ID
parentID String - Parent Context ID
metrics Boolean - Need send metrics events
level - Level of context

Static Members

constructor

new Context(broker: ServiceBroker, action: Action)

Creates an instance of Context.

Parameters

Property Type Default Description
broker ServiceBroker - Broker instance
action Action - Action definition

Examples

let ctx = new Context(broker, action);
let ctx2 = new Context(broker, action);

create

create(broker: ServiceBroker, action: Object, nodeID, params, opts: Object): Context

Create a new Context instance.

Parameters

Property Type Default Description
broker ServiceBroker - -
action Object - -
nodeID - -
params - -
opts Object - -

setParams

setParams(newParams: Object, cloning: Boolean)

Set params of context

Parameters

Property Type Default Description
newParams Object - -
cloning Boolean - -

call

call(actionName: String, params, opts): Promise

Call an other action. It creates a sub-context.

Parameters

Property Type Default Description
actionName String - -
params - -
opts - -

Examples

Call an other service with params & options

ctx.call("posts.get", { id: 12 }, { timeout: 1000 });

emit

emit(eventName: string, data, groups, payload: any)

Emit an event (grouped & balanced global event)

Parameters

Property Type Default Description
eventName string - -
groups - -
payload any - -

Examples

ctx.emit("user.created", { entity: user, creator: ctx.meta.user });

broadcast

broadcast(eventName: string, data, groups, payload: any)

Emit an event for all local & remote services

Parameters

Property Type Default Description
eventName string - -
groups - -
payload any - -

Examples

ctx.broadcast("user.created", { entity: user, creator: ctx.meta.user });