We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reader.HasNext() should return true when messages are available.
Reader.HasNext()
true
Reader.HasNext() returns false when messages are available.
false
package main import ( "context" "fmt" "os" "github.com/apache/pulsar-client-go/pulsar" ) func main() { if err := Main(); err != nil { fmt.Fprintf(os.Stderr, "Error: %s\n", err) os.Exit(1) } os.Exit(0) } func Main() error { client, err := pulsar.NewClient(pulsar.ClientOptions{ URL: "pulsar://localhost:6650", }) if err != nil { return err } producer, err := client.CreateProducer(pulsar.ProducerOptions{ Topic: "persistent://public/test/test", }) if err != nil { return err } id, err := producer.Send(context.Background(), &pulsar.ProducerMessage{Payload: []byte("test")}) if err != nil { return err } consumer, err := client.CreateReader(pulsar.ReaderOptions{ Topic: "persistent://public/test/test", StartMessageID: id, StartMessageIDInclusive: true, }) hasnext := consumer.HasNext() fmt.Printf("HasNext: %v\n", hasnext) next, err := consumer.Next(context.Background()) if err != nil { return err } fmt.Printf("Next: %+v\n", next) return nil }
INFO[0000] Connecting to broker remote_addr="pulsar://localhost:6650" INFO[0000] TCP connection established local_addr="127.0.0.1:33626" remote_addr="pulsar://localhost:6650" INFO[0000] Connection is ready local_addr="127.0.0.1:33626" remote_addr="pulsar://localhost:6650" INFO[0000] Created producer cnx="127.0.0.1:33626 -> 127.0.0.1:6650" producer_name=standalone-0-130 topic="persistent://public/test/test" INFO[0000] Connected consumer name= subscription=reader-knfbf topic="persistent://public/test/test" INFO[0000] Created consumer name= subscription=reader-knfbf topic="persistent://public/test/test" HasNext: false Next: &{publishTime:{wall:195000000 ext:63724497913 loc:0xc19de0} eventTime:{wall:128448384 ext:55340232221 loc:0xc19de0} key: payLoad:[116 101 115 116] msgID:0xc000172000 properties:map[] topic:persistent://public/test/test replicationClusters:[] redeliveryCount:0}
Pulsar version: 2.5.1
The text was updated successfully, but these errors were encountered:
You can try to use the following code example:
consumer, err := client.CreateReader(pulsar.ReaderOptions{ Topic: "persistent://public/default/test", StartMessageID: pulsar.EarliestMessageID(), StartMessageIDInclusive: true, })
More use reference to here
Sorry, something went wrong.
The issue will be fixed in #329
No branches or pull requests
Expected behavior
Reader.HasNext()
should returntrue
when messages are available.Actual behavior
Reader.HasNext()
returnsfalse
when messages are available.Steps to reproduce
System configuration
Pulsar version: 2.5.1
The text was updated successfully, but these errors were encountered: