GitHub user merlimat added a comment to the discussion: Golang Client: Async 
producer does not send messages

To add on the previous responses. `SendAsync()` will take a callback function 
that will be invoked when the send operation is completed, so you can track it.

```go
        // SendAsync a message in asynchronous mode
        // This call is blocked when the `maxPendingMessages` becomes full 
(default: 1000)
        // The callback will report back the message being published and
        // the eventual error in publishing
        SendAsync(context.Context, *ProducerMessage, func(MessageID, 
*ProducerMessage, error))
```

Additionally, if you want to just send a bunch of messages and then wait for 
completion, you can use `Flush()`:

```go

for i := 0; i < 100; i++ {
    producer.SendAsync(context.Background(), &pulsar.ProducerMessage{
                        Payload: []byte(fmt.Sprintf("hello-%d", i)),
        }, nil)
}

// Wait for all messages to be published
err := producer.Flush()
```

GitHub link: 
https://github.com/apache/pulsar/discussions/22224#discussioncomment-8723397

----
This is an automatically sent email for commits@pulsar.apache.org.
To unsubscribe, please send an email to: commits-unsubscr...@pulsar.apache.org

Reply via email to