createMicroservice

Creates and bootstraps microservice for given transport layer

Importing

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

Type declaration

createMicroservice :: CreateMicroserviceConfig
    -> Promise<ServerIO<TransportLayerConnection>>

Parameters

CreateMicroserviceConfig

StrategyOptions (Transport.AMQP)

StrategyOptions (Transport.REDIS)

Example (AMQP):

import { IO } from 'fp-ts/lib/IO';
import { createMicroservice, messagingListener, Transport } from '@marblejs/messaging';

const amqpMicroservice = createMicroservice({
  transport: Transport.AMQP,
  options: {
    host: 'amqp://localhost:5672',
    queue: 'some_queue_name',
    queueOptions: { durable: true },
    timeout: 360 * 1000,
  },
  listener: messagingListener(...),
  dependencies: [...],
});

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

main();

Example (REDIS):

import { IO } from 'fp-ts/lib/IO';
import { createMicroservice, messagingListener, Transport } from '@marblejs/messaging';

const redisMicroservice = createMicroservice({
  transport: Transport.REDIS,
  options: {
    host: 'redis://127.0.0.1:6379',
    channel: 'some_channelname',
    timeout: 360 * 1000,
  },
  listener: messagingListener(...),
  dependencies: [...],
});

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

main();

Last updated