1414
1515from __future__ import absolute_import
1616
17+ import datetime as dt
1718import json
1819import math
20+ import pytz
1921import time
2022
2123from google .cloud .pubsub_v1 .subscriber ._protocol import requests
@@ -79,7 +81,7 @@ def __init__(self, message, ack_id, delivery_attempt, request_queue):
7981
8082 Args:
8183 message (~.pubsub_v1.types.PubsubMessage): The message received
82- from Pub/Sub.
84+ from Pub/Sub. TODO: it's the raw protobuf message! for performance
8385 ack_id (str): The ack_id received from Pub/Sub.
8486 delivery_attempt (int): The delivery attempt counter received
8587 from Pub/Sub if a DeadLetterPolicy is set on the subscription,
@@ -99,6 +101,15 @@ def __init__(self, message, ack_id, delivery_attempt, request_queue):
99101 # the default lease deadline.
100102 self ._received_timestamp = time .time ()
101103
104+ self ._attributes = message .attributes
105+ self ._data = message .data
106+ self ._publish_time = dt .datetime .fromtimestamp (
107+ message .publish_time .seconds + message .publish_time .nanos / 1e9 ,
108+ tz = pytz .UTC ,
109+ )
110+ self ._ordering_key = message .ordering_key
111+ self ._size = message .ByteSize ()
112+
102113 def __repr__ (self ):
103114 # Get an abbreviated version of the data.
104115 abbv_data = self ._message .data
@@ -130,7 +141,7 @@ def attributes(self):
130141 .ScalarMapContainer: The message's attributes. This is a
131142 ``dict``-like object provided by ``google.protobuf``.
132143 """
133- return self ._message . attributes
144+ return self ._attributes
134145
135146 @property
136147 def data (self ):
@@ -140,7 +151,7 @@ def data(self):
140151 bytes: The message data. This is always a bytestring; if you
141152 want a text string, call :meth:`bytes.decode`.
142153 """
143- return self ._message . data
154+ return self ._data
144155
145156 @property
146157 def publish_time (self ):
@@ -149,17 +160,17 @@ def publish_time(self):
149160 Returns:
150161 datetime: The date and time that the message was published.
151162 """
152- return self ._message . publish_time
163+ return self ._publish_time
153164
154165 @property
155166 def ordering_key (self ):
156167 """str: the ordering key used to publish the message."""
157- return self ._message . ordering_key
168+ return self ._ordering_key
158169
159170 @property
160171 def size (self ):
161172 """Return the size of the underlying message, in bytes."""
162- return self ._message . _pb . ByteSize ()
173+ return self ._size
163174
164175 @property
165176 def ack_id (self ):
0 commit comments