rpc

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CometServicePushPrivate  = "CometRPC.PushPrivate"
	CometServicePushPrivates = "CometRPC.PushPrivates"
	CometServiceMigrate      = "CometRPC.Migrate"
)
View Source
const (
	// group id
	PrivateGroupId = 0
	PublicGroupId  = 1
	// message rpc service
	MessageService             = "MessageRPC"
	MessageServiceGetPrivate   = "MessageRPC.GetPrivate"
	MessageServiceSavePrivate  = "MessageRPC.SavePrivate"
	MessageServiceSavePrivates = "MessageRPC.SavePrivates"
	MessageServiceDelPrivate   = "MessageRPC.DelPrivate"
)
View Source
const (
	// common
	// ok
	OK = 0
	// param error
	ParamErr = 65534
	// internal error
	InternalErr = 65535
)

Variables

View Source
var (
	ErrRandLBLength = errors.New("clients and addrs length not match")
	ErrRandLBAddr   = errors.New("clients map no addr key")
)
View Source
var (
	ErrCometRPC = errors.New("comet rpc call failed")
)
View Source
var (
	ErrParam = errors.New("parameter error")
)

Functions

func InitComet

func InitComet(conn *zk.Conn, migrateLockPath, fpath string, retry, ping time.Duration)

InitComet init a rand lb rpc for comet module.

func InitMessage

func InitMessage(conn *zk.Conn, fpath string, retry, ping time.Duration)

InitMessage init a rand lb rpc for message module.

Types

type CometMigrateArgs

type CometMigrateArgs struct {
	Nodes map[string]int // current comet nodes
}

Channel Migrate Args

type CometNewArgs

type CometNewArgs struct {
	Expire int64  // message expire second
	Token  string // auth token
	Key    string // subscriber key
}

Channel New Args

type CometNodeEvent

type CometNodeEvent struct {
	// node name(node1, node2...)
	Key string
	// node info
	Value *CometNodeInfo
	// event type
	Event int
}

type CometNodeInfo

type CometNodeInfo struct {
	RpcAddr []string `json:"rpc"`
	TcpAddr []string `json:"tcp"`
	WsAddr  []string `json:"ws"`
	Weight  int      `json:"weight"`
	Rpc     *RandLB  `json:"-"`
}

CometNodeData stored in zookeeper

func GetComet

func GetComet(key string) *CometNodeInfo

GetComet get the node infomation under the node.

type CometPushPrivateArgs

type CometPushPrivateArgs struct {
	Key    string          // subscriber key
	Msg    json.RawMessage // message content
	Expire uint            // message expire second
}

Channel Push Private Message Args

type CometPushPrivatesArgs added in v1.0.5

type CometPushPrivatesArgs struct {
	Keys   []string        // subscriber keys
	Msg    json.RawMessage // message content
	Expire uint            // message expire second
}

Channel Push multi Private Message Args

type CometPushPrivatesResp added in v1.0.5

type CometPushPrivatesResp struct {
	FKeys []string // subscriber keys
}

Channel Push multi Private Message response

type CometPushPublicArgs

type CometPushPublicArgs struct {
	MsgID int64  // message id
	Msg   string // message content
}

Channel Push Public Message Args

type Message

type Message struct {
	Msg     json.RawMessage `json:"msg"` // message content
	MsgId   int64           `json:"mid"` // message id
	GroupId uint            `json:"gid"` // group id
}

The Message struct

func (*Message) Bytes

func (m *Message) Bytes() ([]byte, error)

Bytes get a message reply bytes.

func (*Message) OldBytes

func (m *Message) OldBytes() ([]byte, error)

OldBytes get a message reply bytes(Compatible), TODO remove it.

type MessageGetPrivateArgs added in v1.0.3

type MessageGetPrivateArgs struct {
	MsgId int64  // message id
	Key   string // subscriber key
}

Message Get args

type MessageGetResp

type MessageGetResp struct {
	Msgs []*Message // messages
}

Message Get Response

type MessageNodeEvent

type MessageNodeEvent struct {
	Key *WeightRpc
	// event type
	Event int
}

type MessageNodeInfo added in v1.0.5

type MessageNodeInfo struct {
	Rpc    []string `json:"rpc"`
	Weight int      `json:"weight"`
}

Message node info

type MessageSavePrivateArgs added in v1.0.3

type MessageSavePrivateArgs struct {
	Key    string          // subscriber key
	Msg    json.RawMessage // message content
	MsgId  int64           // message id
	Expire uint            // message expire second
}

Message SavePrivate args

type MessageSavePrivatesArgs added in v1.0.5

type MessageSavePrivatesArgs struct {
	Keys   []string        // subscriber keys
	Msg    json.RawMessage // message content
	MsgId  int64           // message id
	Expire uint            // message expire second
}

Message SavePrivates args

type MessageSavePrivatesResp added in v1.0.5

type MessageSavePrivatesResp struct {
	FKeys []string // failed key
}

Message SavePrivates response

type MessageSavePublishArgs added in v1.0.3

type MessageSavePublishArgs struct {
	MsgID  int64  // message id
	Msg    string // message content
	Expire int64  // message expire second
}

Message SavePublish args

type OldMessage

type OldMessage struct {
	Msg     string `json:"msg"` // Message
	MsgId   int64  `json:"mid"` // Message id
	GroupId uint   `json:"gid"` // Group id
}

The Old Message struct (Compatible), TODO remove it.

type RandLB

type RandLB struct {
	Clients map[string]*WeightRpc
	// contains filtered or unexported fields
}

random load balancing object

var (
	MessageRPC *RandLB
)

func NewRandLB

func NewRandLB(clients map[string]*WeightRpc, service string, retry, ping time.Duration, check bool) (*RandLB, error)

NewRandLB new a random load balancing object.

func (*RandLB) Destroy

func (r *RandLB) Destroy()

Destroy release the rpc.Client resource.

func (*RandLB) Get

func (r *RandLB) Get() *rpc.Client

Get get a rpc client randomly.

func (*RandLB) Stop

func (r *RandLB) Stop()

Stop stop the retry connect goroutine and ping goroutines.

type WeightRpc added in v1.0.5

type WeightRpc struct {
	Client *rpc.Client
	Addr   string
	Weight int
}

WeightRpc is a rand weight rpc struct.

func (*WeightRpc) Call added in v1.0.5

func (w *WeightRpc) Call(serviceMethod string, args interface{}, reply interface{}) error

Call call the weightrpc inner *rpc.Client.

func (*WeightRpc) Close added in v1.0.5

func (w *WeightRpc) Close() error

Close close the weightrpc inner *rpc.Client.

Jump to

Keyboard shortcuts

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