'Google Pubsub Subscription based on attributes or Message content

I am relatively new to GCP platform. I have a system which is publishing messages in pubsub topic. Messages has an attribute named country and based on this attribute different clients would like to subscribe to messages. Client X is interested only in messages for country a. Client Y is interested only in messages of country b.

Will I have to create topic for every country in google pub sub? or there is a smart way to have subscription on single topic based on attribute value

I am referring to attribute passed by publisher as stated in google docs. https://cloud.google.com/pubsub/docs/publisher

Thanks



Solution 1:[1]

If you want to be able to do subscription filtering - please upvote it on the Cloud Pub/Sub ideas forum! https://googlecloudplatform.uservoice.com/forums/302631-cloud-pub-sub

Solution 2:[2]

Answering my own question here -- The approach I went with was to define an event listener like this:

class CustomTestEventListener : public ::testing::EmptyTestEventListener {
    void OnTestEnd(const testing::TestInfo& testInfo) override {
        testing::Test::RecordProperty("key", testInfo.file());
    }
}

This listener will effectively add a section in the generated gtest xml like this:

<testcase>
    ...
    <properties>
        <property name="key" value=""/>
    </properties>
</testcase>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andy
Solution 2 qahoang