We could use KubeMQ's "long polling" feature with a timeout (e.g., 60 seconds) in a for loop, kinda like it's done in Java with wait() to handle spurious wakeups.
So it'd be something like:
for {
res, err := client.NewReceiveQueueMessagesRequest().
SetChannel(channel).
SetMaxNumberOfMessages(1).
SetWaitTimeSeconds(60).
Send(ctx)
if err != nil {
log.Fatal(err)
}
if res != nil && res.MessagesReceived != 0 {
break
}
}
This is in fact what I've done, but:
But the name suggests that it's polling anyway, so not that great.
I cannot find any details regarding SetWaitTimeSeconds()'s implementation in the KubeMQ documentation.
I don't know whether the Go routine is actually being suspended or not, hence I don't know whether this is the optimal solution for our problem...
As I described in #4,
NewReceiveQueueMessagesRequest()
seems not to be blocking.In https://github.com/QMSTR/broker-test/issues/4#issuecomment-734369336 I said:
This is in fact what I've done, but:
I cannot find any details regarding
SetWaitTimeSeconds()
's implementation in the KubeMQ documentation. I don't know whether the Go routine is actually being suspended or not, hence I don't know whether this is the optimal solution for our problem...