According to documentation all non-static calls of EventHubClient are not thread-safe. This means that I cannot easily call the following function from wherever I want:
public async Task SendBatchAsync(IList<EventData> eventHubBatch)
{
try
{
await this.eventHubClient.SendBatchAsync(eventHubBatch);
}
catch (Exception ex)
{
Console.WriteLine("ERROR (EH WRITER): {0}", ex.Message);
}
}
Wonder what are the alternatives?
- Locking
- Sync thread context
- Save to some queue and have one threadpool-based async/await while loop which reads from a queue and posts further to EventHub
UPDATE: Eric from Event Hub team confirmed that it is safe to use SendAsync in multithreaded environment as is.
UPDATE 2: MSDN documentation just got updated (within 2 hours, wow!). Now it says: "Any public static or instance members of this type are thread safe.".