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.

34 lines
753 B

  1. package client
  2. import (
  3. "context"
  4. "google.golang.org/grpc"
  5. "github.com/chrislusf/seaweedfs/weed/pb"
  6. "github.com/chrislusf/seaweedfs/weed/security"
  7. "github.com/chrislusf/seaweedfs/weed/util"
  8. )
  9. type MessagingClient struct {
  10. bootstrapBrokers []string
  11. grpcConnection *grpc.ClientConn
  12. }
  13. func NewMessagingClient(bootstrapBrokers []string) (*MessagingClient, error) {
  14. grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.msg_client")
  15. grpcConnection, err := pb.GrpcDial(context.Background(), "localhost:17777", grpcDialOption)
  16. if err != nil {
  17. return nil, err
  18. }
  19. util.OnInterrupt(func() {
  20. grpcConnection.Close()
  21. })
  22. return &MessagingClient{
  23. bootstrapBrokers: bootstrapBrokers,
  24. grpcConnection: grpcConnection,
  25. }, nil
  26. }