nakamapluskit

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionQueueFull = errors.New("session outgoing queue full")

Functions

func NewService

func NewService(ctx context.Context, logger *zap.Logger, serverNode, serverRole string, md *rtapi.NakamaPeer_NodeMeta, option *grpcpool.Options) runtime.PeerService

Types

type BroadcastOption added in v1.0.3

type BroadcastOption func(m *rtapi.NakamaPeer_Envelope)

func WithBroadcastContext added in v1.0.3

func WithBroadcastContext(md map[string]string) BroadcastOption

func WithBroadcastRecipient added in v1.0.3

func WithBroadcastRecipient(users ...string) BroadcastOption

type Configuration

type Configuration struct {
	Name string               `yaml:"name" json:"name" usage:"服务名称"`
	Role string               `yaml:"role" json:"role" usage:"服务角色"`
	Grpc *GrpcConfiguration   `yaml:"grpc" json:"grpc" usage:"grpc设置"`
	Etcd *etcd.Clientv3Config `yaml:"etcd" json:"etcd" usage:"etcd设置"`
}

func NewConfiguration

func NewConfiguration(name, role string) *Configuration

func (*Configuration) Check

func (c *Configuration) Check(log *zap.Logger) error

type GrpcConfiguration

type GrpcConfiguration struct {
	Addr                         string `yaml:"addr" json:"addr" usage:"服务监听地址"`
	Port                         int    `yaml:"port" json:"port" usage:"服务监听端口, 默认为0."`
	MinPort                      int    `yaml:"min-port" json:"minPort" usage:"当端口为0时,将使用最小端口和最大端口进行随机"`
	MaxPort                      int    `yaml:"max-port" json:"maxPort" usage:"当端口为0时,将使用最小端口和最大端口进行随机"`
	Domain                       string `yaml:"domain" json:"domain" usage:"本机服务地址"`
	GrpcX509Pem                  string `yaml:"grpc_x509_pem" json:"grpc_x509_pem" usage:"ssl pem"`
	GrpcX509Key                  string `yaml:"grpc_x509_key" json:"grpc_x509_key" usage:"ssl key"`
	GrpcToken                    string `yaml:"grpc_token" json:"grpc_token" usage:"token"`
	GrpcPoolMaxIdle              int    `yaml:"grpc_pool_max_idle" json:"grpc_pool_max_idle" usage:"Maximum number of idle connections in the grpc pool"`
	GrpcPoolMaxActive            int    `` /* 137-byte string literal not displayed */
	GrpcPoolMaxConcurrentStreams int    `` /* 221-byte string literal not displayed */
	GrpcPoolReuse                bool   `` /* 218-byte string literal not displayed */
	GrpcPoolMessageQueueSize     int    `yaml:"grpc_pool_message_queue_size" json:"grpc_pool_message_queue_size" usage:"grpc message queue size"`
}

func NewGrpcConfiguration

func NewGrpcConfiguration() *GrpcConfiguration

func (*GrpcConfiguration) Check

func (c *GrpcConfiguration) Check(logger *zap.Logger)

type Handler

type Handler interface {
	Call(ctx context.Context, in *rtapi.NakamaPeer_Envelope) (*rtapi.NakamaPeer_Envelope, error)
	NotifyMsg(session Session, in *rtapi.NakamaPeer_Envelope)
}

type LocalSession

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

func (*LocalSession) Broadcast added in v1.0.3

func (s *LocalSession) Broadcast(m []byte, opts ...BroadcastOption) error

Broadcast 广播消息会发向nakama, 后续消息要怎么处理需要在nakama组件中去监听和实现

func (*LocalSession) Close

func (s *LocalSession) Close()

func (*LocalSession) Consume

func (s *LocalSession) Consume()

func (*LocalSession) Context

func (s *LocalSession) Context() context.Context

func (*LocalSession) ID

func (s *LocalSession) ID() string

func (*LocalSession) Notification added in v1.0.3

func (s *LocalSession) Notification(ns []*api.Notification, opts ...BroadcastOption) error

Notification 通知消息将直接发向用户

func (*LocalSession) Role

func (s *LocalSession) Role() string

func (*LocalSession) Send deprecated

Deprecated: Use Notification or Broadcast

type MapOf

type MapOf[K comparable, V any] struct {
	// contains filtered or unexported fields
}

MapOf is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.

The MapOf type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content.

The MapOf type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a MapOf may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.

The zero MapOf is empty and ready for use. A MapOf must not be copied after first use.

func (*MapOf[K, V]) Delete

func (m *MapOf[K, V]) Delete(key K)

Delete deletes the value for a key.

func (*MapOf[K, V]) Load

func (m *MapOf[K, V]) Load(key K) (value V, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*MapOf[K, V]) LoadAndDelete

func (m *MapOf[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*MapOf[K, V]) LoadOrStore

func (m *MapOf[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*MapOf[K, V]) Range

func (m *MapOf[K, V]) Range(f func(key K, value V) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the MapOf's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*MapOf[K, V]) Store

func (m *MapOf[K, V]) Store(key K, value V)

Store sets the value for a key.

type Server

type Server struct {
	rtapi.NakamaPeerApiServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ctx context.Context, logger *zap.Logger, protojsonMarshaler *protojson.MarshalOptions, protojsonUnmarshaler *protojson.UnmarshalOptions, md map[string]string, c *Configuration) *Server

func (*Server) Call

func (*Server) ServiceRegistry

func (s *Server) ServiceRegistry() *ServiceRegistry

func (*Server) SessionRegistry

func (s *Server) SessionRegistry() *SessionRegistry

func (*Server) Start

func (s *Server) Start(etcd *etcd.ClientV3, h Handler, updated func(serviceRegistry *ServiceRegistry))

func (*Server) Stop

func (s *Server) Stop()

func (*Server) Stream

func (s *Server) Stream(stream rtapi.NakamaPeerApi_StreamServer) error

type Service

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

func (*Service) Close

func (s *Service) Close() error

func (*Service) Do

func (*Service) Metadata

func (s *Service) Metadata() *rtapi.NakamaPeer_NodeMeta

func (*Service) Name

func (s *Service) Name() string

func (*Service) Recv

func (s *Service) Recv(fn func(service runtime.PeerService, msg *rtapi.NakamaPeer_Envelope)) error

func (*Service) Send

func (s *Service) Send(msg *rtapi.NakamaPeer_Envelope) error

type ServiceRegistry

type ServiceRegistry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewServiceRegistry

func NewServiceRegistry(ctx context.Context, logger *zap.Logger, meta *rtapi.NakamaPeer_NodeMeta, protojsonMarshaler *protojson.MarshalOptions, protojsonUnmarshaler *protojson.UnmarshalOptions, config *Configuration) *ServiceRegistry

func (*ServiceRegistry) GetServiceByHashRing added in v1.0.4

func (s *ServiceRegistry) GetServiceByHashRing(role, key string) (runtime.PeerService, bool)

func (*ServiceRegistry) GetServices

func (s *ServiceRegistry) GetServices() map[string]map[string]runtime.PeerService

func (*ServiceRegistry) GetServicesByRole

func (s *ServiceRegistry) GetServicesByRole(role string) []runtime.PeerService

func (*ServiceRegistry) GetServicesWithNakama

func (s *ServiceRegistry) GetServicesWithNakama() []runtime.PeerService

func (*ServiceRegistry) Shutdown

func (s *ServiceRegistry) Shutdown(timeout time.Duration)

func (*ServiceRegistry) Start

func (s *ServiceRegistry) Start(client *etcd.ClientV3, updateChan chan struct{})

type Session

type Session interface {
	ID() string
	Role() string
	Context() context.Context
	Consume()

	// Deprecated: Use Notification or Broadcast
	Send(msg *rtapi.NakamaPeer_Envelope) error

	Notification(ns []*api.Notification, opts ...BroadcastOption) error
	Broadcast(m []byte, opts ...BroadcastOption) error
}

func NewSession

func NewSession(ctx context.Context, logger *zap.Logger, id, role string, conn rtapi.NakamaPeerApi_StreamServer, outgoingQueueSize int, handler Handler) Session

type SessionRegistry

type SessionRegistry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSessionRegistry

func NewSessionRegistry() *SessionRegistry

func (*SessionRegistry) Add

func (r *SessionRegistry) Add(session Session)

func (*SessionRegistry) Count

func (r *SessionRegistry) Count() int

func (*SessionRegistry) Get

func (r *SessionRegistry) Get(sessionID string) (Session, bool)

func (*SessionRegistry) Range

func (r *SessionRegistry) Range(fn func(Session) bool)

func (*SessionRegistry) RangeRole

func (r *SessionRegistry) RangeRole(role string, fn func(Session) bool)

func (*SessionRegistry) Remove

func (r *SessionRegistry) Remove(sessionID string)

Directories

Path Synopsis
core
math/decimal
Package decimal implements an arbitrary precision fixed-point decimal.
Package decimal implements an arbitrary precision fixed-point decimal.

Jump to

Keyboard shortcuts

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