Is Azure TopicClient threadsafe?

亡梦爱人 提交于 2019-12-05 04:20:30

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

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

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.

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.

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.

Just to add another confirmation from MS that this is thread safe, from Best Practices for performance improvements using Service Bus Messaging:

You can safely use the QueueClient object for sending messages from concurrent asynchronous operations and multiple threads.

They don't mention TopicClient explicitly, but would expect the same goes for TopicClient as for QueueClient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!