2020-04-18 08:12:01 +00:00
|
|
|
package broker
|
2020-03-04 08:39:47 +00:00
|
|
|
|
|
|
|
import (
|
2022-07-02 06:34:51 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/cluster"
|
2022-07-02 05:43:25 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/mq_pb"
|
2022-07-02 06:34:51 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/wdclient"
|
2020-03-04 08:39:47 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
|
|
|
|
)
|
|
|
|
|
2022-07-02 05:44:28 +00:00
|
|
|
type MessageQueueBrokerOption struct {
|
2022-07-02 06:34:51 +00:00
|
|
|
Masters map[string]pb.ServerAddress
|
|
|
|
FilerGroup string
|
2022-07-03 07:29:25 +00:00
|
|
|
DataCenter string
|
|
|
|
Rack string
|
2021-09-13 05:47:52 +00:00
|
|
|
Filers []pb.ServerAddress
|
2020-03-04 08:39:47 +00:00
|
|
|
DefaultReplication string
|
|
|
|
MaxMB int
|
2020-05-05 09:05:28 +00:00
|
|
|
Ip string
|
2020-03-04 08:39:47 +00:00
|
|
|
Port int
|
2020-04-17 09:29:00 +00:00
|
|
|
Cipher bool
|
2020-03-04 08:39:47 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 05:44:28 +00:00
|
|
|
type MessageQueueBroker struct {
|
2022-07-02 05:43:25 +00:00
|
|
|
mq_pb.UnimplementedSeaweedMessagingServer
|
2022-07-02 05:44:28 +00:00
|
|
|
option *MessageQueueBrokerOption
|
2020-03-04 08:39:47 +00:00
|
|
|
grpcDialOption grpc.DialOption
|
2022-07-02 06:34:51 +00:00
|
|
|
MasterClient *wdclient.MasterClient
|
2020-03-04 08:39:47 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 06:34:51 +00:00
|
|
|
func NewMessageBroker(option *MessageQueueBrokerOption, grpcDialOption grpc.DialOption) (mqBroker *MessageQueueBroker, err error) {
|
2020-03-04 08:39:47 +00:00
|
|
|
|
2022-07-02 06:34:51 +00:00
|
|
|
mqBroker = &MessageQueueBroker{
|
2020-03-04 08:39:47 +00:00
|
|
|
option: option,
|
2020-04-17 09:29:00 +00:00
|
|
|
grpcDialOption: grpcDialOption,
|
2022-07-03 07:55:37 +00:00
|
|
|
MasterClient: wdclient.NewMasterClient(grpcDialOption, option.FilerGroup, cluster.BrokerType, pb.NewServerAddress(option.Ip, option.Port, 0), option.DataCenter, option.Rack, option.Masters),
|
2020-03-04 08:39:47 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 06:34:51 +00:00
|
|
|
mqBroker.checkFilers()
|
2020-04-18 22:17:27 +00:00
|
|
|
|
2022-07-02 06:34:51 +00:00
|
|
|
go mqBroker.MasterClient.KeepConnectedToMaster()
|
2020-03-04 08:39:47 +00:00
|
|
|
|
2022-07-02 06:34:51 +00:00
|
|
|
return mqBroker, nil
|
2020-03-04 08:39:47 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 05:44:28 +00:00
|
|
|
func (broker *MessageQueueBroker) withFilerClient(streamingMode bool, filer pb.ServerAddress, fn func(filer_pb.SeaweedFilerClient) error) error {
|
2020-03-04 08:39:47 +00:00
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
return pb.WithFilerClient(streamingMode, filer, broker.grpcDialOption, fn)
|
2020-03-04 08:39:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-07-02 05:44:28 +00:00
|
|
|
func (broker *MessageQueueBroker) withMasterClient(streamingMode bool, master pb.ServerAddress, fn func(client master_pb.SeaweedClient) error) error {
|
2020-03-04 08:39:47 +00:00
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
return pb.WithMasterClient(streamingMode, master, broker.grpcDialOption, func(client master_pb.SeaweedClient) error {
|
2020-03-04 08:39:47 +00:00
|
|
|
return fn(client)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|