How I get the sequence number from a ring ZenQ
Hello. I have more questions from this https://github.com/alphadose/ZenQ/issues/10. Assume I created three or more ZenQ 3 rings/instances and want to balance the size of ZenQ when the producer delivers a message by selecting the ring with the lowest sequence. Could you suggest to me how I can retrieve the length of a ring or the most recent sequence from ZenQ?
FYI. I'm new to LMAX Disruptor. Please excuse any misunderstanding.
you can get the sequence number from the writerIndex variable in the ZenQ struct https://github.com/alphadose/ZenQ/blob/main/zenq.go#L87
var sequenceNumber uint32 = ZenQ.writerIndex.Load()
I got it but this writerIndex variable didn't export to use in an external package. Could you provide a method to return this, maybe something like Length() or SequenceNumber()?
@aslupin I am a bit occupied currently, hence the patch with Length() function will take some time
In the meantime you can use
package main
import (
"fmt"
"reflect"
"strings"
"github.com/alphadose/zenq/v2"
)
type payload struct {
alpha int
beta string
}
func main() {
zq := zenq.New[payload](100)
for i := 0; i < 100; i++ {
zq.Write(payload{1, "2"})
}
k := strings.Split(fmt.Sprintf("%v", reflect.ValueOf(*zq).FieldByName("writerIndex")), " ")
fmt.Println(strings.Trim(k[len(k)-1], "}"))
}
output
100
@aslupin I have added Size() function in https://github.com/alphadose/ZenQ/releases/tag/v2.8.3
here is the commit https://github.com/alphadose/ZenQ/commit/43a1241a8670b32266ece6404f6c2b7785bc6b9e
Cool!, Thank you for your help