package gd_crontab import ( "context" "fmt" "runtime" "time" "github.com/smallnest/rpcx/client" "github.com/smallnest/rpcx/protocol" "github.com/smallnest/rpcx/share" ) type GdCrontabXClient struct { xcli client.XClient } func (a *GdCrontabXClient) Init(etcdAddrs []string, basePath, servicePath string) { opt := client.Option{ Retries: 3, RPCPath: share.DefaultRPCPath, ConnectTimeout: 10 * time.Second, SerializeType: protocol.JSON, CompressType: protocol.None, BackupLatency: 10 * time.Millisecond, } if runtime.GOOS == "windows" { d := client.NewEtcdDiscovery(fmt.Sprintf("/%s", basePath), servicePath, etcdAddrs, nil) a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt) } else { d := client.NewEtcdDiscovery(basePath, servicePath, etcdAddrs, nil) a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt) } } // k8s模式下,服务发现方式需要改为点对点,使用k8s自身的Service进行服务发现,Service名称格式必须是abc-xyz的方式,不能使用"_" func (a *GdCrontabXClient) InitForK8s(servicePath string, k8sServiceName string, k8sServicePort string) { opt := client.Option{ Retries: 1, RPCPath: share.DefaultRPCPath, ConnectTimeout: 10 * time.Second, SerializeType: protocol.JSON, CompressType: protocol.None, BackupLatency: 10 * time.Millisecond, } sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", k8sServiceName, k8sServicePort), "") a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, sd, opt) } func (a *GdCrontabXClient) ReciveThirdPartLog(ctx context.Context, req *ReciveThirdPartLogReq) (reply ReciveThirdPartLogReply, err error) { err = a.xcli.Call(ctx, "ReciveThirdPartLog", req, &reply) return } func (a *GdCrontabXClient) ReciveAccessLog(ctx context.Context, req *ReciveAccessLogReq) (reply ReciveAccessLogReply, err error) { err = a.xcli.Call(ctx, "ReciveAccessLog", req, &reply) return }