mesh

package
v2.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 22 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HookHandler added in v2.1.0

type HookHandler func(proxy *Proxy)

HookHandler is the hook handler of the mesh.

type Mesh

type Mesh struct {
	component.Base
	// contains filtered or unexported fields
}

Mesh is the mesh server.

func NewMesh

func NewMesh(opts ...Option) *Mesh

NewMesh returns a new mesh server.

It initializes the proxy and internal components and stays in the shut state.

func (*Mesh) Close added in v2.2.4

func (m *Mesh) Close()

Close closes the mesh.

It marks the mesh as hang and refreshes the service instance state in the registry.

func (*Mesh) Destroy

func (m *Mesh) Destroy()

Destroy destroys the mesh server.

It marks the mesh as shut, deregisters the service instance, stops the transport server and releases the internal component resources.

func (*Mesh) Init

func (m *Mesh) Init()

Init initializes the mesh.

It validates required configuration such as the codec, registry and transporter, terminating the process when they are missing.

func (*Mesh) Name

func (m *Mesh) Name() string

Name returns the component name.

func (*Mesh) Proxy

func (m *Mesh) Proxy() *Proxy

Proxy returns the mesh proxy.

func (*Mesh) Start

func (m *Mesh) Start()

Start starts the mesh.

It marks the mesh as working, then starts the transport server, registers the service instance and starts watching.

type Option

type Option func(o *options)

Option is a mesh option.

func WithCodec

func WithCodec(codec encoding.Codec) Option

WithCodec sets the codec.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the startup context.

func WithEncryptor

func WithEncryptor(encryptor crypto.Encryptor) Option

WithEncryptor sets the message encryptor.

func WithID added in v2.5.4

func WithID(id string) Option

WithID sets the instance ID.

func WithLinkerCallTimeout added in v2.6.0

func WithLinkerCallTimeout(callTimeout time.Duration) Option

WithLinkerCallTimeout sets the RPC call timeout.

func WithLinkerCommandQueueSize added in v2.6.0

func WithLinkerCommandQueueSize(commandQueueSize int32) Option

WithLinkerCommandQueueSize sets the message queue size.

func WithLinkerCommandWriteTimeout added in v2.6.0

func WithLinkerCommandWriteTimeout(commandWriteTimeout time.Duration) Option

WithLinkerCommandWriteTimeout sets the write timeout.

func WithLinkerConnNum added in v2.6.0

func WithLinkerConnNum(connNum int) Option

WithLinkerConnNum sets the number of connections.

func WithLinkerDialRetryTimes added in v2.6.0

func WithLinkerDialRetryTimes(dialRetryTimes int) Option

WithLinkerDialRetryTimes sets the number of internal RPC dial retries.

func WithLinkerDialTimeout added in v2.6.0

func WithLinkerDialTimeout(dialTimeout time.Duration) Option

WithLinkerDialTimeout sets the internal RPC dial timeout.

func WithLinkerFaultRecoveryTime added in v2.6.0

func WithLinkerFaultRecoveryTime(faultRecoveryTime time.Duration) Option

WithLinkerFaultRecoveryTime sets the internal RPC fault recovery time.

func WithLocator

func WithLocator(locator locate.Locator) Option

WithLocator sets the locator.

func WithMetadata added in v2.3.0

func WithMetadata(metadata map[string]string) Option

WithMetadata sets the metadata.

func WithName

func WithName(name string) Option

WithName sets the instance name.

func WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry sets the service registry.

func WithTransporter

func WithTransporter(transporter transport.Transporter) Option

WithTransporter sets the message transporter.

func WithWeight added in v2.2.4

func WithWeight(weight int) Option

WithWeight sets the weight.

type Proxy

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

Proxy is the mesh proxy.

It provides the complete API exposed by the mesh server, including gate/node linking and message pushing.

func (*Proxy) AddHookListener added in v2.1.0

func (p *Proxy) AddHookListener(hook cluster.Hook, handler HookHandler)

AddHookListener adds a hook listener for the given hook.

func (*Proxy) AddServiceProvider

func (p *Proxy) AddServiceProvider(name string, desc, provider any)

AddServiceProvider adds a service provider. The name is the service name, desc is the service description and provider is the service provider.

func (*Proxy) AskGate added in v2.1.0

func (p *Proxy) AskGate(ctx context.Context, gid string, uid int64) (string, bool, error)

AskGate reports whether the user is on the given gate. It returns the gate ID the user is actually on, whether the user is on the given gate, and an error when the mesh has been shut down.

func (*Proxy) AskNode added in v2.1.0

func (p *Proxy) AskNode(ctx context.Context, uid int64, name, nid string) (string, bool, error)

AskNode reports whether the user is on the given node. It returns the node ID the user is actually on, whether the user is on the given node, and an error when the mesh has been shut down.

func (*Proxy) BindGate

func (p *Proxy) BindGate(ctx context.Context, gid string, cid, uid int64) error

BindGate binds the gate, associating the user with the connection. It returns an error when the mesh has been shut down or binding fails.

func (*Proxy) BindNode

func (p *Proxy) BindNode(ctx context.Context, uid int64, name, nid string) error

BindNode binds a node.

A single user may bind to multiple node servers, but only one node server per name; binding to a node server with the same name multiple times overwrites the previous binding. The binding is synchronized to the gate server and other related node servers through publish-subscribe. It returns an error when the mesh has been shut down or binding fails.

func (*Proxy) Broadcast

func (p *Proxy) Broadcast(ctx context.Context, args *cluster.BroadcastArgs) (int64, error)

Broadcast pushes a broadcast message and returns the number of targets pushed successfully, or an error when the mesh has been shut down or pushing fails. To get the number of successful targets, set args.Ack to true.

func (*Proxy) Deliver added in v2.1.0

func (p *Proxy) Deliver(ctx context.Context, args *cluster.DeliverArgs) error

Deliver delivers a message to a node for processing, or returns an error when the mesh has been shut down or delivering fails.

func (*Proxy) Disconnect

func (p *Proxy) Disconnect(ctx context.Context, args *cluster.DisconnectArgs) error

Disconnect disconnects the session, or returns an error when the mesh has been shut down or disconnecting fails.

func (*Proxy) FetchGateList

func (p *Proxy) FetchGateList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)

FetchGateList fetches the gate list filtered by the given states, or an error when the mesh has been shut down.

func (*Proxy) FetchNodeList

func (p *Proxy) FetchNodeList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)

FetchNodeList fetches the node list filtered by the given states, or an error when the mesh has been shut down.

func (*Proxy) GetID added in v2.1.0

func (p *Proxy) GetID() string

GetID returns the current instance ID.

func (*Proxy) GetIP

func (p *Proxy) GetIP(ctx context.Context, args *cluster.GetIPArgs) (string, error)

GetIP returns the client IP, or an error when the mesh has been shut down or the query fails.

func (*Proxy) GetName added in v2.1.0

func (p *Proxy) GetName() string

GetName returns the current instance name.

func (*Proxy) GetState added in v2.6.0

func (p *Proxy) GetState() cluster.State

GetState returns the current mesh state.

func (*Proxy) HasGate added in v2.5.0

func (p *Proxy) HasGate(gid string) (bool, error)

HasGate reports whether the given gate exists. It returns an error when the mesh has been shut down.

func (*Proxy) HasNode added in v2.5.0

func (p *Proxy) HasNode(nid string) (bool, error)

HasNode reports whether the given node exists. It returns an error when the mesh has been shut down.

func (*Proxy) IsOnline added in v2.1.0

func (p *Proxy) IsOnline(ctx context.Context, args *cluster.IsOnlineArgs) (bool, error)

IsOnline reports whether the session is online, or an error when the mesh has been shut down or the query fails.

func (*Proxy) LocateGate

func (p *Proxy) LocateGate(ctx context.Context, uid int64) (string, error)

LocateGate locates the gate the user is on and returns its gate ID, or an error when the mesh has been shut down.

func (*Proxy) LocateNode

func (p *Proxy) LocateNode(ctx context.Context, uid int64, name string) (string, error)

LocateNode locates the node the user is on and returns its node ID, or an error when the mesh has been shut down.

func (*Proxy) LocateNodes added in v2.5.0

func (p *Proxy) LocateNodes(ctx context.Context, uid int64) (map[string]string, error)

LocateNodes locates the nodes the user is on and returns a map from node name to node ID, or an error when the mesh has been shut down.

func (*Proxy) Multicast

func (p *Proxy) Multicast(ctx context.Context, args *cluster.MulticastArgs) (int64, error)

Multicast pushes a multicast message and returns the number of targets pushed successfully, or an error when the mesh has been shut down or pushing fails. To get the number of successful targets, set args.Ack to true.

func (*Proxy) NewMeshClient added in v2.1.0

func (p *Proxy) NewMeshClient(target string) (transport.Client, error)

NewMeshClient creates a new mesh client.

The target parameter supports three forms:

direct://127.0.0.1:8011                        (direct connection by address)
direct://711baf8d-8a06-11ef-b7df-f4f19e1f0070  (direct connection by instance ID)
discovery://service_name                       (service discovery by service name)

It returns an error when the mesh has been shut down.

func (*Proxy) PackBuffer added in v2.2.0

func (p *Proxy) PackBuffer(message any) ([]byte, error)

PackBuffer packs the given message content and returns the packed message bytes, or an error when packing fails.

func (*Proxy) PackMessage added in v2.2.0

func (p *Proxy) PackMessage(message *cluster.Message) (buffer.Buffer, error)

PackMessage packs the given message and returns the packed buffer, whose ownership is transferred to the caller and must be released with buffer.Buffer.Release, or an error when packing fails.

func (*Proxy) Publish added in v2.3.0

func (p *Proxy) Publish(ctx context.Context, args *cluster.PublishArgs) (int64, error)

Publish publishes a message and returns the number of targets published successfully, or an error when the mesh has been shut down or publishing fails. To get the number of successful targets, set args.Ack to true.

func (*Proxy) Push

func (p *Proxy) Push(ctx context.Context, args *cluster.PushArgs) error

Push pushes a message. Setting args.Ack to true reports the actual delivery result. It returns an error when the mesh has been shut down or pushing fails.

func (*Proxy) SetState added in v2.6.0

func (p *Proxy) SetState(state cluster.State) error

SetState sets the current mesh state, returning an error when the state cannot be set.

func (*Proxy) Stat

func (p *Proxy) Stat(ctx context.Context, kind cluster.Session) (int64, error)

Stat returns the total number of sessions, or an error when the mesh has been shut down.

func (*Proxy) Subscribe added in v2.3.0

func (p *Proxy) Subscribe(ctx context.Context, args *cluster.SubscribeArgs) error

Subscribe subscribes to a channel, or returns an error when the mesh has been shut down or subscribing fails.

func (*Proxy) UnbindGate

func (p *Proxy) UnbindGate(ctx context.Context, uid int64) error

UnbindGate unbinds the gate. It returns an error when the mesh has been shut down or unbinding fails.

func (*Proxy) UnbindNode

func (p *Proxy) UnbindNode(ctx context.Context, uid int64, name, nid string) error

UnbindNode unbinds a node.

It unbinds the node server with the corresponding name and validates the node ID; the unbind fails when the node ID does not match. The unbind is synchronized to the gate server and other related node servers through publish-subscribe. It returns an error when the mesh has been shut down or unbinding fails.

func (*Proxy) Unsubscribe added in v2.3.0

func (p *Proxy) Unsubscribe(ctx context.Context, args *cluster.UnsubscribeArgs) error

Unsubscribe unsubscribes from a channel, or returns an error when the mesh has been shut down or unsubscribing fails.

Jump to

Keyboard shortcuts

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