채널이름을 모든 public 함수의 signature를 고려
This commit is contained in:
11
rpc/rpc.go
11
rpc/rpc.go
@ -58,9 +58,18 @@ func Start(ctx context.Context, redisClient *redis.Client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hash := md5.New()
|
hash := md5.New()
|
||||||
for k := range engine.receivers {
|
for k, manifest := range engine.receivers {
|
||||||
hash.Write([]byte(k))
|
hash.Write([]byte(k))
|
||||||
|
for m, r := range manifest.methods {
|
||||||
|
hash.Write([]byte(m))
|
||||||
|
hash.Write([]byte(r.Name))
|
||||||
|
for i := 0; i < r.Type.NumIn(); i++ {
|
||||||
|
inName := r.Type.In(i).Name()
|
||||||
|
hash.Write([]byte(inName))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pubsubName := hex.EncodeToString(hash.Sum(nil))[:16]
|
pubsubName := hex.EncodeToString(hash.Sum(nil))[:16]
|
||||||
|
|
||||||
engine.publish = func(s []byte) error {
|
engine.publish = func(s []byte) error {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package rpc
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"repositories.action2quare.com/ayo/gocommon"
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
@ -13,19 +14,18 @@ type testReceiver struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tr *testReceiver) TargetExists(tid primitive.ObjectID) bool {
|
func (tr *testReceiver) TargetExists(tid primitive.ObjectID) bool {
|
||||||
|
logger.Println(tid.Hex())
|
||||||
return tid[0] >= 10
|
return tid[0] >= 10
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tr *testReceiver) TestFunc(a string, b string) {
|
func (tr *testReceiver) TestFunc(a string, b string, c int) {
|
||||||
logger.Println("TestFunc :", a, b)
|
|
||||||
|
|
||||||
target := primitive.NewObjectID()
|
target := primitive.NewObjectID()
|
||||||
target[0] = 0
|
target[0] = 0
|
||||||
if CallOrGo(tr, target, a, b) != ErrCanExecuteHere {
|
if CallOrGo(tr, target, a, b) != ErrCanExecuteHere {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Println(a, b)
|
logger.Println(" ", a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRpc(t *testing.T) {
|
func TestRpc(t *testing.T) {
|
||||||
@ -34,9 +34,14 @@ func TestRpc(t *testing.T) {
|
|||||||
myctx, cancel := context.WithCancel(context.Background())
|
myctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
redisClient, _ := gocommon.NewRedisClient("redis://192.168.8.94:6379", 0)
|
redisClient, _ := gocommon.NewRedisClient("redis://192.168.8.94:6379", 0)
|
||||||
Start(myctx, redisClient)
|
go func() {
|
||||||
|
for {
|
||||||
|
tr.TestFunc("aaaa", "bbbb", 333)
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
tr.TestFunc("aaa", "bb")
|
Start(myctx, redisClient)
|
||||||
<-myctx.Done()
|
<-myctx.Done()
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user