@millionfor/mq
v2.0.4
Published
A portable function based on mq
Downloads
14
Readme
@millionfor/mq
A portable function based on mq
Installation
$ npm i @millionfor/mq
Usage
import Mq from '@millionfor/mq';
const CONNECTION_SETTING = 'amqp://xxxx:5672';
const CHANNEL_NAME = 'test1';
const _mq = new Mq({ connectionSetting: CONNECTION_SETTING });
_mq.init();
setInterval(() => {
_mq.post(CHANNEL_NAME, { time: new Date() });
}, 1000);
const myPromise = (val) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('logger-[val]', val);
resolve('okokok');
}, 3000);
});
};
_mq.consumer(CONNECTION_SETTING, CHANNEL_NAME, 3, myPromise);
APIs
declare type Option = {
connectionSetting: string;
};
/**
* Mq.
*/
declare class Mq {
/**
* option.
*
* @param {String}
*/
/**
* option.
*/
option: Option;
/**
* connection.
*
* @param {String}
*/
connection: any;
/**
* channel.
*
* @param {String}
*/
channel: any;
/**
* constructor.
*
* @param opt -
*/
constructor(opt: Option);
/**
* init.
*/
init(): void;
/**
* consumer.
*
* @param connectionSetting -
* @param chName -
* @param numConsumers -
* @param handler -
*/
consumer(connectionSetting: string, chName: string, numConsumers: number, handler: (arg: number) => Promise<void>): Promise<void>;
/**
* post.
*
* @param chName -
* @param payload -
*/
post(chName: string, payload: any): void;
}
export default Mq;
License
MIT