2024-03-16 22:29:24 +08:00
|
|
|
import { syscall } from "../syscall.ts";
|
2024-02-29 22:23:05 +08:00
|
|
|
import type { MQStats } from "../types.ts";
|
2023-08-11 00:32:41 +08:00
|
|
|
|
2024-08-07 19:27:25 +08:00
|
|
|
/**
|
|
|
|
* Implements a simple Message Queue system.
|
2024-08-09 15:27:58 +08:00
|
|
|
* @module
|
2024-08-07 19:27:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a message to a queue.
|
|
|
|
* @param queue the name of the queue to send the message to
|
|
|
|
* @param body the body of the message to send
|
|
|
|
*/
|
2024-07-30 23:24:17 +08:00
|
|
|
export function send(queue: string, body: any): Promise<void> {
|
2023-08-11 00:32:41 +08:00
|
|
|
return syscall("mq.send", queue, body);
|
|
|
|
}
|
|
|
|
|
2024-08-07 19:27:25 +08:00
|
|
|
/**
|
|
|
|
* Sends a batch of messages to a queue.
|
|
|
|
* @param queue the name of the queue
|
|
|
|
* @param bodies the bodies of the messages to send
|
|
|
|
*/
|
2024-07-30 23:24:17 +08:00
|
|
|
export function batchSend(queue: string, bodies: any[]): Promise<void> {
|
2023-08-11 00:32:41 +08:00
|
|
|
return syscall("mq.batchSend", queue, bodies);
|
|
|
|
}
|
|
|
|
|
2024-08-07 19:27:25 +08:00
|
|
|
/**
|
|
|
|
* Acknowledges a message from a queue, in case it needs to be explicitly acknowledged.
|
|
|
|
* @param queue the name of the queue the message came from
|
|
|
|
* @param id the id of the message to acknowledge
|
|
|
|
*/
|
2024-07-30 23:24:17 +08:00
|
|
|
export function ack(queue: string, id: string): Promise<void> {
|
2023-08-11 00:32:41 +08:00
|
|
|
return syscall("mq.ack", queue, id);
|
|
|
|
}
|
|
|
|
|
2024-08-07 19:27:25 +08:00
|
|
|
/**
|
|
|
|
* Acknowledges a batch of messages from a queue, in case they need to be explicitly acknowledged.
|
|
|
|
* @param queue the name of the queue the messages came from
|
|
|
|
* @param ids the ids of the messages to acknowledge
|
|
|
|
*/
|
2024-07-30 23:24:17 +08:00
|
|
|
export function batchAck(queue: string, ids: string[]): Promise<void> {
|
2023-08-11 00:32:41 +08:00
|
|
|
return syscall("mq.batchAck", queue, ids);
|
|
|
|
}
|
2023-08-12 02:37:13 +08:00
|
|
|
|
2024-08-07 19:27:25 +08:00
|
|
|
/**
|
|
|
|
* Retrieves stats on a particular queue.
|
|
|
|
* @param queue the name of the queue
|
|
|
|
*/
|
2023-08-28 23:12:15 +08:00
|
|
|
export function getQueueStats(queue: string): Promise<MQStats> {
|
2023-08-12 02:37:13 +08:00
|
|
|
return syscall("mq.getQueueStats", queue);
|
|
|
|
}
|