redis-smq-rest-api
Version:
A RESTful API for RedisSMQ
37 lines • 1.49 kB
JavaScript
import { ProducibleMessage } from 'redis-smq';
import { Container } from '../../container/Container.js';
export const publishMessageController = async (ctx) => {
const messagesService = Container.getInstance().resolve('messagesService');
const { message, exchange } = ctx.scope.resolve('requestBodyDTO');
const msg = new ProducibleMessage();
const { ttl, body, consumeTimeout, priority, retryDelay, retryThreshold, scheduledCron, scheduledRepeat, scheduledRepeatPeriod, scheduledDelay, } = message;
if (ttl)
msg.setTTL(ttl);
if (body)
msg.setBody(body);
if (consumeTimeout)
msg.setConsumeTimeout(consumeTimeout);
if (priority)
msg.setPriority(priority);
if (retryDelay)
msg.setRetryDelay(retryDelay);
if (retryThreshold)
msg.setRetryThreshold(retryThreshold);
if (scheduledCron)
msg.setScheduledCRON(scheduledCron);
if (scheduledRepeat)
msg.setScheduledRepeat(scheduledRepeat);
if (scheduledRepeatPeriod)
msg.setScheduledRepeatPeriod(scheduledRepeatPeriod);
if (scheduledDelay)
msg.setScheduledDelay(scheduledDelay);
if (exchange.queue)
msg.setQueue(exchange.queue);
else if (exchange.topic)
msg.setTopic(exchange.topic);
else if (exchange.fanOut)
msg.setFanOut(exchange.fanOut);
const ids = await messagesService.publishMessage(msg);
return [201, ids];
};
//# sourceMappingURL=publishMessageController.js.map