Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[golang] Fixed go client MessageQueues not filtering slave broker #852

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions golang/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import (
"google.golang.org/grpc/metadata"
)

const (
MASTER_BROKER_ID = 0
)

type Client interface {
GetClientID() string
Sign(ctx context.Context) context.Context
Expand Down Expand Up @@ -335,9 +339,16 @@ func (cli *defaultClient) getMessageQueues(ctx context.Context, topic string) ([
return nil, err
}

masterRoute := []*v2.MessageQueue{}
for _, messageQueue := range route {
if messageQueue.GetId() == MASTER_BROKER_ID {
masterRoute = append(masterRoute, messageQueue)
}
}

// telemeter to all messageQueues
endpointsSet := make(map[string]bool)
for _, messageQueue := range route {
for _, messageQueue := range masterRoute {
for _, address := range messageQueue.GetBroker().GetEndpoints().GetAddresses() {
target := utils.ParseAddress(address)
if _, ok := endpointsSet[target]; ok {
Expand All @@ -350,8 +361,8 @@ func (cli *defaultClient) getMessageQueues(ctx context.Context, topic string) ([
}
}

cli.router.Store(topic, route)
return route, nil
cli.router.Store(topic, masterRoute)
return masterRoute, nil
}

func (cli *defaultClient) queryRoute(ctx context.Context, topic string, duration time.Duration) ([]*v2.MessageQueue, error) {
Expand Down