完成websocket对话演示和main方法的功能抽离
This commit is contained in:
41
rabbitmq/instance.go
Normal file
41
rabbitmq/instance.go
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user