You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by rx...@apache.org on 2020/06/11 12:28:42 UTC

[pulsar-client-go] branch master updated: Update reader example to README.md (#278)

This is an automated email from the ASF dual-hosted git repository.

rxl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a6c3e7  Update reader example to README.md (#278)
2a6c3e7 is described below

commit 2a6c3e70fe5f445714d47d9e4b404b8dae853ae4
Author: 冉小龙 <rx...@apache.org>
AuthorDate: Thu Jun 11 20:28:36 2020 +0800

    Update reader example to README.md (#278)
    
    Signed-off-by: xiaolong.ran <rx...@apache.org>
---
 README.md | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/README.md b/README.md
index acc96f1..17537eb 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,36 @@ fmt.Printf("Received message msgId: %#v -- content: '%s'\n",
 
 ```
 
+Create a Reader:
+
+```go
+client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"})
+if err != nil {
+	log.Fatal(err)
+}
+
+defer client.Close()
+
+reader, err := client.CreateReader(pulsar.ReaderOptions{
+	Topic:          "topic-1",
+	StartMessageID: pulsar.EarliestMessageID(),
+})
+if err != nil {
+	log.Fatal(err)
+}
+defer reader.Close()
+
+for reader.HasNext() {
+	msg, err := reader.Next(context.Background())
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	fmt.Printf("Received message msgId: %#v -- content: '%s'\n",
+		msg.ID(), string(msg.Payload()))
+}
+```
+
 ## Contributing
 
 Contributions are welcomed and greatly appreciated. See [CONTRIBUTING.md](CONTRIBUTING.md) for details on submitting patches and the contribution workflow.