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/06/08 23:53:33 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-857267988


   > > > 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.
   > 
   > Sorry for the late reply. @hunter2046 Regarding all the options in NewDefaultRouter, we expose them in the form of parameters. You can set these options in producerOptions, and NewDefaultRouter is also the specific value obtained from these options.
   
   Thanks. I understand that those options including MessageRouter are in producerOptions. My use case (as mentioned in https://github.com/apache/pulsar-client-go/pull/507#issuecomment-822802546) is that I need to set the MessageRouter in a customized way that is close to what the internalRouter does except using a different number of partitions to avoid causing producers to send messages to a different paritition when the number of partitions is being increased.
   
   In order to do that, I need to initialize the internalRouter by my own by calling `NewDefaultRouter`. To call `NewDefaultRouter`, I could supply my own hashing function for sure. However, because I want to mimic what the internalRouter does, I would like using the same hashing function. That is why I want to see if `getHashingFunction` can be exposed so I could achieve the above thing. Hope that this makes sense.


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