Service broker

The Service Broker is the central component of your node. From here, services are loaded, actions are called and events are triggered. Every node needs his own Service broker.

Create a service broker

    const ServiceBroker = require('@weave-js/core')

    const broker = ServiceBroker()

Create a service broker with custom settings

    const ServiceBroker = require('@weave-js/core')

    const broker = ServiceBroker({
        nodeId: 'myFirstNode',
        loglevel: 'debug'
    })

Service broker settings

Name Type Default Description
nodeId String token Unique identifier for node. Have to be unique in namespace.
namespace String "" Namespace of nodes to segment your nodes on the same network.
cacher Boolean false Cacher settings Read more
metrics Object Metrics settings Read more
middlewares Array<Function> null Register middlewares
statistics Boolean false
logger Boolean or Object or Function console Logger class Read more
logLevel String info
loadInternalMiddlewares Boolean true
internalActions Boolean true
internalActionsAccessable Boolean false
preferLocal Boolean true
requestTimeout Integer 0
validate Boolean true
heartbeatInterval Integer 5000
heartbeatTimeout Integer 10000
retryPolicy Object Retry settings Read more
circuitBreaker Object Circuit breaker settings Read more
started Function null Gets fired when the broker is started. Read more
stopped Function null Gets fired when the broker is stopped. Read more

Service broker methods

Name Response Description
start() Promise Start the broker.
stop() Promise Stop the broker.
createService(schema) Promise Create a service with given schema.
loadService(fileName) Promise Load a service from file.
loadServices(folderName, serviceNameMask) Promise Load a service from folder.
call(actionName, params, options) Promise Call a service.
emit(eventName, payload, groups) Promise Emit a event.
broadcast(eventName, payload, groups) Promise Broadcast a event.
waitForServices(serviceNames) Promise Wait for services.