nodece commented on code in PR #17455:
URL: https://github.com/apache/pulsar/pull/17455#discussion_r962587028
##########
site2/docs/client-libraries-go.md:
##########
@@ -538,37 +556,39 @@ func main() {
defer client.Close()
+ // we can listen this channel
channel := make(chan pulsar.ConsumerMessage, 100)
options := pulsar.ConsumerOptions{
Topic: "topic-1",
SubscriptionName: "my-subscription",
Type: pulsar.Shared,
+ // fill `MessageChannel` field will create a listener
+ MessageChannel: channel,
}
- options.MessageChannel = channel
-
consumer, err := client.Subscribe(options)
if err != nil {
log.Fatal(err)
}
defer consumer.Close()
- // Receive messages from channel. The channel returns a struct which
contains message and the consumer from where
+ // Receive messages from channel. The channel returns a struct
`ConsumerMessage` which contains message and the consumer from where
// the message was received. It's not necessary here since we have 1
single consumer, but the channel could be
// shared across multiple consumers as well
for cm := range channel {
+ consumer := cm.Consumer
msg := cm.Message
- fmt.Printf("Received message msgId: %v -- content: '%s'\n",
- msg.ID(), string(msg.Payload()))
+ fmt.Printf("Consumer %s received a message, msgId: %v, content:
'%s'\n",
+ consumer.Name(), msg.ID(), string(msg.Payload()))
consumer.Ack(msg)
}
}
```
-#### How to use consumer receive timeout
+#### Receive message with timeout
```go
client, err := NewClient(pulsar.ClientOptions{
Review Comment:
```suggestion
client, err := pulsar.NewClient(pulsar.ClientOptions{
```
--
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]