Class: Message
TypeScript 0.4.0 · Source commit cbff27b8a34e1384384018680e46c20d5c610cc9. Generated with reviewed comment corrections; see generation notes.
Defined in: message.ts:15
Message class representing a message retrieved from a queue. Provides methods for acknowledging, negatively acknowledging, or releasing the message, as well as changing its visibility timeout.
Each delivery object permits one terminal attempt: ack(),
ackWithTransaction(), nack(), or release(). Tracking and automatic
renewal end after that attempt, even when it fails. A later settlement or
setVt() call throws an "already been processed" Error; the wording does
not establish that the earlier database operation succeeded.
Settlement and setVt() preserve LeaseLostError, QueueNotFoundError, and
ValidationError from their database wrappers (PMQ01, PMQ02, PMQ03). Other
failures are wrapped in a plain Error, including ConnectionClosedError.
ack/nack/release check database processing state and token; elapsed
visibility alone does not reject them. setVt() also rejects expiry.
Properties
consumerToken
readonlyconsumerToken:string
Defined in: message.ts:26
Consumer token for this message
deliveryAttempts
readonlydeliveryAttempts:number
Defined in: message.ts:29
Number of delivery attempts
groupKey
readonlygroupKey:string|null
Defined in: message.ts:35
Message group (see PublishOptions.groupKey); null if ungrouped
groupSeq
readonlygroupSeq:number|null
Defined in: message.ts:38
Dense 1-based position in the group, in publish commit order; null if ungrouped
id
readonlyid:number
Defined in: message.ts:17
Message ID
payload
readonlypayload:any
Defined in: message.ts:23
Message payload
publishedAt
readonlypublishedAt:Date
Defined in: message.ts:32
Published timestamp
queueName
readonlyqueueName:string
Defined in: message.ts:20
Queue name
vt
vt:
Date
Defined in: message.ts:41
Visibility timeout expiration
Accessors
isSettled
Get Signature
get isSettled():
boolean
Defined in: message.ts:171
True once a terminal operation (ack / nack / release) has been attempted on this message, whether or not it succeeded. HandlerConsumer uses this to decide whether to auto-ack a message the handler returned without settling. Mirrors the "completed" tracking in the Go HandlerConsumer.
Returns
boolean
signal
Get Signature
get signal():
AbortSignal
Defined in: message.ts:161
Cancellation signal for this delivery. It is aborted on consumer stop,
connection close, queue-fatal teardown, or detected ownership loss through
automatic renewal or a setVt() LeaseLostError. It is not a deadline timer
and does not mean that settlement must fail: shutdown alone does not
invalidate the database token.
Stop application work when signalled, then settle as appropriate. Release work that was never attempted; nack work that started but did not complete. Settlement can fail if ownership was lost. Do not leave a delivery unsettled solely because its signal is aborted: that can hold shutdown until its timeout.
Example
for await (const msg of consumer.messages()) {
if (msg.signal.aborted) {
await msg.release(); // No application work was attempted.
continue;
}
try {
await doWork(msg.payload, { signal: msg.signal });
} catch (error) {
await msg.nack(); // Work started; keep this delivery attempt.
continue;
}
await msg.ack(); // A shutdown signal alone does not prevent acknowledgement.
}
The example lets settlement errors reach the caller. After a terminal attempt, do not retry settlement on the same object; handle uncertain outcomes with idempotent processing when the message is redelivered.
Returns
AbortSignal
Methods
ack()
ack():
Promise<void>
Defined in: message.ts:193
Acknowledge the message as successfully processed. The delivery becomes completed and is retained until cleanup.
Returns
Promise<void>
Promise that resolves when acknowledgment is complete
Throws
LeaseLostError, QueueNotFoundError, or ValidationError for translated database failures; plain Error for a previous terminal attempt or other failures.
ackWithTransaction()
ackWithTransaction(
tx):Promise<void>
Defined in: message.ts:217
Acknowledge within a caller-owned transaction on the supplied client. This method does not issue BEGIN, COMMIT, or ROLLBACK, and does not retry. Success means the statement finished, not that the transaction committed. Tracking and renewal end when this statement finishes, even if it fails. If the transaction rolls back, the delivery can become eligible again after its visibility timeout; this Message object cannot settle it again. Commit promptly and make application effects safe to repeat.
Parameters
tx
The transaction object
Returns
Promise<void>
Promise that resolves when acknowledgment is complete
Throws
LeaseLostError, QueueNotFoundError, or ValidationError for translated database failures; plain Error for a previous terminal attempt or other failures.
nack()
nack(
options?):Promise<void>
Defined in: message.ts:241
Negatively acknowledge the message, returning it to the queue for reprocessing after an optional delay, or moving it to the DLQ when attempts are exhausted.
Parameters
options?
Options for negative acknowledgment
Returns
Promise<void>
Promise that resolves when negative acknowledgment is complete
Throws
LeaseLostError, QueueNotFoundError, or ValidationError for translated database failures; plain Error for a previous terminal attempt or other failures.
release()
release():
Promise<void>
Defined in: message.ts:269
Release the message back to the queue, refunding the current delivery attempt. Use this when you haven't actually attempted to process the message.
Returns
Promise<void>
Promise that resolves when release is complete
Throws
LeaseLostError, QueueNotFoundError, or ValidationError for translated database failures; plain Error for a previous terminal attempt or other failures.
setVt()
setVt(
newVt):Promise<Date>
Defined in: message.ts:292
Set the visibility deadline to database time now plus newVt seconds.
This replaces the deadline rather than adding to it, so it can shorten an
existing lease. Enabled automatic renewal can subsequently replace it with
the consumer's configured visibility duration.
Parameters
newVt
number
Nonnegative integer duration in seconds.
Returns
Promise<Date>
The new expiration date, also assigned to message.vt.
Throws
LeaseLostError if the delivery expired or its processing state/token
no longer match. This error also aborts message.signal.
Throws
QueueNotFoundError or ValidationError for the corresponding translated database failures; plain Error for a prior terminal attempt or other failures.