Azure TopicClient线程安全吗? [英] Is Azure TopicClient threadsafe?

查看:61
本文介绍了Azure TopicClient线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been dealing with a spate of Timeout's from TopicClient and I think it may be related to object lifetime and disposal.

我正在使用Microsoft.ServiceBus.Messaging中的TopicClient类,并阅读此

I'm using the TopicClient class from Microsoft.ServiceBus.Messaging and reading this Best Practices Guide states

发送消息后,您不应关闭消息传递工厂或队列,主题和订阅客户端,然后在发送下一条消息时重新创建它们.关闭消息传递工厂将删除与服务总线服务的连接,并且在重新创建工厂时会建立新的连接.

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,但我认为它适用.也许这个假设是不正确的?

This is confusing to me - this document doesn't specifically refer to TopicClient but i am assuming it applies. Perhaps this assumption is incorrect?

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

Can I just store my TopicClient in a static member to avoid recreating the connection? Is there a better way to handle this? Is there some sort of connection pooling mechanism that I should use instead?

推荐答案

The documentation indicates that all static and instance members of the TopicClient are threadsafe.

"此类型的任何公共静态(在Visual Basic中为Shared)成员都是 线程安全.实例成员也保证是线程安全的."

"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.

I read the quote you included as that it does specifically include the TopicClient because it says "queue, topic and subscription clients". I read that as QueueClient, TopicClient and SubscriptionClient.

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

For messaging subsystems I tend to use a Gateway Pattern which can be used to handle the lifetime of the object necessary to work with the messaging subsystem. In your case the Gateway object would handle the lifetime of the TopicClient, or MessageSender/Receivers.

我想问一下您是否看到了更通用的 MessageReceiver 类?发送时使用这些更通用的对象意味着执行发送的客户端代码不必知道它是发送到主题还是队列,它只需发送到地址就可以了.

I would ask if you have seen the more generic MessageSender and MessageReceiver classes? Using these more generic objects when sending means the client code doing the sending doesn't have to know whether or not it is sending to a Topic or a Queue, it can just send to the address and not care.

这篇关于Azure TopicClient线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆