2022-07-10 19:11:37 +00:00
|
|
|
package broker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
2022-07-10 19:11:37 +00:00
|
|
|
)
|
|
|
|
|
2023-12-11 20:05:54 +00:00
|
|
|
func (b *MessageQueueBroker) FindBrokerLeader(c context.Context, request *mq_pb.FindBrokerLeaderRequest) (*mq_pb.FindBrokerLeaderResponse, error) {
|
2022-07-11 07:20:27 +00:00
|
|
|
ret := &mq_pb.FindBrokerLeaderResponse{}
|
2023-12-11 20:05:54 +00:00
|
|
|
err := b.withMasterClient(false, b.MasterClient.GetMaster(), func(client master_pb.SeaweedClient) error {
|
2022-07-11 07:20:27 +00:00
|
|
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
2023-06-20 01:19:13 +00:00
|
|
|
ClientType: cluster.BrokerType,
|
|
|
|
FilerGroup: request.FilerGroup,
|
2022-07-11 07:20:27 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(resp.ClusterNodes) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret.Broker = resp.ClusterNodes[0].Address
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return ret, err
|
|
|
|
}
|