eventBus

Creates messaging client reader for LOCAL transport layer (Event Bus)

Importing

import { eventBus } from '@marblejs/messaging';

Type declaration

eventBus :: EventBusConfig
  -> Reader<Context, Promise<TransportLayerConnection>>

Parameters

parameter

definition

config

EventBusConfig

EventBusConfig

parameter

definition

listener

<optional> MessagingListener

Because of asynchronous nature of messaging client, all related readers have to be bound to server creators via eager binding 👉 #bindEagerlyTo

To learn more about eventBus usage please visit:

CQRS

Example

The event bus can be attached to server creator, like basic HTTP or any other microservice.

@marblejs/messaging module exposes already existing messaging client for eventBus transport layer:

import { eventBus } from '@marblejs/messaging';

Additionally it exports tokens for both EventBus and EventBusClient instances.

import { EventBusToken, EventBusClientToken } from '@marblejs/messaging';
import { httpListener, createServer, bindEagerlyTo } from '@marblejs/core';
import { messagingListener, EventBusToken, EventBusClientToken, eventBusClient, eventBus } from '@marblejs/messaging';

const eventBusListener = messagingListener(...);
const listener = httpListener(...);

export const server = createServer({
  listener,
  dependencies: [
    bindEagerlyTo(EventBusClientToken)(eventBusClient),
    bindEagerlyTo(EventBusToken)(eventBus({ listener: eventBusListener })),
  ],
});

const main: IO<void> = async () =>
  await (await server)();

main();

Last updated