'use strict';
const Base = require('./base');
-const common = require('./common');
+const { fileScope } = require('@squeep/log-helper');
-const _fileScope = common.fileScope(__filename);
+const _fileScope = fileScope(__filename);
class Publisher extends Base {
constructor(logger, options) {
persistent: true,
};
+ /**
+ * @typedef {object} PublishOptions
+ * @property {number} timestamp timestamp in ms, defaults to current
+ * @property {boolean} persistent defaults to true
+ */
/**
* Send a message to an exchange.
- * @param {String} name
- * @param {*} content
- * @param {Object} options
+ * @param {string} name name
+ * @param {*} content message content
+ * @param {PublishOptions} options options
+ * @returns {Promise<void>}
*/
async publish(name, content, options) {
const _scope = _fileScope('publish');
content = Buffer.from(typeof(content) === 'object' ? JSON.stringify(content) : content);
}
- const timestamp = (new Date()).getTime();
- options = Object.assign({ timestamp }, Publisher.publishDefaults, options);
+ const timestamp = Date.now();
+ options = {
+ timestamp,
+ ...Publisher.publishDefaults,
+ ...options,
+ };
return new Promise((resolve, reject) => {
if (!this.keepSending) {
/**
* Producer only needs to plumb the exchange it sends to.
- *
- * @param {String} name
+ * @param {string} name name
*/
async establishAMQPPlumbing(name) {
const _scope = _fileScope('establishAMQPPlumbing');