2020-04-18 19:44:55 +00:00
|
|
|
package client
|
|
|
|
|
2020-04-18 22:17:27 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/security"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
|
|
|
)
|
|
|
|
|
2020-04-18 19:44:55 +00:00
|
|
|
type MessagingClient struct {
|
|
|
|
bootstrapBrokers []string
|
2020-04-18 22:17:27 +00:00
|
|
|
grpcConnection *grpc.ClientConn
|
2020-04-18 19:44:55 +00:00
|
|
|
}
|
|
|
|
|
2020-04-18 22:17:27 +00:00
|
|
|
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-18 19:44:55 +00:00
|
|
|
return &MessagingClient{
|
|
|
|
bootstrapBrokers: bootstrapBrokers,
|
2020-04-18 22:17:27 +00:00
|
|
|
grpcConnection: grpcConnection,
|
|
|
|
}, nil
|
|
|
|
}
|