Class GuardedTransactionalInboxMessageHandler<TMessage, TConfig>Abstract

Type Parameters

Hierarchy

Constructors

  • Create a new Message handler that provides both the functionality to store an incoming RabbitMQ message in the inbox and provides the actual logic to execute the business logic that is based on that message.

    Type Parameters

    Parameters

    • messagingSettings: MessagingSettings

      The definitions of the message that is handled.

    • permissions: string[]

      The set of permissions that allow to execute the handler code

    • logger: Logger
    • config: TConfig

      The configuration object

    • authParams: string | AuthenticationConfig

      The authentication settings - AuthenticationConfig for customizable services and auth serice URL for managed services.

    Returns GuardedTransactionalInboxMessageHandler<TMessage, TConfig>

Properties

aggregateType: string
authParams: string | AuthenticationConfig

The authentication settings - AuthenticationConfig for customizable services and auth serice URL for managed services.

config: TConfig
handlePreprocessor?: HandlePreprocessor<TMessage, GuardedContext>
messageType: string
messagingSettings: MessagingSettings
permissions: string[]

The set of permissions that allow to execute the handler code

Methods

  • Is called from the transactional inbox and calls the abstract handleMessage function with the correct message payload typing. Do not override this message but implement the handleMessage message.

    Parameters

    • message: StoredTransactionalMessage

      The inbox message with the payload to handle.

    • envOwnerClient: DatabaseClient

      The database client that is part of a DB env owner transaction to safely handle the inbox message.

    Returns Promise<void>

  • Is called from the transactional inbox and calls the handleErrorMessage function with the correct message payload typing. Do not override this message but override the handleErrorMessage message.

    Parameters

    • error: Error

      The error that was thrown in the handle method.

    • message: StoredTransactionalMessage

      The inbox message with the payload that was attempted to be handled.

    • envOwnerClient: DatabaseClient

      The database client that is part of a (new) transaction to safely handle the error.

    • retry: boolean

      True if the message will be retried again.

    Returns Promise<void>

    A flag that defines if the message should be retried ('transient_error') or not ('permanent_error')

  • Optionally override this method with your custom business logic to handle an error that was caused by the handleMessage method. The default implementation logs the error if there are no further retries.

    Parameters

    • error: Error

      The error that was thrown in the handleMessage method.

    • message: TypedTransactionalMessage<TMessage>

      The inbox message with the payload that was attempted to be handled.

    • _envOwnerClient: DatabaseClient
    • retry: boolean

      True if the message will be retried again.

    • Optional _context: GuardedContext

    Returns Promise<void>

  • Implement to execute your custom business logic to handle a message that was stored in the inbox.

    Parameters

    • message: TypedTransactionalMessage<TMessage>

      The inbox message with the payload to handle.

    • envOwnerClient: DatabaseClient

      The database client that is part of a DB env owner transaction to safely handle the inbox message.

    • Optional context: GuardedContext

    Returns Promise<void>

    Throws

    If something fails and the inbox message should NOT be acknowledged - throw an error.

  • Function to map a thrown error of an unspecified type to a potentially more human-readable error or remove unsafe properties.

    Parameters

    • error: Error

    Returns Error

  • Add the PostgreSQL settings for the environment owner connection and subject

    Parameters

    • envOwnerClient: DatabaseClient

      The env owner based DB client

    • subject: AuthenticatedManagementSubject

      The user or service account to use for setting the connection context

    Returns Promise<void>

    Example

    const pgSettings = buildAuthPgSettings(subject, this.config.serviceId);
    await setPgSettingsConfig(pgSettings, envOwnerClient);
  • Modifies the original error by extending its details subobject, if exists. Default behavior adds tenantId and environmentId to the details object by parsing the routing key. If still not available - returns original error. Some routing keys will not have tenantId and environmentId, e.g. when a command is sent. A separate handling is needed to extact these values, e.g. from the jwt.

    Parameters

    • error: Error & {
          details?: Record<string, unknown>;
      }
    • message: StoredTransactionalMessage
    • Optional context: GuardedContext

    Returns void

Generated using TypeDoc