redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
69 lines • 2.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._fromMessage = _fromMessage;
const index_js_1 = require("../../exchange/index.js");
const message_envelope_js_1 = require("../../message/message-envelope.js");
const message_state_js_1 = require("../../message/message-state.js");
const index_js_2 = require("../../message/index.js");
function _fromMessage(sourceEnvelope, resetStatus = true, resetState = true) {
const producibleMessage = sourceEnvelope.producibleMessage;
const newProducibleMsg = new index_js_2.ProducibleMessage();
newProducibleMsg.setTTL(producibleMessage.getTTL());
newProducibleMsg.setRetryThreshold(producibleMessage.getRetryThreshold());
newProducibleMsg.setRetryDelay(producibleMessage.getRetryDelay());
newProducibleMsg.setConsumeTimeout(producibleMessage.getConsumeTimeout());
newProducibleMsg.setBody(producibleMessage.getBody());
const priority = producibleMessage.getPriority();
if (priority !== null) {
newProducibleMsg.setPriority(priority);
}
const cron = producibleMessage.getScheduledCRON();
if (cron) {
newProducibleMsg.setScheduledCRON(cron);
}
const delay = producibleMessage.getScheduledDelay();
if (delay !== null) {
newProducibleMsg.setScheduledDelay(delay);
}
const repeatPeriod = producibleMessage.getScheduledRepeatPeriod();
if (repeatPeriod !== null) {
newProducibleMsg.setScheduledRepeatPeriod(repeatPeriod);
}
newProducibleMsg.setScheduledRepeat(producibleMessage.getScheduledRepeat());
const exchange = producibleMessage.getExchange();
if (exchange) {
if (exchange.type === index_js_1.EExchangeType.DIRECT) {
newProducibleMsg.setDirectExchange(exchange);
}
else if (exchange.type === index_js_1.EExchangeType.TOPIC) {
newProducibleMsg.setTopicExchange(exchange);
}
else {
newProducibleMsg.setFanoutExchange(exchange);
}
}
const queue = producibleMessage.getQueue();
if (queue)
newProducibleMsg.setQueue(queue);
const newEnvelope = new message_envelope_js_1.MessageEnvelope(newProducibleMsg);
if (resetState) {
newEnvelope.setMessageState(new message_state_js_1.MessageState());
}
else {
const newMsgState = message_state_js_1.MessageState.fromJSON(sourceEnvelope.getMessageState().toJSON());
newEnvelope.setMessageState(newMsgState);
}
if (resetStatus) {
newEnvelope.setStatus(index_js_2.EMessagePropertyStatus.NEW);
}
else {
newEnvelope.setStatus(sourceEnvelope.getStatus());
}
newEnvelope.setDestinationQueue(sourceEnvelope.getDestinationQueue());
const consumerGroupId = sourceEnvelope.getConsumerGroupId();
if (consumerGroupId) {
newEnvelope.setConsumerGroupId(consumerGroupId);
}
return newEnvelope;
}
//# sourceMappingURL=_from-message.js.map