【问题标题】:Google PubSub ordering key issue, message ordering not enabledGoogle PubSub 排序密钥问题,未启用消息排序
【发布时间】:2021-12-05 15:12:11
【问题描述】:

我在将 google cloud pubsub 消息发布到启用排序的订阅时遇到问题。

我有一个 pubsub 主题:test_order_topic,带有消息排序的推送订阅:已启用 (enableMessageOrdering: true)。

但是当使用 python Google Cloud 函数发布到这个主题时:

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

我收到以下错误:

当未启用消息排序时,无法发布带有排序键的消息。

test_order_pubsub没有其他订阅

您能帮忙解决这个问题吗?谢谢!

【问题讨论】:

    标签: google-cloud-platform google-cloud-functions google-cloud-pubsub


    【解决方案1】:

    使用 Cloud Pub/Sub 客户端库发布时,需要在客户端库中启用排序功能。这可确保客户端库正确地按顺序排列消息。为此,请在PublisherOptions 中设置enable_message_ordering 属性:

    from google.cloud import pubsub_v1
    
    publisher_client = pubsub_v1.PublisherClient(
        publisher_options = pubsub_v1.types.PublisherOptions(
            enable_message_ordering=True,
        )
    )
    

    【讨论】:

    • 非常感谢!我应该得到一个 RTFM :D 谢谢!
    猜你喜欢
    • 2021-10-29
    • 1970-01-01
    • 2012-10-06
    • 2015-12-21
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    相关资源
    最近更新 更多