rpc

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// group id
	PrivateGroupId = 0
	PublicGroupId  = 1

	CometServicePushPrivate = "CometRPC.PushPrivate"
)
View Source
const (
	MessageService      = "MessageRPC"
	MessageServiceGet   = "MessageRPC.Get"
	MessageServiceSave  = "MessageRPC.Save"
	MessageServiceClean = "MessageRPC.Clean"
)
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, 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 []string // current comet nodes
	Vnode int      // ketama virtual node number
}

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 {
	// The addr for subscribe, format like:map[Protocol]Addr
	Addr map[int][]string
	// The connection for Comet RPC
	CometRPC *RandLB
}

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
	GroupId uint            // message group id
	Expire  uint            // message expire second
}

Channel Push Private Message Args

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 MessageGetArgs

type MessageGetArgs struct {
	MsgId    int64  // message id
	PubMsgId int64  // public message id
	Key      string // subscriber key
}

Message Get Args

type MessageGetResp

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

Message Get Response

type MessageNodeEvent

type MessageNodeEvent struct {
	// addr:port
	Key string
	// event type
	Event int
}

type MessageSaveArgs

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

Message Save Args

type MessageSavePubArgs

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

Public Message Save 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]*rpc.Client
	// contains filtered or unexported fields
}

random load balancing object

var (
	MessageRPC *RandLB
)

func NewRandLB

func NewRandLB(clients map[string]*rpc.Client, addrs []string, 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.

Jump to

Keyboard shortcuts

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