@gravito/stream 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +27 -1
  2. package/dist/BatchConsumer.d.ts +81 -0
  3. package/dist/Consumer.d.ts +215 -0
  4. package/dist/DashboardProvider.d.ts +20 -0
  5. package/dist/Job.d.ts +183 -0
  6. package/dist/OrbitStream.d.ts +151 -0
  7. package/dist/QueueManager.d.ts +319 -0
  8. package/dist/Queueable.d.ts +91 -0
  9. package/dist/Scheduler.d.ts +214 -0
  10. package/dist/StreamEventBackend.d.ts +114 -0
  11. package/dist/SystemEventJob.d.ts +33 -0
  12. package/dist/Worker.d.ts +139 -0
  13. package/dist/benchmarks/PerformanceReporter.d.ts +99 -0
  14. package/dist/consumer/ConcurrencyGate.d.ts +55 -0
  15. package/dist/consumer/ConsumerStrategy.d.ts +41 -0
  16. package/dist/consumer/GroupSequencer.d.ts +57 -0
  17. package/dist/consumer/HeartbeatManager.d.ts +65 -0
  18. package/dist/consumer/JobExecutor.d.ts +61 -0
  19. package/dist/consumer/JobSourceGenerator.d.ts +31 -0
  20. package/dist/consumer/PollingStrategy.d.ts +42 -0
  21. package/dist/consumer/ReactiveStrategy.d.ts +41 -0
  22. package/dist/consumer/StreamingConsumer.d.ts +88 -0
  23. package/dist/consumer/index.d.ts +13 -0
  24. package/dist/consumer/types.d.ts +102 -0
  25. package/dist/drivers/BinaryJobFrame.d.ts +78 -0
  26. package/dist/drivers/BullMQDriver.d.ts +186 -0
  27. package/dist/drivers/DatabaseDriver.d.ts +131 -0
  28. package/dist/drivers/GrpcDriver.d.ts +16 -0
  29. package/dist/drivers/KafkaDriver.d.ts +148 -0
  30. package/dist/drivers/MemoryDriver.d.ts +108 -0
  31. package/dist/drivers/QueueDriver.d.ts +250 -0
  32. package/dist/drivers/RabbitMQDriver.d.ts +102 -0
  33. package/dist/drivers/RedisDriver.d.ts +294 -0
  34. package/dist/drivers/SQSDriver.d.ts +111 -0
  35. package/dist/drivers/kafka/BackpressureController.d.ts +60 -0
  36. package/dist/drivers/kafka/BatchProcessor.d.ts +50 -0
  37. package/dist/drivers/kafka/ConsumerLifecycleManager.d.ts +80 -0
  38. package/dist/drivers/kafka/ErrorCategorizer.d.ts +39 -0
  39. package/dist/drivers/kafka/ErrorRecoveryManager.d.ts +100 -0
  40. package/dist/drivers/kafka/HeartbeatManager.d.ts +57 -0
  41. package/dist/drivers/kafka/KafkaDriver.d.ts +138 -0
  42. package/dist/drivers/kafka/KafkaMetrics.d.ts +88 -0
  43. package/dist/drivers/kafka/KafkaNotifier.d.ts +54 -0
  44. package/dist/drivers/kafka/MessageBuffer.d.ts +71 -0
  45. package/dist/drivers/kafka/OffsetTracker.d.ts +63 -0
  46. package/dist/drivers/kafka/PerformanceMonitor.d.ts +88 -0
  47. package/dist/drivers/kafka/RateLimiter.d.ts +52 -0
  48. package/dist/drivers/kafka/RebalanceHandler.d.ts +104 -0
  49. package/dist/drivers/kafka/RingBuffer.d.ts +63 -0
  50. package/dist/drivers/kafka/index.d.ts +22 -0
  51. package/dist/drivers/kafka/types.d.ts +553 -0
  52. package/dist/drivers/prepareJobForTransport.d.ts +10 -0
  53. package/dist/index.cjs +5644 -5508
  54. package/dist/index.cjs.map +71 -0
  55. package/dist/index.d.ts +60 -4378
  56. package/dist/index.js +5609 -5453
  57. package/dist/index.js.map +71 -0
  58. package/dist/locks/DistributedLock.d.ts +175 -0
  59. package/dist/persistence/BufferedPersistence.d.ts +130 -0
  60. package/dist/persistence/BunBufferedPersistence.d.ts +173 -0
  61. package/dist/persistence/MySQLPersistence.d.ts +134 -0
  62. package/dist/persistence/SQLitePersistence.d.ts +133 -0
  63. package/dist/serializers/BinarySerializer.d.ts +42 -0
  64. package/dist/serializers/CachedSerializer.d.ts +38 -0
  65. package/dist/serializers/CborNativeSerializer.d.ts +56 -0
  66. package/dist/serializers/ClassNameSerializer.d.ts +58 -0
  67. package/dist/serializers/JobSerializer.d.ts +33 -0
  68. package/dist/serializers/JsonSerializer.d.ts +28 -0
  69. package/dist/serializers/JsonlSerializer.d.ts +90 -0
  70. package/dist/serializers/MessagePackSerializer.d.ts +29 -0
  71. package/dist/types.d.ts +653 -0
  72. package/dist/workers/BinaryWorkerProtocol.d.ts +77 -0
  73. package/dist/workers/BunWorker.d.ts +179 -0
  74. package/dist/workers/SandboxedWorker.d.ts +132 -0
  75. package/dist/workers/WorkerFactory.d.ts +128 -0
  76. package/dist/workers/WorkerPool.d.ts +186 -0
  77. package/dist/workers/bun-job-executor.d.ts +14 -0
  78. package/dist/workers/index.d.ts +13 -0
  79. package/dist/workers/job-executor.d.ts +9 -0
  80. package/package.json +6 -4
  81. package/dist/index.d.cts +0 -4387
@@ -0,0 +1,148 @@
1
+ import type { SerializedJob, TopicOptions } from '../types';
2
+ import type { QueueDriver } from './QueueDriver';
3
+ /**
4
+ * Kafka driver configuration.
5
+ */
6
+ export interface KafkaDriverConfig {
7
+ /**
8
+ * Kafka client instance (kafkajs).
9
+ *
10
+ * Must provide producer, admin, and consumer factories compatible with KafkaJS.
11
+ */
12
+ client: {
13
+ producer: () => {
14
+ connect: () => Promise<void>;
15
+ send: (args: {
16
+ topic: string;
17
+ messages: Array<{
18
+ key?: string;
19
+ value: string;
20
+ }>;
21
+ }) => Promise<void>;
22
+ disconnect: () => Promise<void>;
23
+ };
24
+ admin: () => {
25
+ connect: () => Promise<void>;
26
+ createTopics: (args: {
27
+ topics: Array<{
28
+ topic: string;
29
+ numPartitions?: number;
30
+ replicationFactor?: number;
31
+ }>;
32
+ }) => Promise<void>;
33
+ deleteTopics: (args: {
34
+ topics: string[];
35
+ }) => Promise<void>;
36
+ disconnect: () => Promise<void>;
37
+ };
38
+ consumer: (args: {
39
+ groupId: string;
40
+ }) => {
41
+ connect: () => Promise<void>;
42
+ subscribe: (args: {
43
+ topics: string[];
44
+ }) => Promise<void>;
45
+ run: (args: {
46
+ eachMessage: (args: {
47
+ topic: string;
48
+ partition: number;
49
+ message: {
50
+ key?: Buffer;
51
+ value: Buffer;
52
+ offset: string;
53
+ };
54
+ }) => Promise<void>;
55
+ }) => Promise<void>;
56
+ disconnect: () => Promise<void>;
57
+ };
58
+ };
59
+ /**
60
+ * Consumer group ID used for reading messages.
61
+ * @default 'gravito-workers'
62
+ */
63
+ consumerGroupId?: string;
64
+ }
65
+ /**
66
+ * Kafka-backed queue driver.
67
+ *
68
+ * Uses Apache Kafka topics as queues. Designed for high-throughput streaming
69
+ * rather than traditional job queue semantics (pop/delete).
70
+ * Supports push-based consumption via `subscribe()`.
71
+ *
72
+ * @public
73
+ * @example
74
+ * ```typescript
75
+ * const driver = new KafkaDriver({ client: kafka, consumerGroupId: 'my-app' });
76
+ * ```
77
+ */
78
+ export declare class KafkaDriver implements QueueDriver {
79
+ private client;
80
+ private consumerGroupId;
81
+ private producer?;
82
+ private admin?;
83
+ constructor(config: KafkaDriverConfig);
84
+ /**
85
+ * Ensure the producer is connected.
86
+ */
87
+ private ensureProducer;
88
+ /**
89
+ * Ensure the admin client is connected.
90
+ */
91
+ private ensureAdmin;
92
+ /**
93
+ * Pushes a job to a Kafka topic.
94
+ *
95
+ * @param queue - The topic name.
96
+ * @param job - The job to publish.
97
+ */
98
+ push(queue: string, job: SerializedJob): Promise<void>;
99
+ /**
100
+ * Pop is not supported for Kafka (Push-based).
101
+ *
102
+ * Kafka consumers typically stream messages. Use `subscribe()` instead.
103
+ *
104
+ * @throws {Error} Always throws as Kafka does not support polling individual messages in this manner.
105
+ */
106
+ pop(_queue: string): Promise<SerializedJob | null>;
107
+ /**
108
+ * Returns 0 as Kafka does not expose a simple "queue size".
109
+ *
110
+ * Monitoring lag requires external tools or Admin API checks not implemented here.
111
+ */
112
+ size(_queue: string): Promise<number>;
113
+ /**
114
+ * Clears a queue by deleting the topic.
115
+ *
116
+ * @param queue - The topic name.
117
+ */
118
+ clear(queue: string): Promise<void>;
119
+ /**
120
+ * Pushes multiple jobs to a Kafka topic.
121
+ *
122
+ * @param queue - The topic name.
123
+ * @param jobs - Array of jobs.
124
+ */
125
+ pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
126
+ /**
127
+ * Creates a new Kafka topic.
128
+ *
129
+ * @param topic - The topic name.
130
+ * @param options - Config for partitions/replication.
131
+ */
132
+ createTopic(topic: string, options?: TopicOptions): Promise<void>;
133
+ /**
134
+ * Deletes a Kafka topic.
135
+ *
136
+ * @param topic - The topic name.
137
+ */
138
+ deleteTopic(topic: string): Promise<void>;
139
+ /**
140
+ * Subscribes to a topic for streaming jobs.
141
+ *
142
+ * Starts a Kafka consumer group and processes messages as they arrive.
143
+ *
144
+ * @param queue - The topic name.
145
+ * @param callback - Function to handle the job.
146
+ */
147
+ subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
148
+ }
@@ -0,0 +1,108 @@
1
+ import type { QueueStats, SerializedJob } from '../types';
2
+ import type { QueueDriver } from './QueueDriver';
3
+ /**
4
+ * Configuration options for the MemoryDriver.
5
+ */
6
+ export interface MemoryDriverConfig {
7
+ /**
8
+ * The maximum number of jobs allowed in a single queue.
9
+ *
10
+ * @default Infinity
11
+ */
12
+ maxSize?: number;
13
+ }
14
+ /**
15
+ * In-memory queue driver.
16
+ *
17
+ * Stores jobs in a local JavaScript Map. Ideal for development, testing, and simple
18
+ * use cases where persistence across restarts is not required.
19
+ * It supports basic delay handling but data is volatile.
20
+ *
21
+ * @public
22
+ * @example
23
+ * ```typescript
24
+ * const driver = new MemoryDriver({ maxSize: 1000 });
25
+ * await driver.push('default', job);
26
+ * ```
27
+ */
28
+ export declare class MemoryDriver implements QueueDriver {
29
+ private queues;
30
+ private maxSize;
31
+ constructor(config?: MemoryDriverConfig);
32
+ /**
33
+ * Pushes a job to the in-memory queue.
34
+ *
35
+ * @param queue - The queue name.
36
+ * @param job - The serialized job.
37
+ * @throws {Error} If the queue has reached `maxSize`.
38
+ */
39
+ push(queue: string, job: SerializedJob): Promise<void>;
40
+ /**
41
+ * Pops the next available job from the queue.
42
+ *
43
+ * Respects `delaySeconds` by checking the job's `createdAt` timestamp.
44
+ *
45
+ * @param queue - The queue name.
46
+ * @returns The job or `null`.
47
+ */
48
+ pop(queue: string): Promise<SerializedJob | null>;
49
+ /**
50
+ * Returns the number of jobs in the queue.
51
+ *
52
+ * @param queue - The queue name.
53
+ */
54
+ size(queue: string): Promise<number>;
55
+ /**
56
+ * Clears all jobs from the queue.
57
+ *
58
+ * @param queue - The queue name.
59
+ */
60
+ clear(queue: string): Promise<void>;
61
+ /**
62
+ * Moves a job to the failed (DLQ) list.
63
+ *
64
+ * In MemoryDriver, this simply pushes to a `failed:{queue}` list.
65
+ *
66
+ * @param queue - The original queue name.
67
+ * @param job - The failed job.
68
+ */
69
+ fail(queue: string, job: SerializedJob): Promise<void>;
70
+ /**
71
+ * Retrieves statistics for the queue.
72
+ *
73
+ * Calculates pending, delayed, and failed counts by iterating through the list.
74
+ *
75
+ * @param queue - The queue name.
76
+ */
77
+ stats(queue: string): Promise<QueueStats>;
78
+ /**
79
+ * Pushes multiple jobs to the queue.
80
+ *
81
+ * @param queue - The queue name.
82
+ * @param jobs - Array of jobs.
83
+ */
84
+ pushMany(queue: string, jobs: SerializedJob[]): Promise<void>;
85
+ /**
86
+ * Pops multiple jobs from the queue.
87
+ *
88
+ * @param queue - The queue name.
89
+ * @param count - Max jobs to pop.
90
+ */
91
+ popMany(queue: string, count: number): Promise<SerializedJob[]>;
92
+ /**
93
+ * Lists all active queues in memory.
94
+ */
95
+ getQueues(): Promise<string[]>;
96
+ /**
97
+ * Stub: MemoryDriver doesn't support reactive notifications.
98
+ */
99
+ enableNotifications(): Promise<void>;
100
+ /**
101
+ * Stub: MemoryDriver doesn't support reactive notifications.
102
+ */
103
+ disableNotifications(): Promise<void>;
104
+ /**
105
+ * Stub: MemoryDriver doesn't support reactive notifications.
106
+ */
107
+ onNotify(_queues: string | string[], _callback: (queue: string) => Promise<void>): Promise<void>;
108
+ }
@@ -0,0 +1,250 @@
1
+ import type { JobPushOptions, QueueStats, SerializedJob, TopicOptions } from '../types';
2
+ /**
3
+ * Queue driver interface.
4
+ *
5
+ * Defines the contract that all storage backends (Redis, Database, SQS, etc.) must implement
6
+ * to be compatible with the QueueManager. It covers the basic operations for a job queue:
7
+ * push, pop, size, and clear.
8
+ *
9
+ * Advanced capabilities like rate limiting, reliable delivery (acknowledgements), and
10
+ * batch operations are optional but recommended for high-performance drivers.
11
+ *
12
+ * @public
13
+ * @example
14
+ * ```typescript
15
+ * class MyCustomDriver implements QueueDriver {
16
+ * async push(queue: string, job: SerializedJob) {
17
+ * // ... write to storage
18
+ * }
19
+ * async pop(queue: string) {
20
+ * // ... read from storage
21
+ * return job;
22
+ * }
23
+ * async size(queue: string) { return 0; }
24
+ * async clear(queue: string) {}
25
+ * }
26
+ * ```
27
+ */
28
+ export interface QueueDriver {
29
+ /**
30
+ * Pushes a job onto the specified queue.
31
+ *
32
+ * @param queue - The name of the queue.
33
+ * @param job - The serialized job data.
34
+ * @param options - Optional parameters like priority or group ID.
35
+ * @returns A promise that resolves when the job is successfully stored.
36
+ */
37
+ push(queue: string, job: SerializedJob, options?: JobPushOptions): Promise<void>;
38
+ /**
39
+ * Retrieves and removes the next job from the queue (FIFO).
40
+ *
41
+ * @param queue - The name of the queue.
42
+ * @returns The serialized job if available, or `null` if the queue is empty.
43
+ */
44
+ pop(queue: string): Promise<SerializedJob | null>;
45
+ /**
46
+ * Blocking version of `pop`. Waits for a job to arrive if the queue is empty.
47
+ *
48
+ * @param queues - A single queue name or an array of queues to listen to.
49
+ * @param timeout - The maximum time to wait in seconds (0 means indefinite).
50
+ * @returns The serialized job if one arrives within the timeout, or `null`.
51
+ */
52
+ popBlocking?(queues: string | string[], timeout: number): Promise<SerializedJob | null>;
53
+ /**
54
+ * Marks a job as completed.
55
+ *
56
+ * Used primarily by drivers that support advanced flow control (like FIFO groups)
57
+ * or explicit acknowledgement (like SQS/RabbitMQ).
58
+ *
59
+ * @param queue - The name of the queue.
60
+ * @param job - The job that was completed.
61
+ */
62
+ complete?(queue: string, job: SerializedJob): Promise<void>;
63
+ /**
64
+ * Returns the number of jobs currently waiting in the queue.
65
+ *
66
+ * @param queue - The name of the queue.
67
+ * @returns The count of pending jobs.
68
+ */
69
+ size(queue: string): Promise<number>;
70
+ /**
71
+ * Removes all jobs from the specified queue.
72
+ *
73
+ * @param queue - The name of the queue to purge.
74
+ */
75
+ clear(queue: string): Promise<void>;
76
+ /**
77
+ * Moves a job to the Dead Letter Queue (DLQ) after repeated failures.
78
+ *
79
+ * @param queue - The original queue name.
80
+ * @param job - The job data (usually including error information).
81
+ */
82
+ fail?(queue: string, job: SerializedJob): Promise<void>;
83
+ /**
84
+ * Retrieves detailed statistics for a queue.
85
+ *
86
+ * @param queue - The name of the queue.
87
+ * @returns An object containing counts for pending, delayed, failed, etc.
88
+ */
89
+ stats?(queue: string): Promise<QueueStats>;
90
+ /**
91
+ * Pushes multiple jobs to the queue in a single batch operation.
92
+ *
93
+ * @param queue - The name of the queue.
94
+ * @param jobs - An array of serialized jobs.
95
+ */
96
+ pushMany?(queue: string, jobs: SerializedJob[]): Promise<void>;
97
+ /**
98
+ * Retrieves multiple jobs from the queue in a single batch operation.
99
+ *
100
+ * @param queue - The name of the queue.
101
+ * @param count - The maximum number of jobs to retrieve.
102
+ * @returns An array of serialized jobs.
103
+ */
104
+ popMany?(queue: string, count: number): Promise<SerializedJob[]>;
105
+ /**
106
+ * Acknowledges a specific message by its ID.
107
+ *
108
+ * Used for drivers that require explicit acknowledgement (e.g., SQS, Kafka).
109
+ *
110
+ * @param messageId - The ID of the message to acknowledge.
111
+ */
112
+ acknowledge?(messageId: string): Promise<void>;
113
+ /**
114
+ * Subscribes to a queue for real-time job processing (Push model).
115
+ *
116
+ * Alternative to polling (`pop`). The driver pushes jobs to the callback as they arrive.
117
+ *
118
+ * @param queue - The name of the queue.
119
+ * @param callback - The function to call when a job is received.
120
+ */
121
+ subscribe?(queue: string, callback: (job: SerializedJob) => Promise<void>): Promise<void>;
122
+ /**
123
+ * Creates a new topic or queue (for drivers like Kafka/RabbitMQ).
124
+ *
125
+ * @param topic - The name of the topic/queue.
126
+ * @param options - Configuration options (partitions, replication, etc.).
127
+ */
128
+ createTopic?(topic: string, options?: TopicOptions): Promise<void>;
129
+ /**
130
+ * Deletes a topic or queue.
131
+ *
132
+ * @param topic - The name of the topic/queue to delete.
133
+ */
134
+ deleteTopic?(topic: string): Promise<void>;
135
+ /**
136
+ * Sends a heartbeat signal for a worker instance.
137
+ *
138
+ * Used for monitoring worker health and presence.
139
+ *
140
+ * @param workerInfo - Metadata about the worker (ID, status, resources).
141
+ * @param prefix - Optional key prefix for storage.
142
+ */
143
+ reportHeartbeat?(workerInfo: {
144
+ id: string;
145
+ status: string;
146
+ hostname: string;
147
+ pid: number;
148
+ uptime: number;
149
+ last_ping: string;
150
+ queues: string[];
151
+ metrics?: Record<string, any>;
152
+ [key: string]: any;
153
+ }, prefix?: string): Promise<void>;
154
+ /**
155
+ * Publishes a log entry to the monitoring system.
156
+ *
157
+ * @param logPayload - The log data (level, message, context).
158
+ * @param prefix - Optional key prefix.
159
+ */
160
+ publishLog?(logPayload: {
161
+ level: string;
162
+ message: string;
163
+ workerId: string;
164
+ jobId?: string;
165
+ timestamp: string;
166
+ [key: string]: any;
167
+ }, prefix?: string): Promise<void>;
168
+ /**
169
+ * Checks if a specific queue has exceeded its rate limit.
170
+ *
171
+ * @param queue - The name of the queue.
172
+ * @param config - The rate limit rules (max jobs per duration).
173
+ * @returns `true` if the job is allowed to proceed, `false` if limited.
174
+ */
175
+ checkRateLimit?(queue: string, config: {
176
+ max: number;
177
+ duration: number;
178
+ }): Promise<boolean>;
179
+ /**
180
+ * Retries failed jobs from the Dead Letter Queue.
181
+ *
182
+ * Moves jobs from the DLQ back to the active queue.
183
+ *
184
+ * @param queue - The name of the queue.
185
+ * @param count - The number of jobs to retry (optional).
186
+ * @returns The number of jobs actually moved.
187
+ */
188
+ retryFailed?(queue: string, count?: number): Promise<number>;
189
+ /**
190
+ * Retrieves a list of failed jobs from the Dead Letter Queue.
191
+ *
192
+ * @param queue - The name of the queue.
193
+ * @param start - Pagination start index.
194
+ * @param end - Pagination end index.
195
+ * @returns An array of failed jobs.
196
+ */
197
+ getFailed?(queue: string, start?: number, end?: number): Promise<SerializedJob[]>;
198
+ /**
199
+ * Clears the Dead Letter Queue for a specific queue.
200
+ *
201
+ * @param queue - The name of the queue.
202
+ */
203
+ clearFailed?(queue: string): Promise<void>;
204
+ /**
205
+ * Lists all queues managed by this driver.
206
+ *
207
+ * Useful for monitoring dashboards to discover active queues dynamically.
208
+ *
209
+ * @returns A list of queue names.
210
+ */
211
+ getQueues?(): Promise<string[]>;
212
+ /**
213
+ * Registers a notification listener for when jobs arrive in a queue.
214
+ *
215
+ * Only sends the queue name as notification, not the job data itself.
216
+ * The consumer is responsible for pulling jobs from the queue.
217
+ * This enables reactive pull-based consumption with low latency.
218
+ *
219
+ * @param queues - One or more queue names to listen for notifications.
220
+ * @param callback - Called when a job arrives in any of the queues, with the queue name.
221
+ * @returns A promise that resolves when the listener is registered.
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * driver.onNotify(['emails', 'sms'], (queue) => {
226
+ * console.log(`Job arrived in ${queue}`);
227
+ * // Consumer will pull from this queue reactively
228
+ * });
229
+ * ```
230
+ */
231
+ onNotify?(queues: string | string[], callback: (queue: string) => Promise<void>): Promise<void>;
232
+ /**
233
+ * Enables real-time notifications for job arrivals.
234
+ *
235
+ * Activates the notification mechanism so that `onNotify` callbacks are invoked.
236
+ * Called once during consumer startup.
237
+ *
238
+ * @returns A promise that resolves when notifications are enabled.
239
+ */
240
+ enableNotifications?(): Promise<void>;
241
+ /**
242
+ * Disables real-time notifications for job arrivals.
243
+ *
244
+ * Stops the notification mechanism to prevent further `onNotify` callbacks.
245
+ * Called during consumer shutdown.
246
+ *
247
+ * @returns A promise that resolves when notifications are disabled.
248
+ */
249
+ disableNotifications?(): Promise<void>;
250
+ }
@@ -0,0 +1,102 @@
1
+ import type { SerializedJob } from '../types';
2
+ import type { QueueDriver } from './QueueDriver';
3
+ /**
4
+ * RabbitMQ driver configuration.
5
+ */
6
+ export interface RabbitMQDriverConfig {
7
+ /**
8
+ * RabbitMQ client (amqplib) Connection or Channel.
9
+ * If a Connection is provided, the driver will create and manage a Channel.
10
+ */
11
+ client: any;
12
+ /**
13
+ * Exchange name (optional).
14
+ */
15
+ exchange?: string;
16
+ /**
17
+ * Exchange type (default: 'fanout').
18
+ */
19
+ exchangeType?: 'direct' | 'topic' | 'headers' | 'fanout' | 'match';
20
+ }
21
+ /**
22
+ * RabbitMQ (AMQP) queue driver.
23
+ *
24
+ * Uses RabbitMQ as the backend. Supports standard AMQP queues, exchanges,
25
+ * and reliable message acknowledgements.
26
+ *
27
+ * @public
28
+ * @example
29
+ * ```typescript
30
+ * import amqp from 'amqplib';
31
+ * const conn = await amqp.connect('amqp://localhost');
32
+ * const driver = new RabbitMQDriver({ client: conn });
33
+ * ```
34
+ */
35
+ export declare class RabbitMQDriver implements QueueDriver {
36
+ private connection;
37
+ private channel;
38
+ private exchange?;
39
+ private exchangeType;
40
+ constructor(config: RabbitMQDriverConfig);
41
+ /**
42
+ * Ensure channel is created.
43
+ */
44
+ ensureChannel(): Promise<any>;
45
+ /**
46
+ * Get the underlying connection.
47
+ */
48
+ getRawConnection(): any;
49
+ /**
50
+ * Pushes a job to a RabbitMQ queue or exchange.
51
+ *
52
+ * @param queue - The queue name.
53
+ * @param job - The serialized job.
54
+ */
55
+ push(queue: string, job: SerializedJob): Promise<void>;
56
+ /**
57
+ * Pops a job from the queue.
58
+ *
59
+ * @param queue - The queue name.
60
+ */
61
+ pop(queue: string): Promise<SerializedJob | null>;
62
+ /**
63
+ * Pops multiple jobs.
64
+ *
65
+ * @param queue - The queue name.
66
+ * @param count - Max jobs.
67
+ */
68
+ popMany(queue: string, count: number): Promise<SerializedJob[]>;
69
+ /**
70
+ * Acknowledges a message.
71
+ *
72
+ * @param messageId - The message object (RabbitMQ requires object reference).
73
+ */
74
+ acknowledge(messageId: string): Promise<void>;
75
+ /**
76
+ * Negative acknowledge a message.
77
+ */
78
+ nack(message: any, requeue?: boolean): Promise<void>;
79
+ /**
80
+ * Reject a message.
81
+ */
82
+ reject(message: any, requeue?: boolean): Promise<void>;
83
+ /**
84
+ * Subscribes to a queue.
85
+ */
86
+ subscribe(queue: string, callback: (job: SerializedJob) => Promise<void>, options?: {
87
+ autoAck?: boolean;
88
+ prefetch?: number;
89
+ }): Promise<void>;
90
+ /**
91
+ * Returns the number of messages in the queue.
92
+ *
93
+ * @param queue - The queue name.
94
+ */
95
+ size(queue: string): Promise<number>;
96
+ /**
97
+ * Purges the queue.
98
+ *
99
+ * @param queue - The queue name.
100
+ */
101
+ clear(queue: string): Promise<void>;
102
+ }