nacos

package
v2.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

* Copyright 1999-2020 Alibaba Group Holding Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var NewNamingClient = clients.NewNamingClient

Functions

func CloseNamingClient

func CloseNamingClient()

func InitialiseNacosNamingClient

func InitialiseNacosNamingClient()

func NewGrpc

func NewGrpc(data ...map[string]interface{})

func NewGrpcClientConn

func NewGrpcClientConn(config NacosConfig, lb string, dialOptions ...grpc.DialOption) *grpc.ClientConn

func NewRRGrpcClientConn

func NewRRGrpcClientConn(config NacosConfig, dialOptions ...grpc.DialOption) *grpc.ClientConn

func NewRest

func NewRest(data ...map[string]interface{})

func NewWRRGrpcClientConn

func NewWRRGrpcClientConn(config NacosConfig, dialOptions ...grpc.DialOption) *grpc.ClientConn

func ShutdownGrpc

func ShutdownGrpc()

func ShutdownRest

func ShutdownRest()

Types

type INacosServiceProvider

type INacosServiceProvider interface {
	SetClusters(clusters []string)
	SetGroupName(groupName string)
	SetNamingClient(namingClient naming_client.INamingClient)
}

type INamingClient

type INamingClient interface {

	// RegisterInstance use to register instance
	// Ip  require
	// Port  require
	// Weight  require,it must be lager than 0
	// Enable  require,the instance can be access or not
	// Healthy  require,the instance is health or not
	// Metadata  optional
	// ClusterName  optional,default:DEFAULT
	// ServiceName require
	// GroupName optional,default:DEFAULT_GROUP
	// Ephemeral optional
	RegisterInstance(param vo.RegisterInstanceParam) (bool, error)

	// DeregisterInstance use to deregister instance
	// Ip required
	// Port required
	// Tenant optional
	// Cluster optional,default:DEFAULT
	// ServiceName  require
	// GroupName  optional,default:DEFAULT_GROUP
	// Ephemeral optional
	DeregisterInstance(param vo.DeregisterInstanceParam) (bool, error)

	// UpdateInstance use to update instance
	// Ip  require
	// Port  require
	// Weight  require,it must be lager than 0
	// Enable  require,the instance can be access or not
	// Healthy  require,the instance is health or not
	// Metadata  optional
	// ClusterName  optional,default:DEFAULT
	// ServiceName require
	// GroupName optional,default:DEFAULT_GROUP
	// Ephemeral optional
	UpdateInstance(param vo.UpdateInstanceParam) (bool, error)

	// GetService use to get service
	// ServiceName require
	// Clusters optional,default:DEFAULT
	// GroupName optional,default:DEFAULT_GROUP
	GetService(param vo.GetServiceParam) (model.Service, error)

	// SelectAllInstances return all instances,include healthy=false,enable=false,weight<=0
	// ServiceName require
	// Clusters optional,default:DEFAULT
	// GroupName optional,default:DEFAULT_GROUP
	SelectAllInstances(param vo.SelectAllInstancesParam) ([]model.Instance, error)

	// SelectInstances only return the instances of healthy=${HealthyOnly},enable=true and weight>0
	// ServiceName require
	// Clusters optional,default:DEFAULT
	// GroupName optional,default:DEFAULT_GROUP
	// HealthyOnly optional
	SelectInstances(param vo.SelectInstancesParam) ([]model.Instance, error)

	// SelectOneHealthyInstance return one instance by WRR strategy for load balance
	// And the instance should be health=true,enable=true and weight>0
	// ServiceName require
	// Clusters optional,default:DEFAULT
	// GroupName optional,default:DEFAULT_GROUP
	SelectOneHealthyInstance(param vo.SelectOneHealthInstanceParam) (*model.Instance, error)

	// Subscribe use to subscribe service change event
	// ServiceName require
	// Clusters optional,default:DEFAULT
	// GroupName optional,default:DEFAULT_GROUP
	// SubscribeCallback require
	Subscribe(param *vo.SubscribeParam) error

	// Unsubscribe use to unsubscribe service change event
	// ServiceName require
	// Clusters optional,default:DEFAULT
	// GroupName optional,default:DEFAULT_GROUP
	// SubscribeCallback require
	Unsubscribe(param *vo.SubscribeParam) error

	// GetAllServicesInfo use to get all service info by page
	GetAllServicesInfo(param vo.GetAllServiceInfoParam) (model.ServiceList, error)

	//CloseClient close the GRPC client
	CloseClient()
}

INamingClient interface for naming client

type NacosConfig

type NacosConfig struct {
	ServiceName string
	Clusters    []string
	GroupName   string
}

type NacosProviderOption

type NacosProviderOption func(INacosServiceProvider)

func WithNacosClusters

func WithNacosClusters(clusters []string) NacosProviderOption

func WithNacosGroupName

func WithNacosGroupName(groupName string) NacosProviderOption

func WithNacosNamingClient

func WithNacosNamingClient(namingClient naming_client.INamingClient) NacosProviderOption

type RRServiceProvider

type RRServiceProvider struct {
	// contains filtered or unexported fields
}

RRServiceProvider is a simple round-robin load balance implementation for IServiceProvider

func NewRRServiceProvider

func NewRRServiceProvider(serviceName string, opts ...NacosProviderOption) *RRServiceProvider

NewRRServiceProvider creates new ServiceProvider instance

func (*RRServiceProvider) Close added in v2.0.6

func (n *RRServiceProvider) Close()

func (*RRServiceProvider) SelectServer

func (n *RRServiceProvider) SelectServer() string

SelectServer return service address from environment variable

func (*RRServiceProvider) SetClusters

func (b *RRServiceProvider) SetClusters(clusters []string)

func (*RRServiceProvider) SetGroupName

func (b *RRServiceProvider) SetGroupName(groupName string)

func (*RRServiceProvider) SetNamingClient

func (b *RRServiceProvider) SetNamingClient(namingClient naming_client.INamingClient)

type WRRServiceProvider

type WRRServiceProvider struct {
	// contains filtered or unexported fields
}

WRRServiceProvider is a WRR load balance implementation for IServiceProvider

func NewWRRServiceProvider

func NewWRRServiceProvider(serviceName string, opts ...NacosProviderOption) *WRRServiceProvider

NewWRRServiceProvider creates new ServiceProvider instance

func (*WRRServiceProvider) Close added in v2.0.6

func (n *WRRServiceProvider) Close()

func (*WRRServiceProvider) SelectServer

func (n *WRRServiceProvider) SelectServer() string

SelectServer return service address from environment variable

func (*WRRServiceProvider) SetClusters

func (b *WRRServiceProvider) SetClusters(clusters []string)

func (*WRRServiceProvider) SetGroupName

func (b *WRRServiceProvider) SetGroupName(groupName string)

func (*WRRServiceProvider) SetNamingClient

func (b *WRRServiceProvider) SetNamingClient(namingClient naming_client.INamingClient)

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL