Skip to content

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 ​

typescript
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 ​

QueueDriver.constructor

Properties ​

capabilities ​

readonly capabilities: QueueCapabilities

Every capability.

Overrides ​

QueueDriver.capabilities


lease? ​

readonly optional lease?: 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 ​

QueueDriver.lease

Methods ​

close() ​

close(): Promise<void>

Drop the messages and stop the subscriptions.

Returns ​

Promise<void>

Resolved at once.

Overrides ​

QueueDriver.close


connect() ​

connect(): Promise<void>

Nothing to connect.

Returns ​

Promise<void>

Resolved at once.

Overrides ​

QueueDriver.connect


consume() ​

consume(options, handler): Promise<QueueSubscription>

Deliver the messages of a queue to a group of this process.

Parameters ​

options ​

QueueConsumeOptions

The queue, the group and the concurrency.

handler ​

(delivery) => Promise<void>

Called for each delivery.

Returns ​

Promise<QueueSubscription>

The subscription.

Overrides ​

QueueDriver.consume


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 ​

QueueDriver.groups


onReply() ​

onReply(handler): void

Receive the replies.

Parameters ​

handler ​

(reply) => void

Called for each reply.

Returns ​

void

Overrides ​

QueueDriver.onReply


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 ​

QueueDriver.readResult


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 ​

QueueDriver.register


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 ​

QueueReply

The reply.

Returns ​

Promise<void>

Resolved at once.

Overrides ​

QueueDriver.reply


replyAddress() ​

replyAddress(): string

The address of the replies to this driver.

Returns ​

string

The address.

Overrides ​

QueueDriver.replyAddress


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 ​

QueueDriver.saveResult


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 ​

QueueMessage

The message.

Returns ​

Promise<boolean>

False when it is dropped as a duplicate.

Overrides ​

QueueDriver.send

Released under the MIT License.