RagingKore commented on a change in pull request #71:
URL: https://github.com/apache/pulsar-dotpulsar/pull/71#discussion_r637382425
##########
File path: src/DotPulsar/PulsarClient.cs
##########
@@ -57,26 +58,84 @@ public sealed class PulsarClient : IPulsarClient
public static IPulsarClientBuilder Builder()
=> new PulsarClientBuilder();
+ public async Task<uint> GetNumberOfPartitions(string topic,
CancellationToken cancellationToken)
+ {
+ var connection = await
_connectionPool.FindConnectionForTopic(topic,
cancellationToken).ConfigureAwait(false);
+ var commandPartitionedMetadata = new
CommandPartitionedTopicMetadata() { Topic = topic };
+ var response = await connection.Send(commandPartitionedMetadata,
cancellationToken).ConfigureAwait(false);
+
+ response.Expect(BaseCommand.Type.PartitionedMetadataResponse);
+
+ if (response.PartitionMetadataResponse.Response ==
CommandPartitionedTopicMetadataResponse.LookupType.Failed)
+ response.PartitionMetadataResponse.Throw();
+
+ return response.PartitionMetadataResponse.Partitions;
+ }
+
/// <summary>
/// Create a producer.
/// </summary>
public IProducer<TMessage>
CreateProducer<TMessage>(ProducerOptions<TMessage> options)
{
ThrowIfDisposed();
+ var partitionsCount = GetNumberOfPartitions(options.Topic,
default).Result;
Review comment:
Yeah .Result is a problem. For this particular case we could use
GetAwaiter().GetResult() cause it raises exceptions and keeps the stack trace.
Still I would consider either delaying that initialization to when we
actually want to start to produce messages, or make the method truly async.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]