paladin-dalao commented on issue #50:
URL: 
https://github.com/apache/pulsar-client-cpp/issues/50#issuecomment-1284037673

   A new producer is created when each message is sent, and it is released 
after the message is sent, so that the adjustment of the partition will take 
effect, but the performance will not be very high in this way, right?
   
   code like this
   ```
   nt PulsarProducer::excuteProduce(const std::string &topic, const std::string 
&key, const string &data)
   {
       pulsar_producer_t *producer = newProducer(topic);
       if (producer == NULL)
       {
           return -1;
       }
       pulsar_result err = pulsar_client_create_producer(m_client, 
topic.c_str(), producer_conf, &producer);
       if (err != pulsar_result_Ok)
       {
           LOG_ERROR("Failed to create producer: %s\n", pulsar_result_str(err));
           pulsar_producer_configuration_free(producer_conf);
           return NULL;
       }
   
       PulsarProducerObject *ptrPulsarProducer = new PulsarProducerObject();
       ptrPulsarProducer->m_producer = producer;
       ptrPulsarProducer->m_producer_conf = producer_conf;
       
       pulsar_message_t *message = pulsar_message_create();
       pulsar_message_set_content(message, (const void *)data.c_str(), 
data.length());
       pulsar_message_set_property(message, "message_key", key.c_str());
       pulsar_producer_send_async(producer, message, 
PulsarProducer::handleSendCallback, (void *)ptrPulsarProducer);
   
       pulsar_message_free(message);
       return 0;
   }
        
   void PulsarProducer::handleSendCallback(pulsar_result result, 
pulsar_message_id_t *msgId, void *ctx)
   {
       if (msgId == NULL)
       {
           return;
       }
   
       char *msg = pulsar_message_id_str(msgId);
       ptrPulsarProducer *producer = (ptrPulsarProducer *)ctx;
       pulsar_producer_close(producer->m_producer);
       pulsar_producer_free(producer->m_producer);
       pulsar_producer_configuration_free(producer->m_producer_conf);
   
       pulsar_message_id_free(msgId);
       if (msg != NULL)
       {
           free(msg);
       }
   
   }
   
   ```


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to