-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace "0" with random Partition key (#7178) #14406
Conversation
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @soo-toance. Thank you very much for your contribution. I left one minor suggestion, but the changes look good to me, overall. If you don't mind addressing the one open comment, I'd be happy to merge this in.
try | ||
{ | ||
var partitions = await GetPartitionsAsync(ehClient); | ||
var partitionId = partitions[new Random().Next(partitions.Length)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend hoisting the Random
instance here to a class-level member. While this is the only place that it is used at the moment, an ephemeral Random
could be easy to overlook and isn't typically a good pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello : ) thanks for the suggestion! i'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @soo-toance! The change looks good to me, I'll go ahead and merge things in. Thank you, again, for your contribution and helping to improve the Azure SDKs .
Fixes #7178 |
before
var ehClient = EventHubClient.CreateFromConnectionString(connectionString);
var partitionSender = ehClient.CreatePartitionSender("0");
after:
var partitions = await this.GetPartitionsAsync(ehClient);
var partitionId = partitions[new Random().Next(partitions.Length)];
var partitionSender = ehClient.CreatePartitionSender(partitionId);