Class AmqpConnector

Description

Amqp connector

Features:

  • connection manager for AMQP

Example

import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { AmqpConnector } from '@biorate/amqp';

const connectionName = 'amqp';
const channelName = 'test';

export class Root extends Core() {
@inject(AmqpConnector) public connector: AmqpConnector;
}

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<AmqpConnector>(AmqpConnector).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

container.get<IConfig>(Types.Config).merge({
Amqp: [
{
name: connectionName,
urls: ['amqp://localhost:5672'],
},
],
});

const root = <Root>container.get<Root>(Root);

(async () => {
root.connector.createChannel(connectionName, {
name: channelName,
json: true,
setup: async (channel: Channel) => {
await channel.assertExchange('test-exchange', 'topic');
await channel.assertQueue('test-queue', { exclusive: true, autoDelete: true });
await channel.bindQueue('test-queue', 'test-exchange', '#send');
await channel.consume('test-queue', (data: ConsumeMessage | null) => {
console.log(data?.content?.toString?.()); // {"test": 1}
});
},
});
root.connector.channel(channelName)!.publish('test-exchange', '#send', { test: 1 });
})();

Hierarchy

Constructors

Properties

#connections: Map<string, AmqpConnectionManager>

Description

Private connections storage

#connections: Map<string, AmqpConnectionManager> = ...

Description

Private connections storage

Description

Private link to selected (used) connection

#current: AmqpConnectionManager = undefined

Description

Private link to selected (used) connection

channels: Map<string, default> = ...

Description

Channels storage

config: IConfig

Description

Config dependency

namespace: "Amqp" = 'Amqp'

Description

Namespace path for fetching configuration

Accessors

Methods

Generated using TypeDoc