📘
@node-test/bus
  • @node-ts/bus
  • Getting started
    • Installation
    • Handling messages
    • Shutting down cleanly
  • Reference
    • Bus
    • BusConfiguration
    • BusInstance
  • Getting help
  • Guide
    • Messages
      • Events
      • Commands
      • System messages
    • Message attributes
      • Correlation id
      • Attributes
      • Sticky attributes
    • Workflows
      • Creating a workflow
      • Starting
      • Handling
      • State
      • Completing
      • Example
    • Transports
      • RabbitMQ
      • Amazon SQS
      • Redis
      • Custom transports
    • Persistence
      • Postgres
      • MongoDB
      • Creating a persistence
    • Serializers
      • Class serializer
    • Loggers
      • Custom loggers
    • Middleware
    • Lifecycle hooks
    • Retry Strategies
    • Dependency injection
    • Long running processes
Powered by GitBook
On this page

Was this helpful?

  1. Guide

Lifecycle hooks

@node-ts/bus exposes a number of lifecycle hooks that can be subscribed to. These are EventEmitter instances that follow the standard node .on() and .off() notation.

Hooks

beforeSend

called just before a command is sent to the underlying transport

bus.beforeSend.on(({ command, attributes }) => {})

beforePublish

called just before a event is published to the underlying transport

bus.beforePublish.on(({ event, attributes }) => {})

afterReceive

called after a message has been read from the queue, and before it is dispatched to handlers

bus.afterReceive.on(transportMessage => {})

beforeDispatch

called before a message is dispatched to its handlers

bus.beforeDispatch.on(({ message, attributes, handlers }) => {})

afterDispatch

called after a message has been successfully handled and the message deleted from the transport

bus.afterDispatch.on(({ message, attributes }) => {})

onError

called when an error occurred reading/dispatching/handling a message

bus.onError.on(({ message, error, attributes, rawMessage }) => {})
PreviousMiddlewareNextRetry Strategies

Last updated 3 years ago

Was this helpful?