client.go 754 Bytes
Newer Older
kzkzzzz's avatar
kzkzzzz committed
1 2 3 4 5 6 7
package client

import (
	"github.com/asim/go-micro/plugins/client/grpc/v4"
	"github.com/asim/go-micro/plugins/registry/consul/v4"
	"go-micro.dev/v4"
	"go-micro.dev/v4/registry"
8
	"gomicro-base/api/member"
kzkzzzz's avatar
kzkzzzz committed
9 10 11 12
	"gomicro-base/service/wallet/internal/conf"
)

var (
kzkzzzz's avatar
kzkzzzz committed
13 14
	cf        *conf.Config
	memberSvc member.MemberService
kzkzzzz's avatar
kzkzzzz committed
15 16 17 18
)

func NewMicroClient(c *conf.Config) {
	cf = c
kzkzzzz's avatar
kzkzzzz committed
19
	microRegistry := consul.NewRegistry(registry.Addrs(c.Server.ConsulAddr...))
kzkzzzz's avatar
kzkzzzz committed
20 21
	// 轮询访问

kzkzzzz's avatar
kzkzzzz committed
22
	microService := micro.NewService(
kzkzzzz's avatar
kzkzzzz committed
23
		micro.Client(grpc.NewClient()),
kzkzzzz's avatar
kzkzzzz committed
24
		micro.Registry(microRegistry),
kzkzzzz's avatar
kzkzzzz committed
25 26
		micro.WrapClient(NewTimeoutWrapper),
	)
kzkzzzz's avatar
kzkzzzz committed
27
	memberSvc = member.NewMemberService(conf.Conf.Client.Member, microService.Client())
kzkzzzz's avatar
kzkzzzz committed
28
}
29 30

func GetMemberSvc() member.MemberService {
kzkzzzz's avatar
kzkzzzz committed
31
	return memberSvc
32
}