什么Azure的.NET SDK EventHubClient实例方法是线程安全的? [英] What Azure .NET SDK EventHubClient instance methods are threadsafe?

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

问题描述

我在写code将发布从多个线程的消息到的天青事件枢纽在C#中使用 EventHubClient 。对于EventHubClient文档包含了相当标准的锅炉板。

I'm writing code that will be publishing messages from multiple threads to an Azure Event Hub in C# using the EventHubClient. The documentation for EventHubClient contains the fairly standard boiler plate.

任何公共static(在Visual Basic中共享)此类型的成员
  线程安全的。任何实例成员不能保证是线程
  安全。

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

有作为线程安​​全中的任何<无附加文档href=\"http://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.messaging.eventhubclient.send.aspx\"相对=nofollow>的 <一个href=\"http://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.messaging.eventhubclient.sendasync.aspx\"相对=nofollow>四 <一个href=\"http://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.messaging.eventhubclient.sendbatch.aspx\"相对=nofollow>发送
<一href=\"http://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.messaging.eventhubclient.sendbatchasync.aspx\"相对=nofollow>方法我最希望是线程安全的。被我相信,发送方法不是线程安全的话,我将结束我每次想发送邮件时创建一个新的EventHubClient实例。由于底层TCP连接显然的重用,除非步骤,采取了这种可能不会有太多的开销。出现与<类似的问题href=\"http://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.messaging.eventhubsender.aspx\"相对=nofollow>分区发件人但因为有一个异步方法创建一个,他们也可能有自己的AMQP连接。

There is no additional documentation as to thread safety in any of the four send methods I would most expect to be thread safe. Were I to believe that the send methods are not threadsafe then I would end up creating a new EventHubClient instance each time I wished to send to a message. Since the underlying tcp connection is apparently reused unless steps are taken this may not have too much overhead. Similar issues arise with partitioned senders though given that there is an async method to create one, they might well have their own AMQP connection.

都是一些,如果不是全部,EventHubClient线程的实例方法,尽管文档安全吗?

Are some, if not all, instance methods of EventHubClient thread safe despite the documentation?

和任何人的Azure将有可能有这样的文件中澄清?这类问题的文件(假设是错误的,因为很可能)似乎 Azure Table中的影响,以及是在一般常见MSDN文档。至于EventHub这是对比的是卡夫卡和<一个明确的线程安全声明href=\"http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/kinesis/AmazonKinesisAsync.html\"相对=nofollow> AWS 室壁运动至少没有明确标注的一切不安全。我没有找到在SDK开源部分EventHubs所以可能不检查自己。

And for any Azure folks would it be possible to have this clarified in the documentation? This sort of documentation issue (assuming it is wrong as seems likely) appears to affect Azure Table as well and is generally common within the MSDN docs. With regards to EventHub this is in contrast to the clear thread safety statement of Kafka and AWS Kinesis at least does not explicitly label everything as unsafe. I did not find EventHubs in the open source portion of the SDK so could not check myself.

推荐答案

ServiceBus SDK提供了两个模式,以创建发件人:
1.基本
2.高级

ServiceBus SDK exposes two patterns to create senders: 1. Basic 2. Advanced

有关Basic版本 - 开发者将直接使用EventHubClient.CreateFromConnectionString(),不担心管理MessagingFactory(连接区的)。 SDK将处理重用MsgFactory所有EventHubClients只要连接字符串是一样的。

For Basic version - developer will directly use EventHubClient.CreateFromConnectionString() and doesn't worry about managing MessagingFactory (connection gu's). SDK will handle reusing MsgFactory across all EventHubClients as long as the connection string is same.

有关高级开发谁需要在连接级别更多的控制,SB SDK提供MessagingFactory.CreateFromConnectionString(),并从该创建EventHubClient实例。

For an Advanced developer who will need a bit more control at connection level, SB SDK provides MessagingFactory.CreateFromConnectionString() and from this create the EventHubClient instance.

的EventHubClient的实例方法无保证是的严格线程安全的(即使它们碰巧是今天)。但是,在一定水平,他们是!
如果,你正在做的就是发送(differentMessages)在多个线程 - 它是安全的假设,他们是线程安全的。
这样做的原因之中:实施绝对线程安全库将总是具有相当性能刑罚只来 - 我相信,这个被选择为跨越净默认模式

None of the instance methods of EventHubClient are guaranteed to be strictly thread safe (even though they happen to be today). But, to some level they are! If, all you are doing is just to Send(differentMessages) across multiple threads - it is safe to assume that they are thread safe. The reason for this being: implementing absolute thread-safe library will always come only with a considerable Performance penality - I believe that, this is chosen as a default pattern across .Net.

创建EventHubClient每次发送消息的新实例预期的格局。而ServiceBus SDK将重用底层MessagingFactory实现最佳性能的照顾。

Creating a new instance of EventHubClient each time to send message is the intended pattern. And the ServiceBus SDK will take care of reusing the underlying MessagingFactory for achieving optimal performance.

如果您正在寻找真正的高吞吐量的情景,那么你应该设计一个战略,以创建多个MessagingFactory对象,然后创建一个EventHubClient每个。但是 - 确保你已经增加了吞吐单位的门户网站的EventHub试图以此为默认之前仅仅是1 Mbps的 - 所有累计16个分区的

If you are looking for real high throughput scenarios then you should design a strategy to create multiple MessagingFactory objects and then Create an EventHubClient each. However - make sure that you have already increased the Thruput units for your EventHub on the Portal before trying this as the default is just 1 MBPS - cumulative of all 16 partitions.

此外,如果您正在使用的发送模式是分区发件人 - 他们都也将采用同样的底层MessagingFactory - (CreatePartitionedSender())如果从同一创建所有发件人的 eventHubClient 实例。

Also, if the Send pattern you are using is Partitioned Senders - they all will also use the same underlying MessagingFactory - if you create all Senders from the same eventHubClient(.CreatePartitionedSender()) instance.

心连心!
SREE

HTH! Sree

这篇关于什么Azure的.NET SDK EventHubClient实例方法是线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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