servicecomb

package module
v2.0.0-...-a803e9d Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 10 Imported by: 7

README

Servicecomb Registry

example

server
package main

import (
	"log"

	"github.com/go-chassis/sc-client"
	"github.com/go-kratos/kratos/contrib/registry/servicecomb/v2"
	"github.com/go-kratos/kratos/v2"
)

func main() {
	c, err := sc.NewClient(sc.Options{
		Endpoints: []string{"127.0.0.1:30100"},
	})
	if err != nil {
		log.Panic(err)
	}
	r := servicecomb.NewRegistry(c)
	app := kratos.New(
		kratos.Name("helloServicecomb"),
		kratos.Registrar(r),
	)
	if err := app.Run(); err != nil {
		log.Fatal(err)
	}
}

client
package main

import (
	"context"
	"log"

	"github.com/go-chassis/sc-client"
	"github.com/go-kratos/kratos/contrib/registry/servicecomb/v2"
	"github.com/go-kratos/kratos/v2/transport/grpc"
)

func main() {
	c, err := sc.NewClient(sc.Options{
		Endpoints: []string{"127.0.0.1:30100"},
	})
	if err != nil {
		log.Panic(err)
	}
	r := servicecomb.NewRegistry(c)
	ctx := context.Background()
	conn, err := grpc.DialInsecure(
		ctx,
		grpc.WithEndpoint("discovery:///helloServicecomb"),
		grpc.WithDiscovery(r),
	)
	if err != nil {
		return
	}
	defer conn.Close()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

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

Registry is servicecomb registry.

func NewRegistry

func NewRegistry(client RegistryClient) *Registry

func (*Registry) Deregister

func (r *Registry) Deregister(_ context.Context, svcIns *registry.ServiceInstance) error

func (*Registry) GetService

func (r *Registry) GetService(_ context.Context, serviceName string) ([]*registry.ServiceInstance, error)

func (*Registry) Register

func (r *Registry) Register(_ context.Context, svcIns *registry.ServiceInstance) error

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, serviceName string) (registry.Watcher, error)

type RegistryClient

type RegistryClient interface {
	GetMicroServiceID(appID, microServiceName, version, env string, opts ...sc.CallOption) (string, error)
	FindMicroServiceInstances(consumerID, appID, microServiceName, versionRule string, opts ...sc.CallOption) ([]*discovery.MicroServiceInstance, error)
	RegisterService(microService *discovery.MicroService) (string, error)
	RegisterMicroServiceInstance(microServiceInstance *discovery.MicroServiceInstance) (string, error)
	Heartbeat(microServiceID, microServiceInstanceID string) (bool, error)
	UnregisterMicroServiceInstance(microServiceID, microServiceInstanceID string) (bool, error)
	WatchMicroService(microServiceID string, callback func(*sc.MicroServiceInstanceChangedEvent)) error
}

type Watcher

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

func (*Watcher) Next

func (w *Watcher) Next() ([]*registry.ServiceInstance, error)

func (*Watcher) Put

func (w *Watcher) Put(svcIns *registry.ServiceInstance)

Put only for UT

func (*Watcher) Stop

func (w *Watcher) Stop() error

Jump to

Keyboard shortcuts

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