Is Azure TopicClient threadsafe?

前端 未结 2 2488

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

I\'m using the TopicClient

相关标签:
2条回答
  • 2021-01-12 03:29

    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

    0 讨论(0)
  • 2021-01-12 03:41

    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.

    0 讨论(0)
提交回复
热议问题