You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/04/19 21:37:34 UTC

[GitHub] [pulsar-client-go] hunter2046 commented on pull request #507: Expose GetHashingFunction() method on producer

hunter2046 commented on pull request #507:
URL: https://github.com/apache/pulsar-client-go/pull/507#issuecomment-822802546


   > The point is wrong, can MessageRouter not meet our functions?
   > 
   > e.g:
   > 
   > ```
   > 	producer, err := client.CreateProducer(ProducerOptions{
   > 		Topic: "my-partitioned-topic",
   > 		MessageRouter: func(msg *ProducerMessage, tm TopicMetadata) int {
   > 			fmt.Println("Routing message ", msg, " -- Partitions: ", tm.NumPartitions())
   > 			return 2
   > 		},
   > 	})
   > ```
   
   Thanks for taking a look. MessageRouter is what we need. We'd like to set the MessageRouter to a function that works similar to the defaultRouter with a customized number of partitions, e.g.
   
   ```
   	internalRouter := pulsarClient.NewDefaultRouter(
   		getHashingFunction(producerOptions.HashingScheme),
   		producerOptions.BatchingMaxMessages,
   		producerOptions.BatchingMaxSize,
   		producerOptions.BatchingMaxPublishDelay,
   		producerOptions.DisableBatching)
   	messageRouter := func(message *pulsarClient.ProducerMessage, metadata pulsarClient.TopicMetadata) int {
                    // customNumberOfPartitions could be different from metadata.NumPartitions() here
   		return internalRouter(message, customNumberOfPartitions)
   	}
   ```
   
   The problem is that `getHashingFunction` is not exposed so we can't use it to feed the `NewDefaultRouter` method.


-- 
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:
users@infra.apache.org