@lynxvs/amqp
Advanced tools
Comparing version 3.0.0 to 3.0.1
{ | ||
"name": "@lynxvs/amqp", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
import * as amqp from "amqplib"; | ||
/** | ||
* Publishes a message in a queue in RabbitMQ. | ||
* Publishes a message to RabbitMQ. | ||
* | ||
* @param {string} exchange | ||
* @param {string} routingKey | ||
* @param message | ||
* @param {any} message | ||
* @param {Options.Publish} options | ||
@@ -12,3 +12,3 @@ * @returns {Promise<void>} | ||
export declare function publish( | ||
exchange: string | undefined, | ||
exchange: string, | ||
routingKey: string, | ||
@@ -19,7 +19,7 @@ message: any, | ||
/** | ||
* Publishes a message in a queue in RabbitMQ. | ||
* Publishes messages to RabbitMQ. | ||
* | ||
* @param {string} exchange | ||
* @param {string} name | ||
* @param messages | ||
* @param {string} routingKey | ||
* @param {any[]} messages | ||
* @param {Options.Publish} options | ||
@@ -29,6 +29,6 @@ * @returns {Promise<void>} | ||
export declare function publishMessages( | ||
exchange: string | undefined, | ||
name: string, | ||
exchange: string, | ||
routingKey: string, | ||
messages: any[], | ||
options?: amqp.Options.Publish | ||
): Promise<void>; |
20
queue.js
@@ -44,12 +44,13 @@ "use strict"; | ||
const _ = __importStar(require("lodash")); | ||
const config = __importStar(require("./config")); | ||
/** | ||
* Publishes a message in a queue in RabbitMQ. | ||
* Publishes a message to RabbitMQ. | ||
* | ||
* @param {string} exchange | ||
* @param {string} routingKey | ||
* @param message | ||
* @param {any} message | ||
* @param {Options.Publish} options | ||
* @returns {Promise<void>} | ||
*/ | ||
function publish(exchange = "", routingKey, message, options = {}) { | ||
function publish(exchange, routingKey, message, options = {}) { | ||
return __awaiter(this, void 0, void 0, function*() { | ||
@@ -61,11 +62,11 @@ return publishMessages(exchange, routingKey, [message], options); | ||
/** | ||
* Publishes a message in a queue in RabbitMQ. | ||
* Publishes messages to RabbitMQ. | ||
* | ||
* @param {string} exchange | ||
* @param {string} name | ||
* @param messages | ||
* @param {string} routingKey | ||
* @param {any[]} messages | ||
* @param {Options.Publish} options | ||
* @returns {Promise<void>} | ||
*/ | ||
function publishMessages(exchange = "", name, messages, options = {}) { | ||
function publishMessages(exchange, routingKey, messages, options = {}) { | ||
return __awaiter(this, void 0, void 0, function*() { | ||
@@ -82,5 +83,8 @@ const conn = yield amqp_1.connect(); | ||
// Note: on Node 6 Buffer.from(msg) should be used | ||
config.config.logger.info( | ||
`publishing message with routingKey=${routingKey} in exchange=${exchange}` | ||
); | ||
yield ch.publish( | ||
exchange, | ||
name, | ||
routingKey, | ||
Buffer.from(JSON.stringify(message)), | ||
@@ -87,0 +91,0 @@ _.extend( |
import { connect, createChannel } from "./amqp"; | ||
import * as _ from "lodash"; | ||
import * as amqp from "amqplib"; | ||
import * as config from "./config"; | ||
/** | ||
* Publishes a message in a queue in RabbitMQ. | ||
* Publishes a message to RabbitMQ. | ||
* | ||
* @param {string} exchange | ||
* @param {string} routingKey | ||
* @param message | ||
* @param {any} message | ||
* @param {Options.Publish} options | ||
@@ -15,3 +16,3 @@ * @returns {Promise<void>} | ||
export async function publish( | ||
exchange: string = "", | ||
exchange: string, | ||
routingKey: string, | ||
@@ -25,7 +26,7 @@ message: any, | ||
/** | ||
* Publishes a message in a queue in RabbitMQ. | ||
* Publishes messages to RabbitMQ. | ||
* | ||
* @param {string} exchange | ||
* @param {string} name | ||
* @param messages | ||
* @param {string} routingKey | ||
* @param {any[]} messages | ||
* @param {Options.Publish} options | ||
@@ -35,4 +36,4 @@ * @returns {Promise<void>} | ||
export async function publishMessages( | ||
exchange: string = "", | ||
name: string, | ||
exchange: string, | ||
routingKey: string, | ||
messages: any[], | ||
@@ -53,5 +54,8 @@ options: amqp.Options.Publish = {} | ||
// Note: on Node 6 Buffer.from(msg) should be used | ||
config.config.logger.info( | ||
`publishing message with routingKey=${routingKey} in exchange=${exchange}` | ||
); | ||
await ch.publish( | ||
exchange, | ||
name, | ||
routingKey, | ||
Buffer.from(JSON.stringify(message)), | ||
@@ -58,0 +62,0 @@ _.extend( |
Sorry, the diff of this file is not supported yet
81390
1610