Documentation
¶
Index ¶
- type HookHandler
- type Mesh
- type Option
- func WithCodec(codec encoding.Codec) Option
- func WithContext(ctx context.Context) Option
- func WithEncryptor(encryptor crypto.Encryptor) Option
- func WithID(id string) Option
- func WithLinkerCallTimeout(callTimeout time.Duration) Option
- func WithLinkerCommandQueueSize(commandQueueSize int32) Option
- func WithLinkerCommandWriteTimeout(commandWriteTimeout time.Duration) Option
- func WithLinkerConnNum(connNum int) Option
- func WithLinkerDialRetryTimes(dialRetryTimes int) Option
- func WithLinkerDialTimeout(dialTimeout time.Duration) Option
- func WithLinkerFaultRecoveryTime(faultRecoveryTime time.Duration) Option
- func WithLocator(locator locate.Locator) Option
- func WithMetadata(metadata map[string]string) Option
- func WithName(name string) Option
- func WithRegistry(r registry.Registry) Option
- func WithTransporter(transporter transport.Transporter) Option
- func WithWeight(weight int) Option
- type Proxy
- func (p *Proxy) AddHookListener(hook cluster.Hook, handler HookHandler)
- func (p *Proxy) AddServiceProvider(name string, desc, provider any)
- func (p *Proxy) AskGate(ctx context.Context, gid string, uid int64) (string, bool, error)
- func (p *Proxy) AskNode(ctx context.Context, uid int64, name, nid string) (string, bool, error)
- func (p *Proxy) BindGate(ctx context.Context, gid string, cid, uid int64) error
- func (p *Proxy) BindNode(ctx context.Context, uid int64, name, nid string) error
- func (p *Proxy) Broadcast(ctx context.Context, args *cluster.BroadcastArgs) (int64, error)
- func (p *Proxy) Deliver(ctx context.Context, args *cluster.DeliverArgs) error
- func (p *Proxy) Disconnect(ctx context.Context, args *cluster.DisconnectArgs) error
- func (p *Proxy) FetchGateList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)
- func (p *Proxy) FetchNodeList(ctx context.Context, states ...cluster.State) ([]*registry.ServiceInstance, error)
- func (p *Proxy) GetID() string
- func (p *Proxy) GetIP(ctx context.Context, args *cluster.GetIPArgs) (string, error)
- func (p *Proxy) GetName() string
- func (p *Proxy) GetState() cluster.State
- func (p *Proxy) HasGate(gid string) (bool, error)
- func (p *Proxy) HasNode(nid string) (bool, error)
- func (p *Proxy) IsOnline(ctx context.Context, args *cluster.IsOnlineArgs) (bool, error)
- func (p *Proxy) LocateGate(ctx context.Context, uid int64) (string, error)
- func (p *Proxy) LocateNode(ctx context.Context, uid int64, name string) (string, error)
- func (p *Proxy) LocateNodes(ctx context.Context, uid int64) (map[string]string, error)
- func (p *Proxy) Multicast(ctx context.Context, args *cluster.MulticastArgs) (int64, error)
- func (p *Proxy) NewMeshClient(target string) (transport.Client, error)
- func (p *Proxy) PackBuffer(message any) ([]byte, error)
- func (p *Proxy) PackMessage(message *cluster.Message) (buffer.Buffer, error)
- func (p *Proxy) Publish(ctx context.Context, args *cluster.PublishArgs) (int64, error)
- func (p *Proxy) Push(ctx context.Context, args *cluster.PushArgs) error
- func (p *Proxy) SetState(state cluster.State) error
- func (p *Proxy) Stat(ctx context.Context, kind cluster.Session) (int64, error)
- func (p *Proxy) Subscribe(ctx context.Context, args *cluster.SubscribeArgs) error
- func (p *Proxy) UnbindGate(ctx context.Context, uid int64) error
- func (p *Proxy) UnbindNode(ctx context.Context, uid int64, name, nid string) error
- func (p *Proxy) Unsubscribe(ctx context.Context, args *cluster.UnsubscribeArgs) error
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 ¶
Mesh is the mesh server.
func NewMesh ¶
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.
type Option ¶
type Option func(o *options)
Option is a mesh option.
func WithContext ¶
WithContext sets the startup context.
func WithEncryptor ¶
WithEncryptor sets the message encryptor.
func WithLinkerCallTimeout ¶ added in v2.6.0
WithLinkerCallTimeout sets the RPC call timeout.
func WithLinkerCommandQueueSize ¶ added in v2.6.0
WithLinkerCommandQueueSize sets the message queue size.
func WithLinkerCommandWriteTimeout ¶ added in v2.6.0
WithLinkerCommandWriteTimeout sets the write timeout.
func WithLinkerConnNum ¶ added in v2.6.0
WithLinkerConnNum sets the number of connections.
func WithLinkerDialRetryTimes ¶ added in v2.6.0
WithLinkerDialRetryTimes sets the number of internal RPC dial retries.
func WithLinkerDialTimeout ¶ added in v2.6.0
WithLinkerDialTimeout sets the internal RPC dial timeout.
func WithLinkerFaultRecoveryTime ¶ added in v2.6.0
WithLinkerFaultRecoveryTime sets the internal RPC fault recovery time.
func WithMetadata ¶ added in v2.3.0
WithMetadata sets the metadata.
func WithRegistry ¶
WithRegistry sets the service registry.
func WithTransporter ¶
func WithTransporter(transporter transport.Transporter) Option
WithTransporter sets the message transporter.
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 ¶
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
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
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 ¶
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 ¶
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 ¶
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
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 ¶
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) GetIP ¶
GetIP returns the client IP, or an error when the mesh has been shut down or the query fails.
func (*Proxy) HasGate ¶ added in v2.5.0
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
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
IsOnline reports whether the session is online, or an error when the mesh has been shut down or the query fails.
func (*Proxy) LocateGate ¶
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 ¶
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
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 ¶
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
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
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
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
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 ¶
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
SetState sets the current mesh state, returning an error when the state cannot be set.
func (*Proxy) Stat ¶
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
Subscribe subscribes to a channel, or returns an error when the mesh has been shut down or subscribing fails.
func (*Proxy) UnbindGate ¶
UnbindGate unbinds the gate. It returns an error when the mesh has been shut down or unbinding fails.
func (*Proxy) UnbindNode ¶
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
Unsubscribe unsubscribes from a channel, or returns an error when the mesh has been shut down or unsubscribing fails.