Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to optimize throughput when sending to EventHubs with .Net core app

How can I create multiple EventHubClients that use multiple underlying TCP connects to allow fast writes to the EventHubs from a .net core web app?

In the programming guide for EventHubs (https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-programming-guide) it is written:

It is important to note that additional EventHubClient objects created from a messaging factory instance reuse the same underlying TCP connection. Therefore, these objects have a client-side limit on throughput. The Create method reuses a single messaging factory. If you need very high throughput from a single sender, then you can create multiple message factories and one EventHubClient object from each messaging factory.

And then they have a code sample:

var factory = MessagingFactory.CreateFromConnectionString("your_connection_string");
var client = factory.CreateEventHubClient("MyEventHub");

However, I dont know where / if there is a MessagingFactory in .Net core? Is it at all possible to do this from .Net core? I looked at Microsoft.Azure.ServiceBus but could not find any.

like image 566
viblo Avatar asked Nov 08 '22 13:11

viblo


1 Answers

After testing it seems like creating multiple clients with EventHubClient.CreateFromConnectionString will open multiple connections to EventHubs just as expected. (The connections can be seen as separate TCP connections in Windows Resource Monitor).

(When I reread the documentation carefully I think its only applies to EventHubClients created from a MessaginFactory, which was not clear the first time I read it. But I add this as an answer and let the question stay in case someone else reads the documentation like I did at first)

like image 88
viblo Avatar answered Nov 14 '22 21:11

viblo