From b5a72aad05a770e6540e888e2eefc399a6c457a6 Mon Sep 17 00:00:00 2001 From: mountain Date: Mon, 10 Jul 2023 12:13:51 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B1=84=EB=84=90=EC=9D=B4=EB=A6=84=EC=9D=84?= =?UTF-8?q?=20=EB=AA=A8=EB=93=A0=20public=20=ED=95=A8=EC=88=98=EC=9D=98=20?= =?UTF-8?q?signature=EB=A5=BC=20=EA=B3=A0=EB=A0=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/rpc.go | 11 ++++++++++- rpc/rpc_test.go | 17 +++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/rpc/rpc.go b/rpc/rpc.go index 08b49f6..fa6090a 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -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 { diff --git a/rpc/rpc_test.go b/rpc/rpc_test.go index dc8f521..2965c1b 100644 --- a/rpc/rpc_test.go +++ b/rpc/rpc_test.go @@ -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() }