Links

createMicroservice

Creates and bootstraps microservice for given transport layer

Importing

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

Type declaration

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

Parameters

parameter
definition
config
CreateMicroserviceConfig

CreateMicroserviceConfig

parameter
definition
listener
MessagingListener
event$
<optional> HttpServerEffect
dependencies
<optional> Array<BoundDependency<any>>
transport
Transport
options
StrategyOptions

StrategyOptions (Transport.AMQP)

parameter
definition
host
string
queue
string
queueOptions
<optional> Options.AssertQueue (see: amqplib)
prefetchCount
<optional> number (defaults to 1)
expectAck
<optional> boolean
timeout
<optional> number in ms (defaults to 120s)

StrategyOptions (Transport.REDIS)

parameter
definition
host
string
channel
string
port
<optional> number
password
<optional> string
timeout
<optional> number in ms (defaults to 120s)

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();