重构了一下 rag的方法, 使用 goframe的框架, 还有redis连接部分
This commit is contained in:
@@ -2,8 +2,8 @@ package rabbitmq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
)
|
||||
@@ -35,7 +35,7 @@ type BindingConfig struct {
|
||||
}
|
||||
|
||||
// DeclareQueue 声明队列
|
||||
func DeclareQueue(ctx context.Context, cfg *QueueConfig) error {
|
||||
func DeclareQueue(ctx context.Context, cfg *QueueConfig) (err error) {
|
||||
ch, err := GetChannel()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -56,11 +56,11 @@ func DeclareQueue(ctx context.Context, cfg *QueueConfig) error {
|
||||
}
|
||||
|
||||
g.Log().Infof(ctx, "队列声明成功: %s", cfg.Name)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
// DeclareExchange 声明 Exchange
|
||||
func DeclareExchange(ctx context.Context, cfg *ExchangeConfig) error {
|
||||
func DeclareExchange(ctx context.Context, cfg *ExchangeConfig) (err error) {
|
||||
ch, err := GetChannel()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -82,11 +82,11 @@ func DeclareExchange(ctx context.Context, cfg *ExchangeConfig) error {
|
||||
}
|
||||
|
||||
g.Log().Infof(ctx, "Exchange 声明成功: %s (type=%s)", cfg.Name, cfg.Type)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
// BindQueue 绑定队列到 Exchange
|
||||
func BindQueue(ctx context.Context, cfg *BindingConfig) error {
|
||||
func BindQueue(ctx context.Context, cfg *BindingConfig) (err error) {
|
||||
ch, err := GetChannel()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -108,7 +108,7 @@ func BindQueue(ctx context.Context, cfg *BindingConfig) error {
|
||||
|
||||
g.Log().Infof(ctx, "队列绑定成功: queue=%s → exchange=%s (routingKey=%s)",
|
||||
cfg.Queue, cfg.Exchange, cfg.RoutingKey)
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
// SetupDelayExchange 设置延时 Exchange(需要 rabbitmq_delayed_message_exchange 插件)
|
||||
@@ -165,9 +165,9 @@ func SetupQueueWithDLX(ctx context.Context, queueName, dlxExchange, dlxRoutingKe
|
||||
}
|
||||
|
||||
// SetupBasicTopology 设置基础拓扑(适用于小红书客服场景)
|
||||
func SetupBasicTopology(ctx context.Context) error {
|
||||
func SetupBasicTopology(ctx context.Context) (err error) {
|
||||
// 1. 声明普通 Exchange
|
||||
err := DeclareExchange(ctx, &ExchangeConfig{
|
||||
err = DeclareExchange(ctx, &ExchangeConfig{
|
||||
Name: "ragflow_exchange",
|
||||
Type: "direct",
|
||||
Durable: true,
|
||||
@@ -179,7 +179,7 @@ func SetupBasicTopology(ctx context.Context) error {
|
||||
// 2. 声明延时 Exchange
|
||||
err = SetupDelayExchange(ctx, "delay_exchange")
|
||||
if err != nil {
|
||||
return fmt.Errorf("延时 Exchange 声明失败(可能未安装插件): %v", err)
|
||||
return gerror.Newf("延时 Exchange 声明失败(可能未安装插件): %v", err)
|
||||
}
|
||||
|
||||
// 3. 声明死信队列
|
||||
@@ -227,5 +227,5 @@ func SetupBasicTopology(ctx context.Context) error {
|
||||
}
|
||||
|
||||
g.Log().Info(ctx, "RabbitMQ 拓扑结构设置完成")
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user