Constructor
new Message(sub, message)
Parameters:
Name | Type | Description |
---|---|---|
sub |
Subscriber |
The parent subscriber. |
message |
object |
The raw message response. |
Example
```
subscription.on('message', message => {
// {
// ackId: 'RUFeQBJMJAxESVMrQwsqWBFOBCEhPjA',
// attributes: {key: 'value'},
// data: Buffer.from('Hello, world!'),
// id: '1551297743043',
// orderingKey: 'ordering-key',
// publishTime: new PreciseDate('2019-02-27T20:02:19.029534186Z'),
// received: 1551297743043,
// length: 13
// }
});
```
Members
ackId
This ID is used to acknowledge the message.
attributes
Optional attributes for this message.
data
The message data as a Buffer.
deliveryAttempt
Delivery attempt counter is 1 + (the sum of number of NACKs and number of ack_deadline exceeds) for this message.
id
ID of the message, assigned by the server when the message is published. Guaranteed to be unique within the topic.
length
The length of the message data.
orderingKey
Identifies related messages for which publish order should be respected.
If a Subscription
has enableMessageOrdering
set to true
, messages
published with the same orderingKey
value will be delivered to
subscribers in the order in which they are received by the Pub/Sub
system.
EXPERIMENTAL: This feature is part of a closed alpha release. This API might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.
publishTime
The time at which the message was published.
received
The time at which the message was recieved by the subscription.
Methods
ack()
Acknowledges the message.
(async) ackWithResponse()
Acknowledges the message, expecting a response (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully.
Example
```
subscription.on('message', async (message) => {
const response = await message.ackWithResponse();
});
```
nack()
Removes the message from our inventory and schedules it to be redelivered.
(async) nackWithResponse()
Removes the message from our inventory and schedules it to be redelivered, with the modAck response being returned (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully.