UNPKG

redis-smq

Version:

A high-performance, reliable, and scalable message queue for Node.js.

66 lines 2.77 kB
import { EExchangeType } from '../../exchange/index.js'; import { MessageEnvelope } from '../../message/message-envelope.js'; import { MessageState } from '../../message/message-state.js'; import { EMessagePropertyStatus, ProducibleMessage, } from '../../message/index.js'; export function _fromMessage(sourceEnvelope, resetStatus = true, resetState = true) { const producibleMessage = sourceEnvelope.producibleMessage; const newProducibleMsg = new 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 === EExchangeType.DIRECT) { newProducibleMsg.setDirectExchange(exchange); } else if (exchange.type === EExchangeType.TOPIC) { newProducibleMsg.setTopicExchange(exchange); } else { newProducibleMsg.setFanoutExchange(exchange); } } const queue = producibleMessage.getQueue(); if (queue) newProducibleMsg.setQueue(queue); const newEnvelope = new MessageEnvelope(newProducibleMsg); if (resetState) { newEnvelope.setMessageState(new MessageState()); } else { const newMsgState = MessageState.fromJSON(sourceEnvelope.getMessageState().toJSON()); newEnvelope.setMessageState(newMsgState); } if (resetStatus) { newEnvelope.setStatus(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