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.

Source:
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 :string

This ID is used to acknowledge the message.

Source:

attributes :object

Optional attributes for this message.

Source:

data :Buffer

The message data as a Buffer.

Source:

id :string

ID of the message, assigned by the server when the message is published. Guaranteed to be unique within the topic.

Source:

length :number

The length of the message data.

Source:

orderingKey :string

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.

Source:

publishTime :external:PreciseDate

The time at which the message was published.

Source:

received :number

The time at which the message was recieved by the subscription.

Source:

Methods

ack()

Acknowledges the message.

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

nack()

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

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