public sealed class PubsubMessage : IMessage<PubsubMessage>, IEquatable<PubsubMessage>, IDeepCloneable<PubsubMessage>, IBufferMessage, IMessage
Reference documentation and code samples for the Cloud Pub/Sub v1 API class PubsubMessage.
A message that is published by publishers and consumed by subscribers. The
message must contain either a non-empty data field or at least one attribute.
Note that client libraries represent this object differently
depending on the language. See the corresponding client library
documentation for
more information. See quotas and limits for more information about message
limits.
public MapField<string, string> Attributes { get; }
Optional. Attributes for this message. If this field is empty, the message
must contain non-empty data. This can be used to filter messages on the
subscription.
ID of this message, assigned by the server when the message is published.
Guaranteed to be unique within the topic. This value may be read by a
subscriber that receives a PubsubMessage via a Pull call or a push
delivery. It must not be populated by the publisher in a Publish call.
Optional. If non-empty, identifies related messages for which publish order
should be respected. If a Subscription has enable_message_ordering set
to true, messages published with the same non-empty ordering_key value
will be delivered to subscribers in the order in which they are received by
the Pub/Sub system. All PubsubMessages published in a given
PublishRequest must specify the same ordering_key value. For more
information, see ordering
messages.
The time at which the message was published, populated by the server when
it receives the Publish call. It must not be populated by the
publisher in a Publish call.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis webpage provides reference documentation for the \u003ccode\u003ePubsubMessage\u003c/code\u003e class within the Google Cloud Pub/Sub v1 API for .NET, including links to various version-specific details.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ePubsubMessage\u003c/code\u003e class represents a message that is published and consumed, and it requires either a non-empty data field or at least one attribute.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ePubsubMessage\u003c/code\u003e class inherits from \u003ccode\u003eobject\u003c/code\u003e and implements several interfaces such as \u003ccode\u003eIMessage\u003c/code\u003e, \u003ccode\u003eIEquatable\u003c/code\u003e, \u003ccode\u003eIDeepCloneable\u003c/code\u003e, and \u003ccode\u003eIBufferMessage\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eKey properties of \u003ccode\u003ePubsubMessage\u003c/code\u003e include \u003ccode\u003eAttributes\u003c/code\u003e, \u003ccode\u003eData\u003c/code\u003e, \u003ccode\u003eMessageId\u003c/code\u003e, \u003ccode\u003eOrderingKey\u003c/code\u003e, and \u003ccode\u003ePublishTime\u003c/code\u003e, which handle message details and ordering.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of \u003ccode\u003ePubsubMessage\u003c/code\u003e is version 3.23.0, and the page lists all version references, dating back to version 2.3.0, each accessible via its link.\u003c/p\u003e\n"]]],[],null,["# Cloud Pub/Sub v1 API - Class PubsubMessage (3.27.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.27.0 (latest)](/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.26.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.26.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.25.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.25.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.24.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.24.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.23.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.23.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.22.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.22.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.21.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.21.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.20.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.20.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.19.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.19.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.18.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.18.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.17.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.17.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.16.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.16.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.15.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.15.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.14.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.14.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.13.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.13.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.12.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.12.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.11.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.11.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.10.1](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.10.1/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.9.1](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.9.1/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.8.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.8.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.7.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.7.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.6.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.6.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.5.1](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.5.1/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.4.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.4.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.3.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.3.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.2.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.2.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.1.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.1.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [3.0.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/3.0.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.10.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.10.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.9.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.9.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.8.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.8.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.7.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.7.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.6.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.6.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.5.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.5.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.4.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.4.0/Google.Cloud.PubSub.V1.PubsubMessage)\n- [2.3.0](/dotnet/docs/reference/Google.Cloud.PubSub.V1/2.3.0/Google.Cloud.PubSub.V1.PubsubMessage) \n\n public sealed class PubsubMessage : IMessage\u003cPubsubMessage\u003e, IEquatable\u003cPubsubMessage\u003e, IDeepCloneable\u003cPubsubMessage\u003e, IBufferMessage, IMessage\n\nReference documentation and code samples for the Cloud Pub/Sub v1 API class PubsubMessage.\n\nA message that is published by publishers and consumed by subscribers. The\nmessage must contain either a non-empty data field or at least one attribute.\nNote that client libraries represent this object differently\ndepending on the language. See the corresponding [client library\ndocumentation](https://cloud.google.com/pubsub/docs/reference/libraries) for\nmore information. See [quotas and limits](https://cloud.google.com/pubsub/quotas) for more information about message\nlimits. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e PubsubMessage \n\nImplements\n----------\n\n[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[PubsubMessage](/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessage), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[PubsubMessage](/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessage), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[PubsubMessage](/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessage), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html) \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.PubSub.V1](/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1)\n\nAssembly\n--------\n\nGoogle.Cloud.PubSub.V1.dll\n\nConstructors\n------------\n\n### PubsubMessage()\n\n public PubsubMessage()\n\n### PubsubMessage(PubsubMessage)\n\n public PubsubMessage(PubsubMessage other)\n\nProperties\n----------\n\n### Attributes\n\n public MapField\u003cstring, string\u003e Attributes { get; }\n\nOptional. Attributes for this message. If this field is empty, the message\nmust contain non-empty data. This can be used to filter messages on the\nsubscription.\n\n### Data\n\n public ByteString Data { get; set; }\n\nOptional. The message data field. If this field is empty, the message must\ncontain at least one attribute.\n\n### MessageId\n\n public string MessageId { get; set; }\n\nID of this message, assigned by the server when the message is published.\nGuaranteed to be unique within the topic. This value may be read by a\nsubscriber that receives a `PubsubMessage` via a `Pull` call or a push\ndelivery. It must not be populated by the publisher in a `Publish` call.\n\n### OrderingKey\n\n public string OrderingKey { get; set; }\n\nOptional. If non-empty, identifies related messages for which publish order\nshould be respected. If a `Subscription` has `enable_message_ordering` set\nto `true`, messages published with the same non-empty `ordering_key` value\nwill be delivered to subscribers in the order in which they are received by\nthe Pub/Sub system. All `PubsubMessage`s published in a given\n`PublishRequest` must specify the same `ordering_key` value. For more\ninformation, see [ordering\nmessages](https://cloud.google.com/pubsub/docs/ordering).\n\n### PublishTime\n\n public Timestamp PublishTime { get; set; }\n\nThe time at which the message was published, populated by the server when\nit receives the `Publish` call. It must not be populated by the\npublisher in a `Publish` call.\n\nExtension Method\n----------------\n\n[PubsubExtensions.GetDeliveryAttempt(PubsubMessage)](/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubExtensions#Google_Cloud_PubSub_V1_PubsubExtensions_GetDeliveryAttempt_Google_Cloud_PubSub_V1_PubsubMessage_)"]]