You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/03/13 08:46:18 UTC
[GitHub] [pulsar] archfish commented on issue #6535: [BUG]Msg duplicate when
consumer in Failover mode
archfish commented on issue #6535: [BUG]Msg duplicate when consumer in Failover mode
URL: https://github.com/apache/pulsar/issues/6535#issuecomment-598612987
```golang
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/apache/pulsar-client-go/pulsar"
)
func main() {
client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://my.pulsar.lan:6650"})
if err != nil {
log.Fatal(err)
}
defer client.Close()
consumer, err := client.Subscribe(pulsar.ConsumerOptions{
Topic: "shared",
SubscriptionName: "my-sub",
Type: pulsar.Failover,
})
if err != nil {
log.Fatal(err)
}
defer consumer.Close()
for i := 0; i < 10; i++ {
msg, err := consumer.Receive(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Received message msgId: %#v -- content: '%s'\n",
msg.ID(), string(msg.Payload()))
// consumer.Ack(msg)
time.Sleep(10 * time.Second)
}
if err := consumer.Unsubscribe(); err != nil {
log.Fatal(err)
}
}
```
```shell
# at least has one message in topic
go run examples/consumer/consumer.go
# after consumer started
go run examples/consumer/consumer.go
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services