Class: MemoryQueueDriver
The memory driver of the queues ({type: 'memory'}, the default of a Queue): the messages are kept in the memory of the process, delivered to the groups of the process, lost when it exits. It supports every capability natively. A message sent to a queue no group consumes yet is kept for its first group (an application whose components add messages before its entrypoint starts loses none); the groups consuming it later receive the messages sent after them. For development, tests, desktop applications and the jobs whose loss does not matter; it needs no package.
Example
import {MemoryQueueDriver} from '@lakutata/queue'
const driver = new MemoryQueueDriver()
await driver.connect()
console.log(driver.capabilities.delay) //true
await driver.close()Extends
Constructors
Constructor
new MemoryQueueDriver():
MemoryQueueDriver
Returns
MemoryQueueDriver
Inherited from
Properties
capabilities
readonlycapabilities:QueueCapabilities
Every capability.
Overrides
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.
Inherited from
Methods
close()
close():
Promise<void>
Drop the messages and stop the subscriptions.
Returns
Promise<void>
Resolved at once.
Overrides
connect()
connect():
Promise<void>
Nothing to connect.
Returns
Promise<void>
Resolved at once.
Overrides
consume()
consume(
options,handler):Promise<QueueSubscription>
Deliver the messages of a queue to a group of this process.
Parameters
options
The queue, the group and the concurrency.
handler
(delivery) => Promise<void>
Called for each delivery.
Returns
Promise<QueueSubscription>
The subscription.
Overrides
groups()
groups(
name):Promise<string[]>
The groups consuming a queue in this process.
Parameters
name
string
The queue.
Returns
Promise<string[]>
The names of the groups.
Overrides
onReply()
onReply(
handler):void
Receive the replies.
Parameters
handler
(reply) => void
Called for each reply.
Returns
void
Overrides
readResult()
readResult(
key):Promise<Uint8Array<ArrayBufferLike> |undefined>
Read a value kept.
Parameters
key
string
The key.
Returns
Promise<Uint8Array<ArrayBufferLike> | undefined>
The value, or undefined when it is not kept (or expired).
Overrides
register()
register(
name,group):Promise<void>
Register a group of a queue: the messages sent from then on are kept for it (and the messages sent before the first group of the queue, for the first one).
Parameters
name
string
The queue.
group
string
The group.
Returns
Promise<void>
Overrides
reply()
reply(
address,reply):Promise<void>
Send a reply (to this driver only: the queues of the process are independent).
Parameters
address
string
The address.
reply
The reply.
Returns
Promise<void>
Resolved at once.
Overrides
replyAddress()
replyAddress():
string
The address of the replies to this driver.
Returns
string
The address.
Overrides
saveResult()
saveResult(
key,value,ttl):Promise<void>
Keep a value in memory.
Parameters
key
string
The key.
value
Uint8Array
The value.
ttl
number
How long it is kept, in milliseconds.
Returns
Promise<void>
Resolved at once.
Overrides
send()
send(
message):Promise<boolean>
Send a message to each group of its queue (to the first group to come when there is none).
Parameters
message
The message.
Returns
Promise<boolean>
False when it is dropped as a duplicate.