Class Message (2.14.1)

Message(message: types.PubsubMessage._meta._pb, ack_id: str, delivery_attempt: int, request_queue: queue.Queue, exactly_once_delivery_enabled_func: Callable[[], bool] = <function Message.<lambda>>)

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.)

The data in the message. Note that this will be a bytes, not a text string.

The time that this message was originally published.

Properties

ack_id

the ID used to ack the message.

attributes

Return the attributes of the underlying Pub/Sub Message.

data

Return the data for the underlying Pub/Sub Message.

delivery_attempt

The delivery attempt counter is 1 + (the sum of number of NACKs and number of ack_deadline exceeds) for this message. It is set to None if a DeadLetterPolicy is not set on the subscription.

A NACK is any call to ModifyAckDeadline with a 0 deadline. An ack_deadline exceeds event is whenever a message is not acknowledged within ack_deadline. Note that ack_deadline is initially Subscription.ackDeadlineSeconds, but may get extended automatically by the client library.

The first delivery of a given message will have this value as 1. The value is calculated at best effort and is approximate.

ordering_key

The ordering key used to publish the message.

publish_time

Return the time that the message was originally published.

size

Return the size of the underlying message, in bytes.

Methods

Message

Message(message: types.PubsubMessage._meta._pb, ack_id: str, delivery_attempt: int, request_queue: queue.Queue, exactly_once_delivery_enabled_func: Callable[[], bool] = <function Message.<lambda>>)

Construct the Message.

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.

ack_with_response

ack_with_response()

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.

If exactly-once delivery is NOT enabled on the subscription, the future returns immediately with an AcknowledgeStatus.SUCCESS. Since acks in Cloud Pub/Sub are best effort when exactly-once delivery is disabled, the message may be re-delivered. Because re-deliveries are possible, you should ensure that your processing code is idempotent, as you may receive any given message more than once.

If exactly-once delivery is enabled on the subscription, the future returned by this method tracks the state of acknowledgement operation. If the future completes successfully, the message is guaranteed NOT to be re-delivered. Otherwise, the future will contain an exception with more details about the failure and the message may be re-delivered.

Exactly once delivery is a preview feature. For more details, see https://cloud.google.com/pubsub/docs/exactly-once-delivery."

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: int)

Resets the deadline for acknowledgement.

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

The default implementation handles automatically modacking received messages 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.

modify_ack_deadline_with_response

modify_ack_deadline_with_response(seconds: int)

Resets the deadline for acknowledgement and returns the response status via a future.

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

The default implementation handles automatically modacking received messages 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.

If exactly-once delivery is NOT enabled on the subscription, the future returns immediately with an AcknowledgeStatus.SUCCESS. Since modify-ack-deadline operations in Cloud Pub/Sub are best effort when exactly-once delivery is disabled, the message may be re-delivered within the set deadline.

If exactly-once delivery is enabled on the subscription, the future returned by this method tracks the state of the modify-ack-deadline operation. If the future completes successfully, the message is guaranteed NOT to be re-delivered within the new deadline. Otherwise, the future will contain an exception with more details about the failure and the message will be redelivered according to its currently-set ack deadline.

Exactly once delivery is a preview feature. For more details, see https://cloud.google.com/pubsub/docs/exactly-once-delivery."

nack

nack()

Decline to acknowledge the given message.

This will cause the message to be re-delivered to subscribers. Re-deliveries may take place immediately or after a delay, and may arrive at this subscriber or another.

nack_with_response

nack_with_response()

Decline to acknowledge the given message, returning the response status via a future.

This will cause the message to be re-delivered to subscribers. Re-deliveries may take place immediately or after a delay, and may arrive at this subscriber or another.

If exactly-once delivery is NOT enabled on the subscription, the future returns immediately with an AcknowledgeStatus.SUCCESS.

If exactly-once delivery is enabled on the subscription, the future returned by this method tracks the state of the nack operation. If the future completes successfully, the future's result will be an AcknowledgeStatus.SUCCESS. Otherwise, the future will contain an exception with more details about the failure.

Exactly once delivery is a preview feature. For more details, see https://cloud.google.com/pubsub/docs/exactly-once-delivery."