RobertIndie commented on a change in pull request #71:
URL: https://github.com/apache/pulsar-dotpulsar/pull/71#discussion_r637383831



##########
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:
       Thanks for your suggestion. 
   Each time a Producer is created, the partitions count needs to be obtained 
first to determine whether it is a partitioned producer, so I think it is 
necessary to get the result of the partitions counts here.




-- 
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]


Reply via email to