mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 18:57:44 +08:00
feat: improve polaris register and upgrade polaris-go version v1.3.0 (#2524)
This commit is contained in:
parent
967a39ecbe
commit
b32eb30212
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.0.0
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.3
|
||||
github.com/polarismesh/polaris-go v1.3.0
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
@ -229,6 +229,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.3 h1:sqN50VGign37xVFp9nrN1RoLXacsB0QfRYUtuCWMJGI=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.3/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI=
|
||||
github.com/polarismesh/polaris-go v1.3.0 h1:KZKX//ow4OPPoS5+s7h07ptprg+2AcNVGrN6WakC9QM=
|
||||
github.com/polarismesh/polaris-go v1.3.0/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
|
@ -10,11 +10,12 @@ package polaris
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/config"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -46,16 +47,19 @@ type options struct {
|
||||
// To show service is healthy or not. Default value is True.
|
||||
Healthy bool
|
||||
|
||||
// Heartbeat enable .Not in polaris . Default value is True.
|
||||
// Deprecated: Use RegisterInstance instead.
|
||||
// Service registration is performed synchronously,
|
||||
// and heartbeat reporting is automatically performed
|
||||
// Heartbeat enable .Not in polaris. Default value is True.
|
||||
Heartbeat bool
|
||||
|
||||
// To show service is isolate or not. Default value is False.
|
||||
Isolate bool
|
||||
|
||||
// TTL timeout. if node needs to use heartbeat to report,required. If not set,server will throw ErrorCode-400141
|
||||
// TTL timeout. if the node needs to use a heartbeat to report, required. If not set,server will throw ErrorCode-400141
|
||||
TTL int
|
||||
|
||||
// optional, Timeout for single query. Default value is global config
|
||||
// Timeout for the single query. Default value is global config
|
||||
// Total is (1+RetryCount) * Timeout
|
||||
Timeout time.Duration
|
||||
|
||||
@ -123,6 +127,7 @@ func WithRetryCount(retryCount int) Option {
|
||||
}
|
||||
|
||||
// WithHeartbeat with the Heartbeat option.
|
||||
// Deprecated remove in v2.4.0
|
||||
func WithHeartbeat(heartbeat bool) Option {
|
||||
return func(o *options) { o.Heartbeat = heartbeat }
|
||||
}
|
||||
|
@ -10,16 +10,17 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/model"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/model"
|
||||
)
|
||||
|
||||
// Register the registration.
|
||||
func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Service, error) {
|
||||
// Replace input service to custom service type.
|
||||
// Replace input service to custom service types.
|
||||
service = &Service{
|
||||
Service: service,
|
||||
}
|
||||
@ -47,8 +48,9 @@ func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Ser
|
||||
rmd[k] = v
|
||||
}
|
||||
}
|
||||
// Register
|
||||
registeredService, err := r.provider.Register(
|
||||
// Register RegisterInstance Service registration is performed synchronously,
|
||||
// and heartbeat reporting is automatically performed
|
||||
registeredService, err := r.provider.RegisterInstance(
|
||||
&polaris.InstanceRegisterRequest{
|
||||
InstanceRegisterRequest: model.InstanceRegisterRequest{
|
||||
Service: service.GetPrefix(),
|
||||
@ -72,7 +74,7 @@ func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Ser
|
||||
return nil, err
|
||||
}
|
||||
if r.opt.Heartbeat {
|
||||
r.doHeartBeat(ctx, registeredService.InstanceID, service, endpoint)
|
||||
// r.doHeartBeat(ctx, registeredService.InstanceID, service, endpoint)
|
||||
}
|
||||
ids = append(ids, registeredService.InstanceID)
|
||||
}
|
||||
@ -83,7 +85,7 @@ func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Ser
|
||||
|
||||
// Deregister the registration.
|
||||
func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error {
|
||||
r.c <- struct{}{}
|
||||
// r.c <- struct{}{}
|
||||
var (
|
||||
err error
|
||||
split = gstr.Split(service.(*Service).ID, instanceIDSeparator)
|
||||
@ -111,6 +113,7 @@ func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deprecated .
|
||||
func (r *Registry) doHeartBeat(ctx context.Context, instanceID string, service gsvc.Service, endpoint gsvc.Endpoint) {
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second * time.Duration(r.opt.TTL))
|
||||
|
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package polaris
|
||||
|
||||
import (
|
||||
|
@ -18,7 +18,7 @@ require (
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/nacos-group/nacos-sdk-go v1.1.2
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.3
|
||||
github.com/polarismesh/polaris-go v1.3.0
|
||||
google.golang.org/grpc v1.49.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
k8s.io/client-go v0.25.2
|
||||
|
@ -442,8 +442,9 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.3 h1:sqN50VGign37xVFp9nrN1RoLXacsB0QfRYUtuCWMJGI=
|
||||
github.com/polarismesh/polaris-go v1.2.0-beta.3/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI=
|
||||
github.com/polarismesh/polaris-go v1.3.0 h1:KZKX//ow4OPPoS5+s7h07ptprg+2AcNVGrN6WakC9QM=
|
||||
github.com/polarismesh/polaris-go v1.3.0/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
||||
|
Loading…
Reference in New Issue
Block a user