EAHITechnology opened a new issue #596:
URL: https://github.com/apache/pulsar-client-go/issues/596


   When we send a messge in the following way:
   
   ```
       producer.SendAsync(ctx, &pulsar.ProducerMessage{
           Key:             "xxxx",
        Value:          "xxxx",
        EventTime:  time.Now(),
           }, func(id pulsar.MessageID, message *pulsar.ProducerMessage, e 
error) {
                fmt.Println("id:", id, " message:", string(message.Payload), " 
err:", e)
       })
   ```
   
   We well print some duplicated MsgIds
   
   By the way, The Consumer also Receive the duplicated MsgIds!!!
   
   This problem can be solved if we add ##waitgroup## to the callback,like this:
   
   ```
       wg := &sync.WaitGroup{}
       for i := 0; i < 100; i++ {
           wg.Add(1)
        producer.SendAsync(ctx, &pulsar.ProducerMessage{
            Key:      "xxxx",
            Value:     "xxxx",
            EventTime: time.Now(),
        }, func(id pulsar.MessageID, message *pulsar.ProducerMessage, e error) {
                fmt.Println("id:", id, " message:", string(message.Payload), " 
err:", e)
                wg.Done()
         })
        if err != nil {
            fmt.Println("Send error:", err.Error())
            continue
        }
        wg.Wait()
       }
   ```


-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to