Abstract Class: QueueDriver
The transport of a Queue: it sends, delivers, acknowledges and redelivers the messages of a server (or of the memory); the queue does the rest (the retries, the dead letters, the codec, the results, the replies). A custom driver extends it and is given to the driver option of the queue as {type: 'custom', driver: new MyDriver()}.
Example
import {QueueDriver, type QueueCapabilities, type QueueConsumeOptions, type QueueDelivery, type QueueMessage, type QueueSubscription} from '@lakutata/queue'
//A driver dropping its messages (a skeleton)
class NullQueueDriver extends QueueDriver {
public readonly capabilities: QueueCapabilities = {delay: false, redeliverAfter: false, dedupe: false, priority: false, ordering: false, results: false, reply: false}
public async connect(): Promise<void> {}
public async send(_message: QueueMessage): Promise<boolean> {
return true
}
public async consume(_options: QueueConsumeOptions, _handler: (delivery: QueueDelivery) => Promise<void>): Promise<QueueSubscription> {
return {stop: async (): Promise<void> => {}}
}
public async groups(_name: string): Promise<string[]> {
return []
}
public async close(): Promise<void> {}
}Extended by
Constructors
Constructor
new QueueDriver():
QueueDriver
Returns
QueueDriver
Properties
capabilities
abstractreadonlycapabilities:QueueCapabilities
What the driver supports natively.
lease?
readonlyoptionallease?:number
The lease of a delivery, in milliseconds: the time before the server delivers it again when it is not ended. The queue extends the deliveries being processed every third of it. Undefined when the deliveries have no lease.
Methods
close()
abstractclose():Promise<void>
Close the connection: the subscriptions stop.
Returns
Promise<void>
Resolved once closed.
connect()
abstractconnect():Promise<void>
Connect to the server.
Returns
Promise<void>
Resolved once connected.
consume()
abstractconsume(options,handler):Promise<QueueSubscription>
Deliver the messages of a queue to a group of this instance.
Parameters
options
The queue, the group and the concurrency.
handler
(delivery) => Promise<void>
Called for each delivery; it ends the delivery.
Returns
Promise<QueueSubscription>
The subscription.
groups()
abstractgroups(name):Promise<string[] |undefined>
The groups consuming a queue (the ones known to the driver).
Parameters
name
string
The queue.
Returns
Promise<string[] | undefined>
The names of the groups, undefined when the driver cannot list them (the queue then keeps them in the store of its results).
onReply()?
optionalonReply(handler):void
Receive the replies sent to this instance (capability reply).
Parameters
handler
(reply) => void
Called for each reply.
Returns
void
readResult()?
optionalreadResult(key):Promise<Uint8Array<ArrayBufferLike> |undefined>
Read a value kept by QueueDriver.saveResult (capability results).
Parameters
key
string
The key.
Returns
Promise<Uint8Array<ArrayBufferLike> | undefined>
The value, or undefined when it is not kept.
register()?
optionalregister(name,group):Promise<void>
Register a group of a queue before it consumes the queue: the messages sent from then on are kept for it. A driver registering its groups only when they consume does not have it.
Parameters
name
string
The queue.
group
string
The group.
Returns
Promise<void>
reply()?
optionalreply(address,reply):Promise<void>
Send a reply to an instance (capability reply).
Parameters
address
string
Its address.
reply
The reply.
Returns
Promise<void>
Resolved once sent.
replyAddress()?
optionalreplyAddress():string
The address the replies to this instance are sent to (capability reply).
Returns
string
The address.
saveResult()?
optionalsaveResult(key,value,ttl):Promise<void>
Keep a value (capability results).
Parameters
key
string
The key.
value
Uint8Array
The value.
ttl
number
How long it is kept, in milliseconds.
Returns
Promise<void>
Resolved once kept.
send()
abstractsend(message):Promise<boolean>
Send a message to each group of its queue.
Parameters
message
The message.
Returns
Promise<boolean>
False when it is dropped as a duplicate (dedupe).