채널이름 고정으로 계산

This commit is contained in:
2023-07-10 11:43:52 +09:00
parent 27a3f2f08c
commit c859aeb75f

View File

@ -3,7 +3,9 @@ package rpc
import ( import (
"bytes" "bytes"
"context" "context"
"crypto/md5"
"encoding/gob" "encoding/gob"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"path" "path"
@ -55,7 +57,12 @@ func Start(ctx context.Context, redisClient *redis.Client) {
return return
} }
pubsubName := primitive.NewObjectID().Hex()[6:] hash := md5.New()
for k := range engine.receivers {
hash.Write([]byte(k))
}
pubsubName := hex.EncodeToString(hash.Sum(nil))[:16]
engine.publish = func(s []byte) error { engine.publish = func(s []byte) error {
_, err := redisClient.Publish(ctx, pubsubName, s).Result() _, err := redisClient.Publish(ctx, pubsubName, s).Result()
return err return err