Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google PubSub ordering key issue, message ordering not enabled

I am facing an issue when publishing a google cloud pubsub message to a subscription with ordering enabled.

I have a pubsub topic : test_order_topic with a push subscription with Message ordering : Enabled (enableMessageOrdering: true).

But when publishing to this topic with a python Google Cloud function :

publisher.publish(
   'projects/project_id/topics/test_order_pubsub',
   json.dumps({ "index": len(WORDS) }).encode('utf-8'),
   ordering_key='key1'
)

I get the following error :

Cannot publish a message with an ordering key when message ordering is not enabled.

test_order_pubsub have no other subscription

Could you help with this issue? Thanks!

like image 674
Béranger Avatar asked Aug 20 '26 16:08

Béranger


1 Answers

When using the Cloud Pub/Sub client libraries to publish, it is necessary to enable ordering in the client library. This ensures that the client library queues messages in order properly. To do so, set the enable_message_ordering property in the PublisherOptions:

from google.cloud import pubsub_v1

publisher_client = pubsub_v1.PublisherClient(
    publisher_options = pubsub_v1.types.PublisherOptions(
        enable_message_ordering=True,
    )
)
like image 102
Kamal Aboul-Hosn Avatar answered Aug 23 '26 02:08

Kamal Aboul-Hosn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!