4141 $ gcloud beta pubsub subscriptions create testsubscription --topic=testtopic
4242
43436. Run this program:
44- $ python notification_polling my-project-id testsubscription
44+ $ python notification_polling.py my-project-id testsubscription
4545
46467. While the program is running, upload and delete some files in the testbucket
4747 bucket (you could use the console or gsutil) and watch as changes scroll by
@@ -64,6 +64,8 @@ def summarize(message):
6464 bucket_id = attributes ['bucketId' ]
6565 object_id = attributes ['objectId' ]
6666 generation = attributes ['objectGeneration' ]
67+ overwrote_generation = attributes ['overwroteGeneration' ]
68+ overwritten_by_generation = attributes ['overwrittenByGeneration' ]
6769 description = (
6870 '\t Event type: {event_type}\n '
6971 '\t Bucket ID: {bucket_id}\n '
@@ -74,6 +76,12 @@ def summarize(message):
7476 object_id = object_id ,
7577 generation = generation )
7678
79+ if overwrote_generation :
80+ description += '\t Overwrote generation: %s\n ' % overwrote_generation
81+ if overwritten_by_generation :
82+ description += '\t Overwritten by generation: %s\n ' % (
83+ overwritten_by_generation )
84+
7785 payload_format = attributes ['payloadFormat' ]
7886 if payload_format == 'JSON_API_V1' :
7987 object_metadata = json .loads (data )
@@ -99,7 +107,7 @@ def poll_notifications(project, subscription_name):
99107 project , subscription_name )
100108
101109 def callback (message ):
102- print ('Received message:\n {1 }' .format (summarize (message )))
110+ print ('Received message:\n {}' .format (summarize (message )))
103111 message .ack ()
104112
105113 subscriber .subscribe (subscription_path , callback = callback )
0 commit comments