tjiuming commented on issue #15045:
URL: https://github.com/apache/pulsar/issues/15045#issuecomment-1090443210

   ```
   func main() {
   
           //end of read stream
           stop := 16
   
           // Instantiate a Pulsar client
           client, err := pulsar.NewClient(pulsar.ClientOptions{
                   URL: "pulsar://pulsar-broker.pulsar.svc.cluster.local:6650",
           })
   
           if err != nil {
                   log.Fatalf("Could not create client: %v", err)
           }
   
           // Use the client to instantiate a reader
           reader, err := client.CreateReader(pulsar.ReaderOptions{
                   Topic:          "ragnarok/transactions/requests",
                   StartMessageID: pulsar.EarliestMessage,
           })
   
           if err != nil {
                   log.Fatalf("Could not create reader: %v", err)
           }
   
           ctx := context.Background()
   
           // Listen on the topic for incoming messages
           cnt := 0
   
           for {
   
                   msg, err := reader.Next(ctx)
   
                   if err != nil {
                           log.Fatalf("Error reading from topic: %v", err)
                   } else {
                           cnt++
                           content := string(msg.Payload())
   
                           fmt.Println(cnt, " -> ", msg.ID(), " -> ", content)
   
                           if cnt == stop {
                                   fmt.Println("reached stream end. breaking 
out.")
                                   defer reader.Close()
                                   defer client.Close()
                                   break
                           }
   
                   }
           }
   }
   ```
   
   like this
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to