Ai
2 Star 0 Fork 0

MixerJ/pitaya

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
worker.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
zhusw 提交于 2020-07-18 17:46 +08:00 . modify go mod
package services
import (
"context"
"gitee.com/mixerj/pitaya"
"gitee.com/mixerj/pitaya/component"
"gitee.com/mixerj/pitaya/examples/demo/worker/protos"
"github.com/golang/protobuf/proto"
)
// Worker server
type Worker struct {
component.Base
}
// Configure starts workers and register rpc job
func (w *Worker) Configure() error {
err := pitaya.StartWorker(pitaya.GetConfig())
if err != nil {
return err
}
pitaya.RegisterRPCJob(&RPCJob{})
return nil
}
// RPCJob implements worker.RPCJob
type RPCJob struct{}
// ServerDiscovery returns a serverID="", meaning any server
// is ok
func (r *RPCJob) ServerDiscovery(
route string,
rpcMetadata map[string]interface{},
) (serverID string, err error) {
return "", nil
}
// RPC calls pitaya's rpc
func (r *RPCJob) RPC(
ctx context.Context,
serverID, routeStr string,
reply, arg proto.Message,
) error {
return pitaya.RPCTo(ctx, serverID, routeStr, reply, arg)
}
// GetArgReply returns reply and arg of LogRemote,
// since we have no other methods in this example
func (r *RPCJob) GetArgReply(
route string,
) (arg, reply proto.Message, err error) {
return &protos.Arg{}, &protos.Response{}, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mixerj/pitaya.git
git@gitee.com:mixerj/pitaya.git
mixerj
pitaya
pitaya
4e7898a663a6

搜索帮助