简体   繁体   中英

Google Cloud: Pubsub subscription filter expression options

I am trying to put filter in the GCP pubsub subscription. My requirement is to add number of codes in the filter. I am using terraform for that.

Here is something that I want to create:

filter = "attributes.code=(\"5426\",\"5427\",\"5428\",\"5429\",\"5430\")"

I checked the above will not work but the google docs have references to syntax something like:

filter = "attributes.code=\"5426\" OR attributes.code=\"5427\""

This one works, but there is a limit on the filter which is 256 bytes if I add all my codes like this then it is not going to work as it throws character limit error.

Is it possible to use RegEx in filter?

I can't do hit and trial as the code is in production so checking with the experts.

There's currently no support for regexes in Pub/Sub filters. You can follow updates on these filtering features on their public issue trackers:

In the meantime, could you potentially restructure your code formats to make use of thehasPrefix() function ? If you know in advance that you want to handle certain codes together in the same subscription, you could add common prefixes for them that you can later capture using hasPrefix() .

You can also try as below. It works for me good. It was less than 256 bytes in my case.

filter = <<EOT
attributes.code=\"5426\" OR attributes.code=\"5427\"
EOT

I used the same for mine like below and it worked well.

filter = <<EOT
attributes.IS_LATEST = "true" AND attributes.ITEM_LIFECYCLE_PHASE != "Preliminary" AND ( attributes.OBJECT_TYPE = "Part" OR attributes.ITEM_TYPE= "Product Specification"  ) AND attributes.REVISION_RELEASE_DATE != "0"
EOT

Hope it helps.

Thanks

MacOS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM