2017-04-24 29 views
0

我想要的是無論何時(且僅當)在GCS上創建文件時,我的發佈/訂閱訂閱都會收到通知。GCS的發佈/訂閱通知 - 事件過濾器不起作用

所以我這樣做:

gsutil notification create -t projects/[my-project-id]/topics/new-raw-file -f none -m eventType:OBJECT_FINALIZE gs://[the-target-bucket] 

我覺得這個配置建立成功,因爲當我跑gsutil notification list,它表明:

projects/_/buckets/[the-target-bucket]/notificationConfigs/7 
Cloud Pub/Sub topic: projects/[my-project-id]/topics/new-raw-file 
Custom attributes: 
    eventType: OBJECT_FINALIZE 

這是唯一的配置。

然而,除了文件的創建等,我也收到文件刪除通知:

Received 1 messages. 
* 118758642722910: message - , attributes - {u'resource': u'projects/_/buckets/[the-target-bucket]/objects/2466870.3.txt#1493038968423735', u'objectId': u'2466870.3.txt', u'bucketId': u'[the-target-bucket]', u'notificationConfig': u'projects/_/buckets/[the-target-bucket]/notificationConfigs/7', u'payloadFormat': u'NONE', u'eventType': u'OBJECT_DELETE', u'objectGeneration': u'1493038968423735'} 

沒得到了什麼事錯了。

回答

1

原來我誤用了一個命令選項。根據this page,「-m」實際上只是將一個key:value屬性附加到通知中,它與我想要的事件過濾器無關。正確的選項應該是「-e」。所以,下面的配置命令實際上正常工作:enter code here

gsutil notification create -t [TOPIC_NAME] -f json -e OBJECT_FINALIZE gs://[BUCKET_NAME]