gpt4 book ai didi

azure - Azure TopicClient 线程安全吗?

转载 作者:行者123 更新时间:2023-12-04 06:20:55 24 4
gpt4 key购买 nike

我一直在处理来自 TopicClient 的大量超时,我认为这可能与对象的生存期和处置有关。

我正在使用 Microsoft.ServiceBus.Messaging 中的 TopicClient 类并阅读本文 Best Practices Guide

You should not close messaging factories or queue, topic, and subscription clients after you send a message, and then re-create them when you send the next message. Closing a messaging factory deletes the connection to the Service Bus service, and a new connection is established when recreating the factory.

这让我感到困惑 - 本文档并未具体提及 TopicClient 但我假设它适用。也许这个假设是不正确的?

我可以将 TopicClient 存储在静态成员中以避免重新创建连接吗?有更好的方法来处理这个问题吗?我应该使用某种连接池机制吗?

最佳答案

documentation indicates TopicClient 的所有静态成员和实例成员都是线程安全的。

"Any public static (Shared in Visual Basic) members of this type are thread safe. Instance members are also guaranteed to be thread safe."

我阅读了您引用的内容,因为它确实包含 TopicClient,因为它说“队列、主题和订阅客户端”。我将其理解为 QueueClient、TopicClient 和 SubscriptionClient。

对于消息传递子系统,我倾向于使用 Gateway Pattern它可用于处理与消息子系统一起工作所需的对象的生命周期。在您的情况下,网关对象将处理 TopicClient 或 MessageSender/Receivers 的生命周期。

我想问你是否见过更通用的 MessageSenderMessageReceiver类(class)?发送时使用这些更通用的对象意味着执行发送的客户端代码不必知道它是发送到主题还是队列,它可以只发送到地址而不关心。

关于azure - Azure TopicClient 线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15776256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com