完成websocket对话演示和main方法的功能抽离

This commit is contained in:
Cold
2025-12-19 15:02:05 +08:00
committed by 张斌
parent 5bc580b3b8
commit 7381d57b77
5 changed files with 85 additions and 10 deletions

41
rabbitmq/instance.go Normal file
View File

@@ -0,0 +1,41 @@
package rabbitmq
import (
"fmt"
"os"
"sync"
"github.com/gogf/gf/v2/util/guid"
)
var (
instanceId string
instanceOnce sync.Once
)
// getInstanceId 获取当前实例的唯一标识(单例)
// 格式:{hostname}.{uuid8}
func getInstanceId() string {
instanceOnce.Do(func() {
// 获取主机名
hostname, err := os.Hostname()
if err != nil || hostname == "" {
hostname = "unknown"
}
// 生成8位UUID
uuid := guid.S()[:8]
instanceId = fmt.Sprintf("%s.%s", hostname, uuid)
})
return instanceId
}
// GetInstanceQueueName 获取当前实例的响应队列名
// 格式:{baseQueue}.{hostname}.{uuid8}
func GetInstanceQueueName(baseQueue string) string {
if baseQueue == "" {
baseQueue = "ragflow.response"
}
return fmt.Sprintf("%s.%s", baseQueue, getInstanceId())
}