Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AkeraWeb

AkeraWeb is holding information about the broker(s) used as first parameter of the constructor. If other REST interfaces are used beside the Web Handler one it is best to create an instance of AkeraWeb and use that as input to REST middleware services instead of just passing the broker configuration, that way the connections are re-used between different services. Use the mount method to get the Web Handler router.

Hierarchy

  • AkeraWeb

Index

Constructors

constructor

  • Construct an instance of AkeraWeb.

    Parameters

    • config: IBrokerConfig | Array<IBrokerConfig> | IBroker

      Can be one or an array of broker configuration for remote brokers or a broker instance when running embedded into the application server.

    • Optional _logger: AkeraLogger
    • Optional _poolSize: number

    Returns AkeraWeb

Accessors

brokers

  • get brokers(): string[]
  • Returns the brokers defined in configuration (alias).

    Returns string[]

Methods

endConnection

  • endConnection(connection: IConnection, broker?: string): Promise<void>
  • Called when the connection obtained through getConnection is no longer needed.

    It is the broker responsibility to decide if to disconnect it or keep it in the connection pool.

    Parameters

    • connection: IConnection

      The connection that is not needed anymore.

    • Optional broker: string

      The broker alias.

    Returns Promise<void>

getCgiVars

  • getCgiVars(req: express.Request, broker?: string): IWebCgi
  • Returns the CGI variables from the request.

    Parameters

    • req: express.Request

      The web request.

    • Optional broker: string

      The broker alias.

    Returns IWebCgi

getConnection

  • getConnection(alias?: string): Promise<IConnection>
  • Returns a connection to one of the brokers mounted for this router. If only one broker is mounted the alias parameter is ignored and a connection to that broker is returned.

    When multiple application servers are defined for the same broker (alias) the first one for which a connection can be established is used (fail-over).

    Parameters

    • Optional alias: string

    Returns Promise<IConnection>

log

  • log(message: string, level?: LogLevel): void
  • Log an event information using the instance logger, if any.

    Parameters

    • message: string

      The message to log.

    • Optional level: LogLevel

      The event log level.

    Returns void

mount

  • mount(): express.Router
  • Mount all brokers defined in configuration and return the Express [[Router]] to be used as middleware.

    If there is only on broker defined in configuration that is mounted on the router's main route, otherwise each broker is mounted on a separate path using broker's alias. Multiple application servers can be defined on each broker for fail-over functionality.

    Returns express.Router

Static init

  • A static method that combines the default constructor and call mount on the instance to return the Express [[Router]] that can be used as middleware.

    Parameters

    • config: IBrokerConfig | Array<IBrokerConfig> | IBroker

      Can be one or an array of broker configuration for remote brokers or a broker instance when running embedded into the application server.

    • Optional logger: AkeraLogger

      An instance of [AkeraLogger] to be used by the router for logging.

    • Default value poolSize: number = 0

      The size of connections pool, if set to zero no pooling is used.

    Returns express.Router