@allgemein/eventbus
Version:
42 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RedisWriter = void 0;
const RedisConstants_1 = require("./RedisConstants");
const Serializer_1 = require("../../utils/Serializer");
const AbstractRedisConnection_1 = require("./AbstractRedisConnection");
const lodash_1 = require("lodash");
class RedisWriter extends AbstractRedisConnection_1.AbstractRedisConnection {
constructor(options) {
super(options);
const _options = (0, lodash_1.clone)(options);
// @ts-ignore
this.options = options['writer'] ? (0, lodash_1.merge)(_options, _options['writer']) : _options;
}
async open() {
const client = await this.getClient();
// client.on(E_PSUBSCRIBE, (...args: any[]) => {
// console.log('subscribe', args);
// });
}
async publish(message, channel = RedisConstants_1.C_ANY) {
if (!(0, lodash_1.isString)(message.message)) {
message.message = Serializer_1.Serializer.serialize(message.message);
}
const client = await this.getClient();
return client.publish(message.topic + '::' + channel, message.message);
// return new Promise((resolve, reject) => {
// client.publish(message.topic + '::' + channel, message.message, (err, reply) => {
// if (err) {
// reject(err);
// } else {
// resolve(reply);
// }
// });
// });
}
async close() {
await this.quit();
}
}
exports.RedisWriter = RedisWriter;
//# sourceMappingURL=RedisWriter.js.map