|
| 1 | +/** |
| 2 | + * IClientConnector is an interface that defines the methods required for interacting with a queueing system. |
| 3 | + */ |
| 4 | +export interface IClientConnector<K> { |
| 5 | + /** |
| 6 | + * Initializes the connection to the queueing system. |
| 7 | + * @returns A promise that resolves to the initialized connection. |
| 8 | + */ |
| 9 | + create(): Promise<K>; |
| 10 | + |
| 11 | + /** |
| 12 | + * Checks if a consumer group exists in the specified queue. |
| 13 | + * @param queue - The name of the queue. |
| 14 | + * @param group - The name of the consumer group. |
| 15 | + * @returns A promise that resolves when the existence check is complete. |
| 16 | + */ |
| 17 | + groupExists(queue: string, group: string): Promise<void>; |
| 18 | + |
| 19 | + /** |
| 20 | + * Retrieves the length of the specified queue. |
| 21 | + * @param queue - The name of the queue. |
| 22 | + * @returns A promise that resolves to the length of the queue. |
| 23 | + */ |
| 24 | + getStreamLength(queue: string): Promise<number>; |
| 25 | + |
| 26 | + /** |
| 27 | + * Reads messages from a consumer group in the specified queue. |
| 28 | + * @param queue - The name of the queue. |
| 29 | + * @param group - The name of the consumer group. |
| 30 | + * @param consumerId - The ID of the consumer. |
| 31 | + * @param count - The maximum number of messages to read. |
| 32 | + * @param block - The maximum amount of time to block if no messages are available. |
| 33 | + * @returns A promise that resolves to the read messages. |
| 34 | + */ |
| 35 | + readGroup( |
| 36 | + queue: string, |
| 37 | + group: string, |
| 38 | + consumerId: string, |
| 39 | + count: number, |
| 40 | + block: number |
| 41 | + ): Promise<any>; |
| 42 | + |
| 43 | + /** |
| 44 | + * Acknowledges a message in a consumer group as processed. |
| 45 | + * @param queue - The name of the queue. |
| 46 | + * @param group - The name of the consumer group. |
| 47 | + * @param messageId - The ID of the message to acknowledge. |
| 48 | + * @returns A promise that resolves when the message is acknowledged. |
| 49 | + */ |
| 50 | + acknowledgeMessage( |
| 51 | + queue: string, |
| 52 | + group: string, |
| 53 | + messageId: string |
| 54 | + ): Promise<void>; |
| 55 | + |
| 56 | + /** |
| 57 | + * Deletes a consumer from a consumer group in the specified queue. |
| 58 | + * @param consumersSetId - The ID of the set of consumers. |
| 59 | + * @param queue - The name of the queue. |
| 60 | + * @param group - The name of the consumer group. |
| 61 | + * @param consumerId - The ID of the consumer to delete. |
| 62 | + * @returns A promise that resolves when the consumer is deleted. |
| 63 | + */ |
| 64 | + deleteConsumer( |
| 65 | + consumersSetId: string, |
| 66 | + queue: string, |
| 67 | + group: string, |
| 68 | + consumerId: string |
| 69 | + ): Promise<void>; |
| 70 | + |
| 71 | + /** |
| 72 | + * Adds data to the specified queue. |
| 73 | + * @param queue - The name of the queue. |
| 74 | + * @param data - The data to add to the queue. |
| 75 | + * @returns A promise that resolves when the data is added. |
| 76 | + */ |
| 77 | + add(queue: string, data: any): Promise<void>; |
| 78 | + |
| 79 | + /** |
| 80 | + * Adds data atomically to the specified queue and additional queues. |
| 81 | + * @param queue - The name of the main queue. |
| 82 | + * @param additionalQueues - Additional queues to add the data to atomically. |
| 83 | + * @param data - The data to add to the queues. |
| 84 | + * @returns A promise that resolves when the data is added. |
| 85 | + */ |
| 86 | + addAtomic(queue: string, additionalQueues: string[], data: any): Promise<void>; |
| 87 | + |
| 88 | + /** |
| 89 | + * Adds multiple data entries to the specified queue. |
| 90 | + * @param queue - The name of the queue. |
| 91 | + * @param data - An array of data entries to add to the queue. |
| 92 | + * @returns A promise that resolves when the data is added. |
| 93 | + */ |
| 94 | + bulk(queue: string, data: any[]): Promise<void>; |
| 95 | + |
| 96 | + /** |
| 97 | + * Adds multiple data entries atomically to the specified queue and additional queues. |
| 98 | + * @param queue - The name of the main queue. |
| 99 | + * @param additionalQueues - Additional queues to add the data to atomically. |
| 100 | + * @param data - An array of data entries to add to the queues. |
| 101 | + * @returns A promise that resolves when the data is added. |
| 102 | + */ |
| 103 | + bulkAtomic(queue: string, additionalQueues: string[], data: any[]): Promise<void>; |
| 104 | + |
| 105 | + /** |
| 106 | + * Sets a heartbeat for the specified worker. |
| 107 | + * @param workerId - The ID of the worker. |
| 108 | + * @returns A promise that resolves when the heartbeat is set. |
| 109 | + */ |
| 110 | + setHeartbeat(workerId: string): Promise<void>; |
| 111 | + |
| 112 | + /** |
| 113 | + * Retrieves all heartbeats from the queueing system. |
| 114 | + * @returns A promise that resolves to an object containing all heartbeats, indexed by worker ID. |
| 115 | + */ |
| 116 | + getAllHeartbeats(): Promise<{ [key: string]: string }>; |
| 117 | + |
| 118 | + /** |
| 119 | + * Deletes the heartbeat for the specified worker. |
| 120 | + * @param workerId - The ID of the worker. |
| 121 | + * @returns A promise that resolves when the heartbeat is deleted. |
| 122 | + */ |
| 123 | + deleteHeartbeat(workerId: string): Promise<void>; |
| 124 | + |
| 125 | + /** |
| 126 | + * Disconnects the client from the queueing system. |
| 127 | + * @returns A promise that resolves when the client is disconnected. |
| 128 | + */ |
| 129 | + quit(): Promise<void>; |
| 130 | +} |
0 commit comments