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