Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterRServer(s *grpc.Server, srv RServer)
- type Api
- type Discovery
- type Err
- type Handler
- type Http
- type IOption
- type MatchRequest
- func (*MatchRequest) Descriptor() ([]byte, []int)deprecated
- func (x *MatchRequest) GetGroup() string
- func (x *MatchRequest) GetKey() string
- func (*MatchRequest) ProtoMessage()
- func (x *MatchRequest) ProtoReflect() protoreflect.Message
- func (x *MatchRequest) Reset()
- func (x *MatchRequest) String() string
- type MatchResponse
- func (*MatchResponse) Descriptor() ([]byte, []int)deprecated
- func (x *MatchResponse) GetAddr() string
- func (x *MatchResponse) GetGroup() string
- func (x *MatchResponse) GetId() string
- func (*MatchResponse) ProtoMessage()
- func (x *MatchResponse) ProtoReflect() protoreflect.Message
- func (x *MatchResponse) Reset()
- func (x *MatchResponse) String() string
- type Member
- func (m *Member) GetTag(key string) (string, bool)
- func (m *Member) GetTags() map[string]string
- func (m *Member) IsSelf(b *Member) bool
- func (m *Member) Marshal() ([]byte, error)
- func (m *Member) SetTag(key string, val string)
- func (m *Member) SetTags(tags map[string]string)
- func (m *Member) Unmarshal(paylaod []byte) error
- type MembersRequest
- type MembersResponse
- type Option
- type RClient
- type RServer
- type Registry
- func (s *Registry) Close()
- func (s *Registry) Match(groupName string, key string) (*Service, error)
- func (s *Registry) Members(groupName string) []*Service
- func (s *Registry) OnMemberJoin(m *Member) error
- func (s *Registry) OnMemberLeave(m *Member) error
- func (s *Registry) OnMemberUpdate(m *Member) error
- func (s *Registry) Serve()
- type RpcServer
- type Serf
- type Service
- type UnimplementedRServer
Constants ¶
const ( // TagGroup is the tag key of the group name. TagGroup = "group" // TagAddr is the tag key of the service address. TagAddr = "addr" // TagReplicas is the tag key of replicas. TagReplicas = "replicas" )
const (
DefaultReplicas = "10000" // Default number of replicas to virtualize a service
)
Variables ¶
var ( ErrMemberIdEmpty = Err{Code: 10000, Msg: "id can't be empty"} ErrReplicasParam = Err{Code: 10000, Msg: "member replicas param error"} ErrGroupNameEmpty = Err{Code: 10001, Msg: "member group name empty"} ErrParseAddrToHostPort = Err{Code: 10002, Msg: "parse addr to host and port error"} ErrParsePort = Err{Code: 10003, Msg: "parse port error"} )
Pre-defined error instances with specific error codes and messages.
var File_rpcserver_proto protoreflect.FileDescriptor
Functions ¶
func RegisterRServer ¶
Types ¶
type Api ¶
type Api interface {
// Start the discovery server
// addr: the addr that discovery server listens to
Start(addr string) error
// Stop the discovery server
Stop()
}
Api is an api interface for service discovery
type Discovery ¶
type Discovery interface {
// SetHandler sets the event processing handler when new services are discovered.
SetHandler(Handler)
// Members returns the members of all services.
Members() []*Member
// LocalMember returns the current service.
LocalMember() *Member
// Start starts the discovery service.
Start() error
// Stop stops the discovery service.
Stop()
}
Auto-discover interface.
type Err ¶ added in v0.0.6
Err represents a custom error type with an error message and error code.
type Handler ¶
type Handler interface {
// OnMemberJoin is triggered when a new service is registered.
OnMemberJoin(*Member) error
// OnMemberLeave is triggered when a service leaves.
OnMemberLeave(*Member) error
// OnMemberUpdate is triggered when a service is updated.
OnMemberUpdate(*Member) error
}
Auto-discover event notification interface
type Http ¶
type Http struct {
// contains filtered or unexported fields
}
Http represents the http server object
type IOption ¶
type IOption func(o *Option)
IOption represents a function that modifies the Option.
func OptAdvertise ¶
OptAdvertise sets the advertised address for service discovery option.
func OptBindAdvertise ¶
OptBindAdvertise sets the advertised address for service registration option.
func OptRegistries ¶
OptRegistries sets the addresses of other registry servers option.
type MatchRequest ¶
type MatchRequest struct {
Group string `protobuf:"bytes,1,opt,name=group,proto3" json:"group,omitempty"`
Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
// contains filtered or unexported fields
}
func (*MatchRequest) Descriptor
deprecated
func (*MatchRequest) Descriptor() ([]byte, []int)
Deprecated: Use MatchRequest.ProtoReflect.Descriptor instead.
func (*MatchRequest) GetGroup ¶
func (x *MatchRequest) GetGroup() string
func (*MatchRequest) GetKey ¶
func (x *MatchRequest) GetKey() string
func (*MatchRequest) ProtoMessage ¶
func (*MatchRequest) ProtoMessage()
func (*MatchRequest) ProtoReflect ¶
func (x *MatchRequest) ProtoReflect() protoreflect.Message
func (*MatchRequest) Reset ¶
func (x *MatchRequest) Reset()
func (*MatchRequest) String ¶
func (x *MatchRequest) String() string
type MatchResponse ¶
type MatchResponse struct {
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Group string `protobuf:"bytes,2,opt,name=group,proto3" json:"group,omitempty"`
Addr string `protobuf:"bytes,3,opt,name=addr,proto3" json:"addr,omitempty"`
// contains filtered or unexported fields
}
func (*MatchResponse) Descriptor
deprecated
func (*MatchResponse) Descriptor() ([]byte, []int)
Deprecated: Use MatchResponse.ProtoReflect.Descriptor instead.
func (*MatchResponse) GetAddr ¶
func (x *MatchResponse) GetAddr() string
func (*MatchResponse) GetGroup ¶
func (x *MatchResponse) GetGroup() string
func (*MatchResponse) GetId ¶
func (x *MatchResponse) GetId() string
func (*MatchResponse) ProtoMessage ¶
func (*MatchResponse) ProtoMessage()
func (*MatchResponse) ProtoReflect ¶
func (x *MatchResponse) ProtoReflect() protoreflect.Message
func (*MatchResponse) Reset ¶
func (x *MatchResponse) Reset()
func (*MatchResponse) String ¶
func (x *MatchResponse) String() string
type Member ¶
type Member struct {
sync.Mutex
// The ID of the service.
Id string `json:"id"`
// The address used to register the service to the registry server.
Bind string `json:"bind"`
// The address that the service will advertise to the registry server.
Advertise string `json:"advertise"`
// The addresses of the registry servers. If there are more than one, separate them with commas, such as "192.168.1.101:7370,192.168.1.102:7370".
Registries string `json:"-"`
// The number of replicated elements of a service that need to be virtualized.
Replicas string `json:"replicas"`
// Service information.
Service Service `json:"service"`
// contains filtered or unexported fields
}
Member is used for auto-discovery. When a service is discovered, a Member object is created.
func NewMember ¶
func NewMember(id string, bind string, advertise string, registries string, group string, addr string) *Member
NewMember creates a new Member object with the given attributes.
func NewSimpleMember ¶
NewSimpleMember creates a simple Member object. It does not contain the address of the service.
func (*Member) GetTag ¶
GetTag retrieves the value associated with the given tag for this Member object.
func (*Member) IsSelf ¶
IsSelf returns true if the given Member object has the same ID as this Member object.
func (*Member) SetTag ¶
SetTag sets the extra information associated with the given tag for this Member object.
type MembersRequest ¶
type MembersRequest struct {
Group string `protobuf:"bytes,1,opt,name=group,proto3" json:"group,omitempty"`
// contains filtered or unexported fields
}
func (*MembersRequest) Descriptor
deprecated
func (*MembersRequest) Descriptor() ([]byte, []int)
Deprecated: Use MembersRequest.ProtoReflect.Descriptor instead.
func (*MembersRequest) GetGroup ¶
func (x *MembersRequest) GetGroup() string
func (*MembersRequest) ProtoMessage ¶
func (*MembersRequest) ProtoMessage()
func (*MembersRequest) ProtoReflect ¶
func (x *MembersRequest) ProtoReflect() protoreflect.Message
func (*MembersRequest) Reset ¶
func (x *MembersRequest) Reset()
func (*MembersRequest) String ¶
func (x *MembersRequest) String() string
type MembersResponse ¶
type MembersResponse struct {
Services []*MatchResponse `protobuf:"bytes,1,rep,name=services,proto3" json:"services,omitempty"`
// contains filtered or unexported fields
}
func (*MembersResponse) Descriptor
deprecated
func (*MembersResponse) Descriptor() ([]byte, []int)
Deprecated: Use MembersResponse.ProtoReflect.Descriptor instead.
func (*MembersResponse) GetServices ¶
func (x *MembersResponse) GetServices() []*MatchResponse
func (*MembersResponse) ProtoMessage ¶
func (*MembersResponse) ProtoMessage()
func (*MembersResponse) ProtoReflect ¶
func (x *MembersResponse) ProtoReflect() protoreflect.Message
func (*MembersResponse) Reset ¶
func (x *MembersResponse) Reset()
func (*MembersResponse) String ¶
func (x *MembersResponse) String() string
type Option ¶
type Option struct {
// Id is the service ID.
Id string
// Bind is the address used to register the service.
// If there is a firewall, ensure that the port is open for both TCP and UDP.
Bind string
// BindAdvertise is the address that the service will advertise to other services for registering.
// Can be used for basic NAT traversal where both the internal IP:port and external IP:port are known.
BindAdvertise string
// Registries are the addresses of other registry servers.
// If there are more than one, separate them with commas, such as "192.168.1.101:7370,192.168.1.102:7370".
Registries string
// Addr is the address used for service discovery.
Addr string
// Advertise is the address that will be advertised to clients for service discovery.
Advertise string
}
Option represents the options for registry server.
func DefaultOption ¶
func DefaultOption() *Option
DefaultOption returns the default options for registering a server.
type RClient ¶
type RClient interface {
Match(ctx context.Context, in *MatchRequest, opts ...grpc.CallOption) (*MatchResponse, error)
Members(ctx context.Context, in *MembersRequest, opts ...grpc.CallOption) (*MembersResponse, error)
}
RClient is the client API for R service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewRClient ¶
func NewRClient(cc grpc.ClientConnInterface) RClient
type RServer ¶
type RServer interface {
Match(context.Context, *MatchRequest) (*MatchResponse, error)
Members(context.Context, *MembersRequest) (*MembersResponse, error)
}
RServer is the server API for R service.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the registry server object
func (*Registry) OnMemberJoin ¶
OnMemberJoin is triggered when a new service is registered
func (*Registry) OnMemberLeave ¶
OnMemberLeave is triggered when a service leaves
func (*Registry) OnMemberUpdate ¶
OnMemberUpdate is triggered when a service is updated
type RpcServer ¶
type RpcServer struct {
// contains filtered or unexported fields
}
RpcServer is a gRPC server for service discovery
func (*RpcServer) Match ¶
func (s *RpcServer) Match(ctx context.Context, req *MatchRequest) (*MatchResponse, error)
Match assigns a service to a key using the consistent hashing algorithm
func (*RpcServer) Members ¶
func (s *RpcServer) Members(ctx context.Context, req *MembersRequest) (*MembersResponse, error)
Members returns a list of services in a group
type Serf ¶
type Serf struct {
// contains filtered or unexported fields
}
Serf represents a discovery instance of hashicorp/serf.
func (*Serf) Join ¶
Join joins the Serf agent to an existing Serf cluster with the specified members.
func (*Serf) LocalMember ¶
LocalMember returns the current registry service.
func (*Serf) SetHandler ¶
SetHandler sets the event processing handler when new services are discovered.
type Service ¶
type Service struct {
// The ID of the service.
Id string `json:"id"`
// The group name of this service.
Group string `json:"group"`
// The service address provided to the client.
Addr string `json:"addr"`
}
Service represents a service object.
type UnimplementedRServer ¶
type UnimplementedRServer struct {
}
UnimplementedRServer can be embedded to have forward compatible implementations.
func (*UnimplementedRServer) Match ¶
func (*UnimplementedRServer) Match(context.Context, *MatchRequest) (*MatchResponse, error)
func (*UnimplementedRServer) Members ¶
func (*UnimplementedRServer) Members(context.Context, *MembersRequest) (*MembersResponse, error)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2023 werbenhu SPDX-FileContributor: werbenhu
|
SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2023 werbenhu SPDX-FileContributor: werbenhu |
|
SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2023 werbenhu SPDX-FileContributor: werbenhu
|
SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2023 werbenhu SPDX-FileContributor: werbenhu |
|
examples
|
|
|
client
command
|
|
|
service
command
SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2023 werbenhu SPDX-FileContributor: werbenhu
|
SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2023 werbenhu SPDX-FileContributor: werbenhu |