@bss-sbc/rabbitmq-connection-instance
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

RabbitMQ Connection Instance

API References

RabbitMQ

  • connect(uri: string, options?: Options): Promise<NodeJS.Timeout | undefined>;

  • publish(queue: string, exchange: string, type: string, routingKey: string, data: any): Promise<boolean | undefined>;

  • consume(queue: string, onMessage: OnMessage): Promise<Replies.Consume | undefined>;

  • stopConsume(queue: string): Promise<void>;

  • getConnection(): Connection | undefined;

Examples

Javascript

const { RabbitMQ } = require(`@bss-sbc/rabbitmq-connection-instance`);

const instance = new RabbitMQ();
instance
    .connect(`amqps://oronngzc:KyHeBT-xzjLNEImdB3LmP7lhz9w2FRQD@armadillo.rmq.cloudamqp.com/oronngzc`)
    .then(() => console.log(instance.getConnection))
    .then(() => process.exit(0));

Typescript (Singleton recommended)

import { RabbitMQ } from '@bss-sbc/rabbitmq-connection-instance';

class SingletonRabbitMQ extends RabbitMQ {
    private static instance: SingletonRabbitMQ;
    private constructor() {
        super();
    }
    public static getInstance(): SingletonRabbitMQ {
        if (!SingletonRabbitMQ.instance) {
            SingletonRabbitMQ.instance = new SingletonRabbitMQ();
        }
        return SingletonRabbitMQ.instance;
    }
}


SingletonRabbitMQ.getInstance()
    .connect(`amqps://oronngzc:KyHeBT-xzjLNEImdB3LmP7lhz9w2FRQD@armadillo.rmq.cloudamqp.com/oronngzc`)
    .then(() => console.log(SingletonRabbitMQ.getInstance().getConnection()))
    .then(() => process.exit(0));

Readme

Keywords

none

Package Sidebar

Install

npm i @bss-sbc/rabbitmq-connection-instance

Weekly Downloads

0

Version

1.0.7

License

ISC

Unpacked Size

8.29 kB

Total Files

4

Last publish

Collaborators

  • hiepnguyennk
  • xhoang0509
  • midadean