Tracks a telemetry tracing parent span through the receive process. This will be the original publisher-side span if we have one; otherwise we'll create a "publisher" span to hang new subscriber spans onto.
This needs to be declared explicitly here, because having a public class implement a private interface seems to confuse TypeScript. (And it's needed in unit tests.)
publishTime
publishTime:PreciseDate;
received
received:number;
subSpans
subSpans:SubscriberSpans;
Tracks subscriber-specific telemetry objects through the library.
Acknowledges the message, expecting a response (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully.
Modifies the ack deadline, expecting a response (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully. At present time, this should generally not be called by users.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class Message (4.8.0)\n\nVersion latestkeyboard_arrow_down\n\n- [4.8.0 (latest)](/nodejs/docs/reference/pubsub/latest/pubsub/message)\n- [4.4.0](/nodejs/docs/reference/pubsub/4.4.0/pubsub/message)\n- [4.3.3](/nodejs/docs/reference/pubsub/4.3.3/pubsub/message)\n- [4.1.1](/nodejs/docs/reference/pubsub/4.1.1/pubsub/message)\n- [4.0.7](/nodejs/docs/reference/pubsub/4.0.7/pubsub/message)\n- [3.7.5](/nodejs/docs/reference/pubsub/3.7.5/pubsub/message)\n- [3.2.1](/nodejs/docs/reference/pubsub/3.2.1/pubsub/message)\n- [3.1.1](/nodejs/docs/reference/pubsub/3.1.1/pubsub/message)\n- [3.0.3](/nodejs/docs/reference/pubsub/3.0.3/pubsub/message)\n- [2.18.3](/nodejs/docs/reference/pubsub/2.18.3/pubsub/message)\n- [2.17.0](/nodejs/docs/reference/pubsub/2.17.0/pubsub/message)\n- [2.16.6](/nodejs/docs/reference/pubsub/2.16.6/pubsub/message)\n- [2.13.0](/nodejs/docs/reference/pubsub/2.13.0/pubsub/message) \nMessage objects provide a simple interface for users to get message data and acknowledge the message.\n\nPackage\n-------\n\n[@google-cloud/pubsub](../overview.html)\n\nExample\n-------\n\n\n subscription.on('message', message =\u003e {\n // {\n // ackId: 'RUFeQBJMJAxESVMrQwsqWBFOBCEhPjA',\n // attributes: {key: 'value'},\n // data: Buffer.from('Hello, world!'),\n // id: '1551297743043',\n // orderingKey: 'ordering-key',\n // publishTime: new PreciseDate('2019-02-27T20:02:19.029534186Z'),\n // received: 1551297743043,\n // length: 13\n // }\n });\n\nConstructors\n------------\n\n### (constructor)(sub, { ackId, message, deliveryAttempt })\n\n constructor(sub: Subscriber, { ackId, message, deliveryAttempt }: google.pubsub.v1.IReceivedMessage);\n\nConstructs a new instance of the `Message` class\n\nProperties\n----------\n\n### ackId\n\n ackId: string;\n\n### attributes\n\n attributes: {\n [key: string]: string;\n };\n\n### data\n\n data: Buffer;\n\n### deliveryAttempt\n\n deliveryAttempt: number;\n\n### id\n\n id: string;\n\n### length\n\n get length(): number;\n\nThe length of the message data.\n\n{number}\n\n### orderingKey\n\n orderingKey?: string;\n\n### parentSpan\n\n parentSpan?: tracing.Span;\n\nTracks a telemetry tracing parent span through the receive process. This will be the original publisher-side span if we have one; otherwise we'll create a \"publisher\" span to hang new subscriber spans onto.\n\nThis needs to be declared explicitly here, because having a public class implement a private interface seems to confuse TypeScript. (And it's needed in unit tests.)\n\n### publishTime\n\n publishTime: PreciseDate;\n\n### received\n\n received: number;\n\n### subSpans\n\n subSpans: SubscriberSpans;\n\nTracks subscriber-specific telemetry objects through the library.\n\nMethods\n-------\n\n### ack()\n\n ack(): void;\n\nAcknowledges the message.\n\n**Example** \n\n\n subscription.on('message', message =\u003e {\n message.ack();\n });\n\n### ackFailed(error)\n\n ackFailed(error: AckError): void;\n\nSets this message's exactly once delivery acks to permanent failure. This is meant for internal library use only.\n\n### ackWithResponse()\n\n ackWithResponse(): Promise\u003cAckResponse\u003e;\n\nAcknowledges the message, expecting a response (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully.\n\n**Example** \n\n\n subscription.on('message', async (message) =\u003e {\n const response = await message.ackWithResponse();\n });\n\n### endParentSpan()\n\n endParentSpan(): void;\n\nEnds any open subscribe telemetry tracing span.\n\n### modAck(deadline)\n\n modAck(deadline: number): void;\n\nModifies the ack deadline. At present time, this should generally not be called by users.\n\n### modAckWithResponse(deadline)\n\n modAckWithResponse(deadline: number): Promise\u003cAckResponse\u003e;\n\nModifies the ack deadline, expecting a response (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully. At present time, this should generally not be called by users.\n\n### nack()\n\n nack(): void;\n\nRemoves the message from our inventory and schedules it to be redelivered.\n\n**Example** \n\n\n subscription.on('message', message =\u003e {\n message.nack();\n });\n\n### nackWithResponse()\n\n nackWithResponse(): Promise\u003cAckResponse\u003e;\n\nRemoves 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.\n\n**Example** \n\n\n subscription.on('message', async (message) =\u003e {\n const response = await message.nackWithResponse();\n });"]]