Message

Message

Message objects provide a simple interface for users to get message data and acknowledge the message.

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.

Example
subscription.on('message', message => {
  message.ack();
});

nack()

Removes the message from our inventory and schedules it to be redelivered.

Example
subscription.on('message', message => {
  message.nack();
});