'Single topic for multiple Publisher/Subscribers

Referring following article/posts for this question

https://cloud.google.com/pubsub/docs/filtering

Google Pubsub Subscription based on attributes or Message content

After going through above, I understand that message filtering is available in Pub/Sub. I have use case that I wanted to accomplish with Pub/Sub and wanted to know your views on that.

Following Microservices Saga pattern, I have different Microservices (Customer, Order etc) that needs to publish event to a topic, and similarly I have many different Microservices consuming these events. I am planning to use Google Pub/Sub for this use case.

So, in my application, I am planning to use a Pub/Sub topic that ALL the Microservices will use for publishing the events, and I can also attach multiple Subscriber to the same topic, and each subscriber can use "message filtering" feature to retrieve messages destined for respective subscriber (service). In that way, I will not have to create many Topics to handle this use case, and all Microservices can publish/subscriber to/from same Topic. I wanted to ask, if you see any drawback of this way to use Google Pub/Sub, or any better way to accomplish this use case?



Solution 1:[1]

It's a good pattern. The tricky part is to think smartly the attribute on the message because you can only filter on the message attribute. It's especially important because you can't change the filter after the subscription creation, and you have to delete it (and loose all the messages) and recreate it with the new filter. It's the only problem that you can have with that pattern.

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 guillaume blaquiere