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 2020/06/29 05:51:11 UTC

[GitHub] [pulsar] ElationAndElation commented on issue #7375: An option in Pulsar functions to define routing for output messages to partitions

ElationAndElation commented on issue #7375:
URL: https://github.com/apache/pulsar/issues/7375#issuecomment-650924130


   > @ElationAndElation
   > 
   > You can use `Context.newOutputMessage()` to specify the topic (partition) to produce messages to. Does it meet your requirements?
   
   In pulsar producer has hashing schema, using these schema pulsar topic partition are chosen for a particular message. Please refer below code. Lets say ptest has 4 partitions and hashing as Murmur3_32Hash, then total 5 messages are sent, for each message partition is chosen based on Hashing Scheme murmur. There is no need exclusive logic written by here to chose partition. 
   Whereas for functions in Context.newOutputMessage(), we have to write a exclusive logic to chose a partition or topic. So, looking for the feature as in producer. 
   
    PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
               Producer producer = client.newProducer()
                       .hashingScheme(HashingScheme.Murmur3_32Hash)
                       .topic("ptest")
                       .create();
               for (int i = 1; i <= 5; i++) {
                   String key = "key-1"+System.currentTimeMillis();
                   if( i%2 == 0)
                       key = "key-2"+System.currentTimeMillis();
                   
                   try {
                       MessageId message = producer.send(key);
                       
                   } catch (PulsarClientException e ) {
                       e.printStackTrace();
                   }
               }
               producer.close();
               client.close();
   


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