BusConfiguration
Registers a class handler that receives a message and performs a unit of work. When Bus is initialized it will configure the transport to subscribe to the type of message handled by the handler and upon receipt will forward the message through to the
handle()
function.Argument | Description | Default |
---|---|---|
classHandler | A class responsible for handling messages that implements Handler | None |
import { Bus } from '@node-ts/bus-core'
import { TestHandler } from './test-handler'
Bus.configure().withHandler(TestHandler)
Registers a function handler that receives a message and performs a unit of work. When Bus is initialized it will configure the transport to subscribe to the type of message handled by the function handler and upon receipt will forward the message to the function.
Argument | Description | Default |
---|---|---|
functionHandler | A functional handler mapping initialized using handlerFor | None |
import { Bus, handlerFor } from '@node-ts/bus-core'
import { TestEvent } from './test-event'
Bus.configure().withHandler(handlerFor(TestEvent, event => {}))
Registers a custom handler that receives messages from external systems, or messages that don't implement the Message interface from @node-ts/bus-messages.
Argument | Description | Default |
---|---|---|
messageHandler | A handler that receives the custom message | None |
customResolver | A discriminator that determines if an incoming message should be mapped to this handler | None |
import { Bus } from '@node-ts/bus-core'
import { S3Event } from 'aws-sdk'
Bus.configure()
.withCustomHandler(
async (event: S3Event) => console.log('Received S3 event', { event }),
{
resolveWith: event => event.Records
&& event.Records.length
}
)
Registers a workflow definition so that all of the messages it depends on will be subscribed to and forwarded to the handlers inside the workflow.
Argument | Description | Default |
---|---|---|
workflow | Workflow definition to register | None |
import { Bus } from '@node-ts/bus-core'
import { TestWorkflow } from './test-workflow'