채널이름을 모든 public 함수의 signature를 고려

This commit is contained in:
2023-07-10 12:13:51 +09:00
parent c859aeb75f
commit b5a72aad05
2 changed files with 21 additions and 7 deletions

View File

@ -58,9 +58,18 @@ func Start(ctx context.Context, redisClient *redis.Client) {
}
hash := md5.New()
for k := range engine.receivers {
for k, manifest := range engine.receivers {
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]
engine.publish = func(s []byte) error {

View File

@ -3,6 +3,7 @@ package rpc
import (
"context"
"testing"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"repositories.action2quare.com/ayo/gocommon"
@ -13,19 +14,18 @@ type testReceiver struct {
}
func (tr *testReceiver) TargetExists(tid primitive.ObjectID) bool {
logger.Println(tid.Hex())
return tid[0] >= 10
}
func (tr *testReceiver) TestFunc(a string, b string) {
logger.Println("TestFunc :", a, b)
func (tr *testReceiver) TestFunc(a string, b string, c int) {
target := primitive.NewObjectID()
target[0] = 0
if CallOrGo(tr, target, a, b) != ErrCanExecuteHere {
return
}
logger.Println(a, b)
logger.Println(" ", a, b)
}
func TestRpc(t *testing.T) {
@ -34,9 +34,14 @@ func TestRpc(t *testing.T) {
myctx, cancel := context.WithCancel(context.Background())
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()
cancel()
}