GeezerVison is showing github.com — pubsub Message class does not set timestamp · Issue #2243 · googleapis/google-cloud-python
pubsub Message class does not set timestamp #2243Labels api: pubsubIssues related to the Pub/Sub API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. Descriptionpubsub.Message timestamps are not set. There are two object properties, neither of them is set. What's even more confusing is that attempting to access an attribute of an instance throws an error.
To reproduce:
from gcloud import pubsub
t = pubsub.Client(project='...').topic('${TOPIC}')
# MAY NEED t.create()
s = t.subscription('${SUBSCRIPTION}')
# MAY NEED s.create()
t.publish('test data') # RETURNS A MSG ID
ack_id, m = s.pull() # WAS t.pull()Activityadded type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. on Sep 2, 2016dhermes commented on Sep 2, 2016 Trying to repro right now. dhermes commented on Sep 2, 2016 @kir-google-cloud-pubsub I can't reproduce. ack_id, m = s.pull() is essentially invalid, but maybe you meant to say
pairs = s.pull()
ack_id, m = pairs[0]
When I run the slightly modified code, I get
>>> pub_id = t.publish('test data')
>>> pub_id
u'44126525330808'
>>> msgs = s.pull()
>>> assert len(msgs) == 1
>>> ack_id, m = msgs[0]
>>> m.message_id
u'44126525330808'
>>> m.message_id == pub_id
True
>>> m.data
'test data'
Any more details you can provide? kir-titievsky commented on Sep 7, 2016 You are right -- about the mistake I meant. In your code, try m.timestamp -- it should be set, but is not. kir-titievsky commented on Sep 7, 2016 also, m.service_timestamp tseaver commented on Sep 7, 2016 There are two timestamps possible on a message:
message.timestamp is in the attributes of the message, and must therefore be set by the topic: setting those is controlled by the topic.timestamp_messages attribute, which defaults to False.
message.service_timestamp is set by the back-end, and parsed from the publishTime field of the pulled message resource.
To activate the first kind:
from gcloud.pubsub.client import Client
client = Client(project='...')
topic = client.topic('${TOPIC}', timestamp_messages=True)
t.create()
s = t.subscription('${SUBSCRIPTION}')
s.create()
t.publish('test data')
ack_ids = []
for ack_id, m in s.pull():
ack_ids.append(ack_id)
print(m.data, m.timestamp, m.service_timetamp)
sub.acknowledge(ack_ids)
On my box, the previous example yields:
(datetime.datetime(2016, 9, 7, 20, 42, 18, 810563, tzinfo=<UTC>), 'test_data', None)
That tells me that for some reason the back-end is not setting the publishTime field in the message resource it is returning, but that the timestamp attribute set by the publishing application is being set. tseaver commented on Sep 7, 2016 It appears that the GAX/gRPC adapter for pubsub is not mediating between the publish_time field in the PublishedMessage proto and the expected publishTime field (as returned from the JSON-over-HTTP API).
MetadataMetadataapi: pubsubIssues related to the Pub/Sub API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|