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() }