1

I would like to confront my understanding of google pubSub/lite vs RabbitMQ (using MQTT over WSS).

My use case is that I need something like a topic exchange. To send messages individually or to all or to some.

Having RabbitMQ I understand that I can create a topic have multiple queues linked via routingKey. E.g. amqTopic.routingKey1-10. And I can push a message to a specific queue e.g. like this amqTopic.routingKey8 or push to the entire topic(all queues routed) like this amqTopic.*

Is it possible to create topic exchange structure with Google PubSub and if so how? I am not sure if I miss something. But from what I read I am inclined to say no, because google works like a direct exchange.

Thank you for helping..

petr
  • 27
  • 1
  • 4

1 Answers1

1

This kind of topic exchange structure is possible to re-create using Cloud Pub/Sub filters. You can attach attributes to your messages when they are published (e.g. "routingKey": "8" or "routingKey": "all") and configure filters on your subscriptions to receive only messages meant for a particular routing key (attributes.routingKey="8" OR attributes.routingKey="all" in this scenario).

It's not currently possible to create this kind of topic exchange structure in Pub/Sub Lite.

Lauren
  • 844
  • 4
  • 8
  • Thank you for your reply. One more question comes to my mind. Say I have a Topic T and Subscriptions 1-5. When publishing a message I am able to publish to each Subscription individually or to all at once. What I am struggling with is publishing the message to a dynamic selection. E.g. Subscription 1,3,5.. or next time Subscription 1,2. Is it possible to do this dynamically (e.g. when sending the message and putting its attributes defining the key as regex expression)? – petr May 17 '22 at 14:42
  • 2
    If you want to publish a message to multiple specific subscriptions, you could try a different approach with attributes by putting the key in the attribute key. For example, a message destined to subscription 1 could have the attribute `"routingKey1": "true"` (the value of the attribute doesn't matter, as we're just checking for the existence of the key). Then subscription 1 could filter on `attributes:routingKey1 OR attributes:routingKeyAll`. A message destined to subscriptions 1, 3, and 5 would need the attributes `"routingKey1": "true", "routingKey3": "true", "routingKey5": "true"`. – Lauren May 17 '22 at 14:58
  • 1
    Thank you Lauren... I was experimenting with hasPrefix() trying to reach above described, but for me it worked only when I wanted to send to all, or 1. Your approach does 100 % what I was looking for - sending to all or 1 or some. – petr May 18 '22 at 11:38