Reputation: 166
A question on the behaviour of Cloud Pub/Sub: Assuming I have a topic with message ordering, and a subscription handling message ordering. if I have more than one consumer for the subscription, is there a way to ensure the same consumer always gets the messages for the same ordering key? I’m basically trying to work out if similar parallelism behaviour as with Kafka topic partitions is possible, in order to be able to have stateful consumers handling all messages for some key.
Upvotes: 2
Views: 2213
Reputation: 530
According to https://medium.com/google-cloud/google-cloud-pub-sub-ordered-delivery-1e4181f60bc8, enable "Message ordering" on the subscription and set the OrderingKey
pubsub metadata tag when publishing messages will route messages to the same subscriber in sequence for the same OrderingKey
.
Affinity: If there are messages with an ordering key outstanding to a
streaming pull subscriber, then additional messages that are delivered
are sent to that same subscriber. If no messages are currently outstanding
for an ordering key, the service delivers messages to the last subscriber
to receive messages for that key on a best-effort basis.
Upvotes: 1