seaweedfs/weed/messaging/client/client.go

35 lines
753 B
Go
Raw Normal View History

package client
import (
"context"
"google.golang.org/grpc"
"github.com/chrislusf/seaweedfs/weed/pb"
"github.com/chrislusf/seaweedfs/weed/security"
"github.com/chrislusf/seaweedfs/weed/util"
)
type MessagingClient struct {
bootstrapBrokers []string
grpcConnection *grpc.ClientConn
}
func NewMessagingClient(bootstrapBrokers []string) (*MessagingClient, error) {
grpcDialOption := security.LoadClientTLS(util.GetViper(), "grpc.msg_client")
grpcConnection, err := pb.GrpcDial(context.Background(), "localhost:17777", grpcDialOption)
if err != nil {
return nil, err
}
2020-04-19 10:03:40 +00:00
util.OnInterrupt(func() {
grpcConnection.Close()
})
return &MessagingClient{
bootstrapBrokers: bootstrapBrokers,
grpcConnection: grpcConnection,
}, nil
}