Skip to content

client lib v2.0.0 (the pure go version), can't re-create client #1924

@liye-github

Description

@liye-github

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")
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions