Class Message (1.1.0)

Message(message, ack_id, request_queue)

A representation of a single Pub/Sub message.

The common way to interact with .pubsub_v1.subscriber.message.Message objects is to receive them in callbacks on subscriptions; most users should never have a need to instantiate them by hand. (The exception to this is if you are implementing a custom subclass to .pubsub_v1.subscriber._consumer.Consumer.)

Attributes

NameDescription
message_id str
The message ID. In general, you should not need to use this directly.
data bytes
The data in the message. Note that this will be a bytes, not a text string.
attributes .ScalarMapContainer
The attributes sent along with the message. See attributes for more information on this type.
publish_time datetime
The time that this message was originally published.

Properties

ack_id

str: the ID used to ack the message.

attributes

Return the attributes of the underlying Pub/Sub Message.

Returns
TypeDescription
.ScalarMapContainerThe message's attributes. This is a dict-like object provided by google.protobuf.

data

Return the data for the underlying Pub/Sub Message.

Returns
TypeDescription
bytesThe message data. This is always a bytestring; if you want a text string, call bytes.decode.

publish_time

Return the time that the message was originally published.

Returns
TypeDescription
datetimeThe date and time that the message was published.

size

Return the size of the underlying message, in bytes.

Methods

Message

Message(message, ack_id, request_queue)

Construct the Message.

Parameters
NameDescription
message .pubsub_v1.types.PubsubMessage

The message received from Pub/Sub.

ack_id str

The ack_id received from Pub/Sub.

request_queue queue.Queue

A queue provided by the policy that can accept requests; the policy is responsible for handling those requests.

ack

ack()

Acknowledge the given message.

Acknowledging a message in Pub/Sub means that you are done with it, and it will not be delivered to this subscription again. You should avoid acknowledging messages until you have finished processing them, so that in the event of a failure, you receive the message again.

drop

drop()

Release the message from lease management.

This informs the policy to no longer hold on to the lease for this message. Pub/Sub will re-deliver the message if it is not acknowledged before the existing lease expires.

modify_ack_deadline

modify_ack_deadline(seconds)

Resets the deadline for acknowledgement.

New deadline will be the given value of seconds from now.

The default implementation handles this for you; you should not need to manually deal with setting ack deadlines. The exception case is if you are implementing your own custom subclass of .pubsub_v1.subcriber._consumer.Consumer.

Parameter
NameDescription
seconds int

The number of seconds to set the lease deadline to. This should be between 0 and 600. Due to network latency, values below 10 are advised against.

nack

nack()

Decline to acknowldge the given message.

This will cause the message to be re-delivered to the subscription.