-
Notifications
You must be signed in to change notification settings - Fork 12k
Closed
Description
Within the same process, once a client is "Shutdown()", it is not able to create a same client again (same GroupName, NameServers, and InstanceName).
Demo code: minor modification upon official example "examples/consumer/simple/main.go":
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/apache/rocketmq-client-go/v2"
"github.com/apache/rocketmq-client-go/v2/consumer"
"github.com/apache/rocketmq-client-go/v2/primitive"
)
func sub(name string) {
c, _ := rocketmq.NewPushConsumer(
consumer.WithGroupName("testGroup"),
consumer.WithNameServer([]string{"127.0.0.1:9876"}),
consumer.WithInstance(name),
)
err := c.Subscribe("test", consumer.MessageSelector{}, func(ctx context.Context,
msgs ...*primitive.MessageExt) (consumer.ConsumeResult, error) {
for i := range msgs {
fmt.Printf("subscribe callback: %v \n", msgs[i])
}
return consumer.ConsumeSuccess, nil
})
if err != nil {
fmt.Println(err.Error())
}
// Note: start after subscribe
err = c.Start()
if err != nil {
fmt.Println(err.Error())
os.Exit(-1)
}
// Shutdown after 10s
time.Sleep(time.Second*10)
err = c.Shutdown()
if err != nil {
fmt.Printf("shutdown Consumer error: %s", err.Error())
}
}
func main() {
// this will run OK
sub("name1")
// this will fail
sub("name1")
}Reactions are currently unavailable