The service represents a microservice in Weave. You can define actions and subscribe to events. To create a service you must define a schema. The service schema is similar to a component system of VueJS.

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
metrics Object
middlewares Array<Function> null
statistics Boolean false
logger Boolean or Object or Function console
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
circuitBreaker Object
started Function null
stopped Function null

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.