2022-07-11 03:11:37 +08:00
|
|
|
package broker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-07-29 15:17:28 +08: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-11 03:11:37 +08:00
|
|
|
)
|
|
|
|
|
2023-12-12 04:05:54 +08:00
|
|
|
func (b *MessageQueueBroker) FindBrokerLeader(c context.Context, request *mq_pb.FindBrokerLeaderRequest) (*mq_pb.FindBrokerLeaderResponse, error) {
|
2022-07-11 15:20:27 +08:00
|
|
|
ret := &mq_pb.FindBrokerLeaderResponse{}
|
2023-12-12 04:05:54 +08:00
|
|
|
err := b.withMasterClient(false, b.MasterClient.GetMaster(), func(client master_pb.SeaweedClient) error {
|
2022-07-11 15:20:27 +08:00
|
|
|
resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
|
2023-06-20 09:19:13 +08:00
|
|
|
ClientType: cluster.BrokerType,
|
|
|
|
FilerGroup: request.FilerGroup,
|
2022-07-11 15:20:27 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(resp.ClusterNodes) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ret.Broker = resp.ClusterNodes[0].Address
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return ret, err
|
|
|
|
}
|