servicerouter

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: 19 Imported by: 1

README

Service routing

Canary function

  • Enable configure
selector:  # Configuration for trpc framework service discovery.
  polaris:  # Polaris service discovery configuration.
    enable_canary: true  # Enable the canary function, the default false is not enabled.
  • Use the demo
package main

import (
    "context"
    "time"

    "trpc.group/trpc-go/trpc-go/client"
    "trpc.group/trpc-go/trpc-go/log"
    "trpc.group/trpc-go/trpc-go/naming/registry"
    "trpc.group/trpc-go/trpc-naming-polarismesh/servicerouter"

    pb "trpc.group/trpcprotocol/test/helloworld"
)

func main() {
    ctx, cancel := context.WithTimeout(context.TODO(), time.Millisecond*2000)
    defer cancel()

    node := &registry.Node{}
    opts := []client.Option{
        client.WithServiceName("your service"),
        client.WithNamespace("Production"),
        client.WithSelectorNode(node),
        servicerouter.WithCanary("1"),
    }

    proxy := pb.NewGreeterClientProxy()

    req := &pb.HelloRequest{
        Msg: "trpc-go-client",
    }
    rsp, err := proxy.SayHello(ctx, req, opts...)
    log.Debugf("req:%s, rsp:%s, err:%v, node: %+v", req, rsp, err, node)
}

Documentation

Overview

Package servicerouter is a service router.

Index

Constants

This section is empty.

Variables

View Source
var CanaryKey string = "trpc-canary"

CanaryKey is the trpc canary key.

Functions

func Setup

func Setup(sdkCtx api.SDKContext, cfg *Config, setDefault bool) error

Setup is for setting up.

func WithCanary

func WithCanary(val string) client.Option

WithCanary sets canary metadata.

Types

type Config

type Config struct {
	// Name is the current name of plugin.
	Name string
	// Enable configures whether to enable the service routing function.
	Enable bool
	// EnableCanary configures whether to enable the canary function.
	EnableCanary bool
	// NeedReturnAllNodes expands all nodes into registry.Node and return.
	NeedReturnAllNodes bool
}

Config configuration.

type ServiceRouter

type ServiceRouter struct {
	RuleBased   servicerouter.ServiceRouter
	NearbyBased servicerouter.ServiceRouter
	FilterOnly  servicerouter.ServiceRouter
	DstMeta     servicerouter.ServiceRouter
	SetDivision servicerouter.ServiceRouter
	Canary      servicerouter.ServiceRouter
	// contains filtered or unexported fields
}

ServiceRouter is service routing.

func (*ServiceRouter) Filter

func (s *ServiceRouter) Filter(serviceName string,
	nodes []*registry.Node, opt ...tsr.Option) ([]*registry.Node, error)

Filter filters instances based on routing rules.

Jump to

Keyboard shortcuts

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