Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Latest commit

 

History

History
128 lines (104 loc) · 3.74 KB

README.md

File metadata and controls

128 lines (104 loc) · 3.74 KB

registry-polaris (This is a community driven project)

Notice

This repository has been migrated to polaris and welcome to use.

Some application runtime use polaris for service discovery. 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.

How to install registry-polaris?

go get -u github.com/kitex-contrib/registry-polaris

How to use with Kitex server?

import (
        ...
   	"context"
   	"log"
   	"net"
   
   	"github.com/cloudwego/kitex/pkg/registry"
   	"github.com/polarismesh/polaris-go/pkg/config"
   	"github.com/cloudwego/kitex-examples/hello/kitex_gen/api"
   	"github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello"
   	"github.com/cloudwego/kitex/server"
   	polaris "github.com/kitex-contrib/registry-polaris"
        ...
)

const (
	confPath       = "polaris.yaml"
	Namespace      = "Polaris"
	// At present,polaris server tag is v1.4.0,can't support auto create namespace,
	// If you want to use a namespace other than default,Polaris ,before you register an instance,
	// you should create the namespace at polaris console first.
)

func main() {
    ...
	r, err := polaris.NewPolarisRegistry(confPath)
	if err != nil {
		log.Fatal(err)
	}
	Info := &registry.Info{
		ServiceName: "echo",
		Tags: map[string]string{
			"namespace": Namespace,
		},
	}
        // https://www.cloudwego.io/docs/kitex/tutorials/framework-exten/service_discovery/#usage-example
	newServer := hello.NewServer(new(HelloImpl), server.WithRegistry(r), server.WithRegistryInfo(Info),
		server.WithServiceAddr(&net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 8888}))

	err = newServer.Run()
	if err != nil {
		log.Fatal(err)
	}
	...
}

How to use with Kitex client?

import (
        ...
	"context"
	"log"
	"time"

	"github.com/cloudwego/kitex-examples/hello/kitex_gen/api"
	"github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello"
	"github.com/cloudwego/kitex/client"
	polaris "github.com/kitex-contrib/registry-polaris"
	"github.com/polarismesh/polaris-go/pkg/config"
        ...
)

const (
	confPath       = "polaris.yaml"
	Namespace      = "Polaris"
	// At present,polaris server tag is v1.4.0,can't support auto create namespace,
	// if you want to use a namespace other than default,Polaris ,before you register an instance,
	// you should create the namespace at polaris console first.
)

func main() {
    ...
	r, err := polaris.NewPolarisResolver(confPath)
	if err != nil {
		log.Fatal(err)
	}
        // https://www.cloudwego.io/docs/kitex/tutorials/framework-exten/service_discovery/#usage-example
	// client.WithTag sets the namespace tag for service discovery
	newClient := hello.MustNewClient("echo", client.WithTag("namespace", Namespace),
		client.WithResolver(r), client.WithRPCTimeout(time.Second*60))
	
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
	resp, err := newClient.Echo(ctx, &api.Request{Message: "Hi,polaris!"})
	cancel()
	if err != nil {
		log.Fatal(err)
	}
	log.Println(resp)
	...
	}
}

How to install polaris?

Polaris support stand-alone and cluster. More information can be found in install polaris

Todolist

Welcome to contribute your ideas

Use polaris with Kitex

See example and test

Compatibility

Compatible with polaris.

maintained by: liu-song