You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.9 KiB

5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
  1. package broker
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/cluster"
  4. "github.com/chrislusf/seaweedfs/weed/pb/mq_pb"
  5. "github.com/chrislusf/seaweedfs/weed/wdclient"
  6. "google.golang.org/grpc"
  7. "github.com/chrislusf/seaweedfs/weed/pb"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  9. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  10. )
  11. type MessageQueueBrokerOption struct {
  12. Masters map[string]pb.ServerAddress
  13. FilerGroup string
  14. DataCenter string
  15. Rack string
  16. Filers []pb.ServerAddress
  17. DefaultReplication string
  18. MaxMB int
  19. Ip string
  20. Port int
  21. Cipher bool
  22. }
  23. type MessageQueueBroker struct {
  24. mq_pb.UnimplementedSeaweedMessagingServer
  25. option *MessageQueueBrokerOption
  26. grpcDialOption grpc.DialOption
  27. MasterClient *wdclient.MasterClient
  28. }
  29. func NewMessageBroker(option *MessageQueueBrokerOption, grpcDialOption grpc.DialOption) (mqBroker *MessageQueueBroker, err error) {
  30. mqBroker = &MessageQueueBroker{
  31. option: option,
  32. grpcDialOption: grpcDialOption,
  33. MasterClient: wdclient.NewMasterClient(grpcDialOption, option.FilerGroup, cluster.BrokerType, pb.NewServerAddress(option.Ip, option.Port, 0), option.DataCenter, option.Rack, option.Masters),
  34. }
  35. mqBroker.checkFilers()
  36. go mqBroker.MasterClient.KeepConnectedToMaster()
  37. return mqBroker, nil
  38. }
  39. func (broker *MessageQueueBroker) withFilerClient(streamingMode bool, filer pb.ServerAddress, fn func(filer_pb.SeaweedFilerClient) error) error {
  40. return pb.WithFilerClient(streamingMode, filer, broker.grpcDialOption, fn)
  41. }
  42. func (broker *MessageQueueBroker) withMasterClient(streamingMode bool, master pb.ServerAddress, fn func(client master_pb.SeaweedClient) error) error {
  43. return pb.WithMasterClient(streamingMode, master, broker.grpcDialOption, func(client master_pb.SeaweedClient) error {
  44. return fn(client)
  45. })
  46. }