简体   繁体   中英

GCP PubSub understanding filters

In my understanding PubSub filters are supposed to reduce number of messages sent to a specific subscription. We currently observe behaviour that we didn't expect.

Assuming there is a PubSub Topic "XYZ" and a subscription to that topic "XYZ-Sub" with a filter attributes.someHeader = "x" There are 2 messages published to that topic:

First one attributes.someHeader = "a". Second one with attributes.someHeader = "x"

I expect the only message 2 will be delivered to the subscription as message 1 does not match the filter. If it is not the case and still both messages get delivered (what we currently observe):

  • GCP console shows a rising number of unacked messages on a sub when no client is connected. Pulling this messages in the gcp console removes them without showing any received messages, which makes me assume that the filters are applied when pulling messages.
  • Are filters evaluated on PubSub client and not topic level?
  • What is the point in using filters with pub/sub?
  • Will the delivery of the unwanted message (the bytes of the message) be billed?

Filtering in Cloud Pub/Sub only delivers messages that match the filter to subscribers. The filters are applied in the Pub/Sub service itself, not in the client. They allow you to limit the set of messages delivered to subscribers when the subscriber only wants to process a subset of the messages.

In your example, only the message with attributes.someHeader = "x" should be delivered. However, note that as the documentation , the backlog metrics might include messages that don't match the filter. Such messages will not be delivered to subscribers, but may still show up in the backlog metrics for a time.

You do get charged the Pub/Sub message delivery price for messages that were not delivered. However, you do not pay any.network fees for them, nor do you end up paying for any compute to process messages you do not receive.

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