registry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0, BSD-3-Clause, MIT Imports: 15 Imported by: 0

README

Service Registry Plugin

How to use

import _ "trpc.group/trpc-go/trpc-naming-polarismesh/registry"

A complete Configuration

plugins:  # tRPC-Go plugin configuration.
  registry:  # Registry has its own plugin type.
    polarismesh:  # This Registry is based on polaris mesh.
      register_self: true  # Whether to register, default as false.
      heartbeat_interval: 3000  # The interval to report heartbeat, must be provided.
      debug: true  # Whether to enable the debug log of polaris mesh sdk, default as false.
      instance_location:  # The location of the registered instance.
        region: China
        zone: Guangdong
        campus: Shenzhen
      service:
        - name:  trpc.test.helloworld.Greeter1  # The name of service.
          namespace: namespace-test1  # The namespace of your service.
          token: xxxxxxxxxxxxxxxxxxxx  # Token is optional for service registration.
          # (Optional) Used to heartbeat or unregister.
          # When register_self is true, this config has no effect, the plugin will use returned instance_id of register to overwrite config.
          # if register_self is false, instance_id cannot be missing.
          instance_id: yyyyyyyyyyyyyyyy
          bind_address: eth1:8080  # Specify the listening address of the service.
          weight: 100  # Default weight is 100.
          metadata:  # Custom metadata when registering.
            # Enable set (both this line and the next line need to be set to fully enable set).
            internal-enable-set: Y
            internal-set-name: xx.yy.sz  # Set service set name.
            key1: val1  # For other metadata, etc., please refer to polaris mesh related documents.
            key2: val2

Documentation

Overview

Package registry is for service registry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterService

type ClusterService struct {
	Discover    string `yaml:"discover"`
	HealthCheck string `yaml:"health_check"`
	Monitor     string `yaml:"monitor"`
}

ClusterService is cluster service.

type Config

type Config struct {
	// ServiceToken Service Access Token.
	ServiceToken string
	// Protocol Server access method, support http grpc, default grpc.
	Protocol string
	// HeartBeat Reporting heartbeat time interval, the default is recommended as TTL/2.
	HeartBeat int
	// EnableRegister By default, only report heartbeat, do not register service, if true, start registration.
	EnableRegister bool
	// Weight.
	Weight *int
	// TTL Unit s, the cycle for the server to check whether the periodic instance is healthy.
	TTL int
	// InstanceID instance name.
	InstanceID string
	// Namespace namespace.
	Namespace string
	// ServiceName Service Name.
	ServiceName string
	// BindAddress specifies reporting address.
	BindAddress string
	// Metadata User-defined metadata information.
	Metadata map[string]string
	// DisableHealthCheck disables healthcheck.
	DisableHealthCheck bool
	// InstanceLocation is the geographic location of the instance.
	InstanceLocation *model.Location
}

Config is registry configuration.

type FactoryConfig

type FactoryConfig struct {
	EnableRegister     bool            `yaml:"register_self"`
	Protocol           string          `yaml:"protocol"`
	HeartbeatInterval  int             `yaml:"heartbeat_interval"`
	Services           []Service       `yaml:"service"`
	Debug              bool            `yaml:"debug"`
	AddressList        string          `yaml:"address_list"`
	ClusterService     ClusterService  `yaml:"cluster_service"`
	ConnectTimeout     int             `yaml:"connect_timeout"`
	MessageTimeout     *time.Duration  `yaml:"message_timeout"`
	DisableHealthCheck bool            `yaml:"disable_health_check"`
	InstanceLocation   *model.Location `yaml:"instance_location"`
}

FactoryConfig is factory configuration.

type Registry

type Registry struct {
	// Provider: public for user custom.
	Provider api.ProviderAPI
	// contains filtered or unexported fields
}

Registry is service registration.

func NewRegistry

func NewRegistry(provider api.ProviderAPI, cfg *Config) (*Registry, error)

NewRegistry provides an externally accessible new instance interface.

func (*Registry) Deregister

func (r *Registry) Deregister(_ string) error

Deregister anti-registration.

func (*Registry) Register

func (r *Registry) Register(_ string, opt ...registry.Option) error

Register is for registration service.

type RegistryFactory

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

RegistryFactory is registered factory.

func (*RegistryFactory) FlexDependsOn

func (f *RegistryFactory) FlexDependsOn() []string

FlexDependsOn makes sure that register is initialized after selector, which may set some global status of SDK, such as log directories.

func (*RegistryFactory) GetSDKCtx

func (f *RegistryFactory) GetSDKCtx() api.SDKContext

GetSDKCtx returns the stored sdk context.

func (*RegistryFactory) Setup

func (f *RegistryFactory) Setup(name string, configDec plugin.Decoder) error

Setup starts loading configuration and registers log.

func (*RegistryFactory) Type

func (f *RegistryFactory) Type() string

Type returns registration type.

type Service

type Service struct {
	Namespace   string            `yaml:"namespace"`
	ServiceName string            `yaml:"name"`
	Token       string            `yaml:"token"`
	InstanceID  string            `yaml:"instance_id"`
	Weight      *int              `yaml:"weight"`
	BindAddress string            `yaml:"bind_address"`
	MetaData    map[string]string `yaml:"metadata"`
}

Service is service configuration.

Jump to

Keyboard shortcuts

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