polaris

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

polaris

Warning: Watch has not yet been implemented. If you want to use it please consider implementing it.

Polaris is a cloud-native service discovery and governance center. It can be used to solve the problem of service connection, fault tolerance, traffic control and secure in distributed and microservice architecture.

https://github.com/polarismesh/polaris

this plugin just use its registry and dicovery in future maybe support more features,eg: Selector plugin for polaris's weight and priority

usage

  1. Do not support ListServices
  2. in polaris_test, will do depoly this version: polaris-standalone-release_v1.11.3.linux.amd64.zip
  3. according my test, it it necessary to call "time.Sleep(time.Second * x)" after call Register or Deregister, then the "GetService" return correct data
import sr "github.com/go-micro/plugins/v4/selector/registry"

func main() {
	poRegUrl := "127.0.0.1:8091"
	poRegNamespace := "default"
	poServiceToken := "nu/0WRA4EqSR1FagrjRj0fZwPXuGlMpX+zCuWu4uMqy8xr1vRjisSbA25aAC3mtU8MeeRsKhQiDAynUR09I="

	poReg := polaris.NewRegistry(
		registry.Addrs(poRegUrl),
			registry.Timeout(time.Second*5),
			// Can use Polaris's loadbalancer by Polairs web console
			polaris.GetOneInstance(true),
			polaris.NameSpace(poRegNamespace),
			polaris.ServerToken(poServiceToken),
		)

	// If polaris.GetOneInstance(true), its better to set sr.TTL(0)
	sel := sr.NewSelector(selector.Registry(poReg), sr.TTL(0))

	srv := micro.NewService()
	// Cmd will overwrite some option
	srv.Init()
	// Init twice
	srv.Init(
		micro.Registry(poReg),
		micro.Selector(sel),
		micro.RegisterInterval(time.Second*5),
		micro.RegisterTTL(time.Second*10),
	)
	// ...
}

Documentation

Overview

Package polaris provides an etcd service registry https://github.com/polarismesh/polaris

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultTimeout is the default registry timeout.
	DefaultTimeout = time.Second * 5

	// ErrNoNodes is returned when the lenth of the node slice is zero.
	ErrNoNodes = errors.New("no nodes provided")
	// ErrNoMetadata is returned when metadata failed to fetch.
	ErrNoMetadata = errors.New("fail to GetMetadata")
)

Functions

func Auth

func Auth(username, password string) registry.Option

Auth allows you to specify username/password. just no effect.

func GetOneInstance

func GetOneInstance(flag bool) registry.Option

GetOneInstance will fetch only one instance for use with Polaris's loadbalancer and disable cache by: github.com/go-micro/plugins/v4/selector/registry, option TTF(0).

func NameSpace

func NameSpace(namespace string) registry.Option

NameSpace sets the namespace.

func NewRegistry

func NewRegistry(opts ...registry.Option) registry.Registry

NewRegistry creates a new Polaris registry.

func ServerToken

func ServerToken(token string) registry.Option

ServerToken sets the server token.

Types

This section is empty.

Jump to

Keyboard shortcuts

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