Replies: 3 comments
-
By default, pulsar producers batch their messages together before sending them to the broker. The sending of the messages occurs only after a certain threshold in terms of message count, total message size, or time has been reached. Since you are sending just one message, my guess is that none of these thresholds are met. Can you try wrapping the sendAsync command in a for loop as well? |
Beta Was this translation helpful? Give feedback.
-
Hey @paulm17 welcome to the community! Since sendAsync is asynchronous, your program might exit before the message has a chance to be sent. Before exiting the program, you might need to wait for the message to be sent. Using |
Beta Was this translation helpful? Give feedback.
-
To add on the previous responses. // 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 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() |
Beta Was this translation helpful? Give feedback.
-
hey all. New to pulsar.
I have the standalone version running on docker and now trying a basic pub/sub app in golang.
I’m able to use a sync publisher, but when I try an async pub. I don’t see any messages being sent, nor any response from the function (logging).
Can someone take a look at my code and let me know if I have missed anything out? I’ve taken a look at the producer_test.go from the go-client and can’t see anything.
https://github.com/apache/pulsar-client-go/blob/6d9cbd8ba3aa08b5285cceb0a4688dad57ae3171/pulsar/producer_test.go
Thanks
Beta Was this translation helpful? Give feedback.
All reactions