From 616ed7e8acab94ad982f2a1ba593317e73b78d59 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Thu, 14 Nov 2024 19:29:22 +0800 Subject: [PATCH 1/5] update --- consume/egg_energy_fund_data_consume.go | 2 +- consume/init.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/consume/egg_energy_fund_data_consume.go b/consume/egg_energy_fund_data_consume.go index b257b5e..2386474 100644 --- a/consume/egg_energy_fund_data_consume.go +++ b/consume/egg_energy_fund_data_consume.go @@ -42,7 +42,7 @@ func EggEnergyDealFundDataConsume(queue md.MqQueue) { for { res, ok = <-delivery if ok == true { - err = handleEggEnergyStartLevelDividendConsume(res.Body) + err = handleEggEnergyDealFundDataConsume(res.Body) if err != nil { fmt.Println("EggEnergyDealFundDataConsume_ERR:::::", err.Error()) utils2.FilePutContents("EggEnergyDealFundDataConsume_ERR", utils2.SerializeStr(map[string]interface{}{ diff --git a/consume/init.go b/consume/init.go index 6fcc1f1..82c78d5 100644 --- a/consume/init.go +++ b/consume/init.go @@ -18,6 +18,8 @@ func Init() { // 增加消费任务队列 func initConsumes() { jobs[consumeMd.EggEnergyStartLevelDividendFunName] = EggEnergyStartLevelDividendConsume + jobs[consumeMd.EggEnergyDealPlatformRevenueDataFunName] = EggEnergyDealPlatformRevenueDataConsume + jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume } func Run() { From e88ce2e62d3aeafd1af06456a21413ef76c6f2f1 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Fri, 15 Nov 2024 17:48:10 +0800 Subject: [PATCH 2/5] update --- consume/egg_energy_fund_data_consume.go | 2 +- consume/egg_energy_platform_revenue_data.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/consume/egg_energy_fund_data_consume.go b/consume/egg_energy_fund_data_consume.go index 2386474..f4350e0 100644 --- a/consume/egg_energy_fund_data_consume.go +++ b/consume/egg_energy_fund_data_consume.go @@ -23,7 +23,7 @@ import ( ) func EggEnergyDealFundDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyStartLevelDividendConsume>>>>>>>>>>>>") + fmt.Println(">>>>>>>>>>>>EggEnergyDealFundDataConsume>>>>>>>>>>>>") ch, err := rabbit.Cfg.Pool.GetChannel() if err != nil { logx.Error(err) diff --git a/consume/egg_energy_platform_revenue_data.go b/consume/egg_energy_platform_revenue_data.go index c98855b..2139714 100644 --- a/consume/egg_energy_platform_revenue_data.go +++ b/consume/egg_energy_platform_revenue_data.go @@ -23,7 +23,7 @@ import ( ) func EggEnergyDealPlatformRevenueDataConsume(queue md.MqQueue) { - fmt.Println(">>>>>>>>>>>>EggEnergyStartLevelDividendConsume>>>>>>>>>>>>") + fmt.Println(">>>>>>>>>>>>EggEnergyDealPlatformRevenueDataConsume>>>>>>>>>>>>") ch, err := rabbit.Cfg.Pool.GetChannel() if err != nil { logx.Error(err) From 3f2435251dd4e0e21a4f7392b3b3f31bb1aff40c Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 27 Nov 2024 19:25:14 +0800 Subject: [PATCH 3/5] add batch send message --- app/cfg/init_cfg.go | 6 ++ app/utils/rpc_client.go | 64 ++++++++++++++ ...m_egg_energy_batch_send_message_consume.go | 87 +++++++++++++++++++ consume/init.go | 1 + consume/md/consume_key.go | 10 +++ go.mod | 11 ++- 6 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 app/utils/rpc_client.go create mode 100644 consume/im_egg_energy_batch_send_message_consume.go diff --git a/app/cfg/init_cfg.go b/app/cfg/init_cfg.go index a4b9a6f..8184c0e 100644 --- a/app/cfg/init_cfg.go +++ b/app/cfg/init_cfg.go @@ -17,6 +17,7 @@ var ( DB *DBCfg MQ *MQCfg Log *LogCfg + ImLogicRpc *ImLogicRpcCfg ) // 初始化配置文件,将cfg.yml读入到内存 @@ -48,3 +49,8 @@ func InitCfg() { MQ = &conf.MQ RedisPassword = conf.RedisPassword } + +type ImLogicRpcCfg struct { + URL string `yaml:"url"` + PORT string `yaml:"port"` +} diff --git a/app/utils/rpc_client.go b/app/utils/rpc_client.go new file mode 100644 index 0000000..52d1d76 --- /dev/null +++ b/app/utils/rpc_client.go @@ -0,0 +1,64 @@ +package utils + +import ( + "applet/pkg/pb" + "context" + "fmt" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "strconv" + "time" +) + +func GetBusinessIntClient(url, port string) pb.BusinessIntClient { + target := fmt.Sprintf("%s:%s", url, port) + conn, err := grpc.Dial(target, grpc.WithInsecure()) + if err != nil { + fmt.Println(err) + return nil + } + return pb.NewBusinessIntClient(conn) +} + +func GetBusinessExtClient(url, port string) pb.BusinessExtClient { + target := fmt.Sprintf("%s:%s", url, port) + conn, err := grpc.Dial(target, grpc.WithInsecure()) + //defer conn.Close() + if err != nil { + fmt.Println(err) + return nil + } + return pb.NewBusinessExtClient(conn) +} + +func GetLogicExtClient(url, port string) pb.LogicExtClient { + target := fmt.Sprintf("%s:%s", url, port) + conn, err := grpc.Dial(target, grpc.WithInsecure()) + if err != nil { + fmt.Println(err) + return nil + } + return pb.NewLogicExtClient(conn) +} + +func GetCtx(token, userId, deviceId, masterId string) context.Context { + if userId == "" { + userId = "1" + } + if deviceId == "" { + deviceId = "1" + } + if token == "" { + token = "0" + } + return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs( + "user_id", userId, + "device_id", deviceId, + "token", token, + "master_id", masterId, + "request_id", strconv.FormatInt(time.Now().UnixNano(), 10))) +} + +func UnixMilliTime(t time.Time) int64 { + return t.UnixNano() / 1000000 +} diff --git a/consume/im_egg_energy_batch_send_message_consume.go b/consume/im_egg_energy_batch_send_message_consume.go new file mode 100644 index 0000000..39aaf1c --- /dev/null +++ b/consume/im_egg_energy_batch_send_message_consume.go @@ -0,0 +1,87 @@ +package consume + +import ( + "applet/app/cfg" + utils2 "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + "applet/pkg/pb" + "code.fnuoos.com/EggPlanet/egg_system_rules.git" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "google.golang.org/protobuf/proto" + "time" +) + +func IMEggEnergyBatchSendMessageDataConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>IMEggEnergyBatchSendMessageDataConsume>>>>>>>>>>>>") + ch, err := rabbit.Cfg.Pool.GetChannel() + if err != nil { + logx.Error(err) + return + } + defer ch.Release() + //1、将自己绑定到交换机上 + ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) + //2、取出数据进行消费 + ch.Qos(1) + delivery := ch.Consume(queue.Name, false) + + egg_system_rules.Init(cfg.RedisAddr) + var res amqp.Delivery + var ok bool + for { + res, ok = <-delivery + if ok == true { + err = handleIMEggEnergyBatchSendMessageDataConsume(res.Body) + if err != nil { + fmt.Println("IMEggEnergyBatchSendMessageDataConsume_ERR:::::", err.Error()) + utils2.FilePutContents("IMEggEnergyBatchSendMessageDataConsume_ERR", utils2.SerializeStr(map[string]interface{}{ + "body": res.Body, + "err": err.Error(), + })) + } + //_ = res.Reject(false) + err = res.Ack(true) + fmt.Println("err ::: ", err) + } else { + panic(errors.New("error getting message")) + } + } + fmt.Println("get msg done") +} + +func handleIMEggEnergyBatchSendMessageDataConsume(msgData []byte) error { + time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 + // 1.解析mq中queue的数据结构体 + var msg *md2.IMEggEnergyStructForBatchSendMessageData + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + + //TODO::调用im GRPC 接口 + buf, err := proto.Marshal(&pb.Text{ + Text: msg.Content, + }) + + _, err = utils2.GetLogicExtClient(cfg.ImLogicRpc.URL, cfg.ImLogicRpc.PORT).SendMessage(utils2.GetCtx("", utils2.Int64ToStr(msg.SendId), "", ""), &pb.SendMessageReq{ + ReceiverType: pb.ReceiverType(msg.ReceiverType), + ReceiverId: msg.ReceiveIMId, + ToUserIds: nil, + MessageType: pb.MessageType(msg.MessageType), + MessageContent: buf, + SendTime: utils2.UnixMilliTime(time.Now()), + IsPersist: true, + MessageContentBack: "", + }) + if err != nil { + return err + } + + return nil +} diff --git a/consume/init.go b/consume/init.go index 82c78d5..52361ba 100644 --- a/consume/init.go +++ b/consume/init.go @@ -20,6 +20,7 @@ func initConsumes() { jobs[consumeMd.EggEnergyStartLevelDividendFunName] = EggEnergyStartLevelDividendConsume jobs[consumeMd.EggEnergyDealPlatformRevenueDataFunName] = EggEnergyDealPlatformRevenueDataConsume jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume + jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume } func Run() { diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index facd11e..488b6be 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -38,10 +38,20 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "EggEnergyDealPlatformRevenueDataConsume", }, + { + ExchangeName: "im.egg.energy", + Name: "im_egg_energy_batch_send_message_queue", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "batch_send_message_data", + BindKey: "", + ConsumeFunName: "IMEggEnergyBatchSendMessageDataConsume", + }, } const ( EggEnergyStartLevelDividendFunName = "EggEnergyStartLevelDividendConsume" EggEnergyDealFundDataFunName = "EggEnergyDealFundDataConsume" EggEnergyDealPlatformRevenueDataFunName = "EggEnergyDealPlatformRevenueDataConsume" + IMEggEnergyBatchSendMessageDataFunName = "IMEggEnergyBatchSendMessageDataConsume" ) diff --git a/go.mod b/go.mod index d769288..e339f64 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241114063419-cb68a0ed34ee + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241119093836-37be936b83fc code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.2 code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 github.com/boombuler/barcode v1.0.1 @@ -21,6 +21,7 @@ require ( github.com/gomodule/redigo v2.0.0+incompatible github.com/makiuchi-d/gozxing v0.1.1 github.com/qiniu/api.v7/v7 v7.8.2 + github.com/shopspring/decimal v1.3.1 github.com/sony/sonyflake v1.0.0 github.com/streadway/amqp v1.0.0 github.com/syyongx/php2go v0.9.8 @@ -52,11 +53,8 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/onsi/ginkgo v1.16.5 // indirect - github.com/onsi/gomega v1.19.0 // indirect + github.com/nxadm/tail v1.4.8 // indirect github.com/pelletier/go-toml/v2 v2.2.0 // indirect - github.com/pkg/errors v0.9.1 // indirect - github.com/shopspring/decimal v1.3.1 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect @@ -65,10 +63,11 @@ require ( golang.org/x/arch v0.7.0 // indirect golang.org/x/crypto v0.21.0 // indirect golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect - golang.org/x/net v0.22.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/sync v0.6.0 // indirect golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.9.1 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect From 8025d9f98cc87c140a7a3b2c5aea5dfef801b9a8 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Thu, 28 Nov 2024 19:18:44 +0800 Subject: [PATCH 4/5] add to deal user virtual coin consume --- ...g_energy_deal_user_virtual_coin_consume.go | 83 +++++++++++++++++++ consume/init.go | 1 + consume/md/consume_key.go | 10 +++ go.mod | 2 +- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 consume/egg_energy_deal_user_virtual_coin_consume.go diff --git a/consume/egg_energy_deal_user_virtual_coin_consume.go b/consume/egg_energy_deal_user_virtual_coin_consume.go new file mode 100644 index 0000000..625f736 --- /dev/null +++ b/consume/egg_energy_deal_user_virtual_coin_consume.go @@ -0,0 +1,83 @@ +package consume + +import ( + "applet/app/cfg" + "applet/app/db" + utils2 "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git" + md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "time" +) + +func EggEnergyDealUserVirtualCoinDataConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>EggEnergyDealUserVirtualCoinDataConsume>>>>>>>>>>>>") + ch, err := rabbit.Cfg.Pool.GetChannel() + if err != nil { + logx.Error(err) + return + } + defer ch.Release() + //1、将自己绑定到交换机上 + ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) + //2、取出数据进行消费 + ch.Qos(1) + delivery := ch.Consume(queue.Name, false) + + egg_system_rules.Init(cfg.RedisAddr) + var res amqp.Delivery + var ok bool + for { + res, ok = <-delivery + if ok == true { + err = handleEggEnergyDealUserVirtualCoinDataConsume(res.Body) + if err != nil { + fmt.Println("EggEnergyDealUserVirtualCoinDataConsume_ERR:::::", err.Error()) + utils2.FilePutContents("EggEnergyDealUserVirtualCoinDataConsume_ERR", utils2.SerializeStr(map[string]interface{}{ + "body": res.Body, + "err": err.Error(), + })) + } + //_ = res.Reject(false) + err = res.Ack(true) + fmt.Println("err ::: ", err) + } else { + panic(errors.New("error getting message")) + } + } + fmt.Println("get msg done") +} + +func handleEggEnergyDealUserVirtualCoinDataConsume(msgData []byte) error { + time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 + // 1.解析mq中queue的数据结构体 + var msg *md2.EggEnergyStructForDealUserVirtualCoinData + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + + engine := db.Db + session := engine.NewSession() + err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ + Kind: msg.Kind, + Title: msg.Title, + TransferType: msg.TransferType, + CoinId: msg.CoinId, + Uid: msg.Uid, + Amount: msg.Amount, + }) + if err != nil { + return err + } + + return nil +} diff --git a/consume/init.go b/consume/init.go index 52361ba..f10ce26 100644 --- a/consume/init.go +++ b/consume/init.go @@ -20,6 +20,7 @@ func initConsumes() { jobs[consumeMd.EggEnergyStartLevelDividendFunName] = EggEnergyStartLevelDividendConsume jobs[consumeMd.EggEnergyDealPlatformRevenueDataFunName] = EggEnergyDealPlatformRevenueDataConsume jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume + jobs[consumeMd.EggEnergyDealUserVirtualCoinDataFunName] = EggEnergyDealUserVirtualCoinDataConsume jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume } diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index 488b6be..4674cb4 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -38,6 +38,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "EggEnergyDealPlatformRevenueDataConsume", }, + { + ExchangeName: "egg.energy", + Name: "egg_deal_user_virtual_coin_queue", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "deal_user_virtual_coin", + BindKey: "", + ConsumeFunName: "EggEnergyDealUserVirtualCoinDataConsume", + }, { ExchangeName: "im.egg.energy", Name: "im_egg_energy_batch_send_message_queue", @@ -53,5 +62,6 @@ const ( EggEnergyStartLevelDividendFunName = "EggEnergyStartLevelDividendConsume" EggEnergyDealFundDataFunName = "EggEnergyDealFundDataConsume" EggEnergyDealPlatformRevenueDataFunName = "EggEnergyDealPlatformRevenueDataConsume" + EggEnergyDealUserVirtualCoinDataFunName = "EggEnergyDealUserVirtualCoinDataConsume" IMEggEnergyBatchSendMessageDataFunName = "IMEggEnergyBatchSendMessageDataConsume" ) diff --git a/go.mod b/go.mod index e339f64..5e88ebe 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241119093836-37be936b83fc + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128102555-fc839292d728 code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.2 code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 github.com/boombuler/barcode v1.0.1 From 3bccc65fc7644330c2dbe11b97f54549c1dab674 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 4 Dec 2024 18:43:09 +0800 Subject: [PATCH 5/5] add del friend circle comment --- ...g_energy_deal_user_virtual_coin_consume.go | 1 - consume/egg_energy_fund_data_consume.go | 1 - consume/egg_energy_platform_revenue_data.go | 1 - ...m_egg_energy_batch_send_message_consume.go | 1 - ...nergy_del_friend_circle_comment_consume.go | 77 +++++++++++++++++++ consume/init.go | 1 + consume/md/consume_key.go | 12 ++- go.mod | 1 + 8 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 consume/im_egg_energy_del_friend_circle_comment_consume.go diff --git a/consume/egg_energy_deal_user_virtual_coin_consume.go b/consume/egg_energy_deal_user_virtual_coin_consume.go index 625f736..874a465 100644 --- a/consume/egg_energy_deal_user_virtual_coin_consume.go +++ b/consume/egg_energy_deal_user_virtual_coin_consume.go @@ -53,7 +53,6 @@ func EggEnergyDealUserVirtualCoinDataConsume(queue md.MqQueue) { panic(errors.New("error getting message")) } } - fmt.Println("get msg done") } func handleEggEnergyDealUserVirtualCoinDataConsume(msgData []byte) error { diff --git a/consume/egg_energy_fund_data_consume.go b/consume/egg_energy_fund_data_consume.go index f4350e0..0898d01 100644 --- a/consume/egg_energy_fund_data_consume.go +++ b/consume/egg_energy_fund_data_consume.go @@ -57,7 +57,6 @@ func EggEnergyDealFundDataConsume(queue md.MqQueue) { panic(errors.New("error getting message")) } } - fmt.Println("get msg done") } func handleEggEnergyDealFundDataConsume(msgData []byte) error { diff --git a/consume/egg_energy_platform_revenue_data.go b/consume/egg_energy_platform_revenue_data.go index 2139714..f5cd933 100644 --- a/consume/egg_energy_platform_revenue_data.go +++ b/consume/egg_energy_platform_revenue_data.go @@ -57,7 +57,6 @@ func EggEnergyDealPlatformRevenueDataConsume(queue md.MqQueue) { panic(errors.New("error getting message")) } } - fmt.Println("get msg done") } func handleEggEnergyDealPlatformRevenueDataConsume(msgData []byte) error { diff --git a/consume/im_egg_energy_batch_send_message_consume.go b/consume/im_egg_energy_batch_send_message_consume.go index 39aaf1c..8127f5b 100644 --- a/consume/im_egg_energy_batch_send_message_consume.go +++ b/consume/im_egg_energy_batch_send_message_consume.go @@ -52,7 +52,6 @@ func IMEggEnergyBatchSendMessageDataConsume(queue md.MqQueue) { panic(errors.New("error getting message")) } } - fmt.Println("get msg done") } func handleIMEggEnergyBatchSendMessageDataConsume(msgData []byte) error { diff --git a/consume/im_egg_energy_del_friend_circle_comment_consume.go b/consume/im_egg_energy_del_friend_circle_comment_consume.go new file mode 100644 index 0000000..fa16e42 --- /dev/null +++ b/consume/im_egg_energy_del_friend_circle_comment_consume.go @@ -0,0 +1,77 @@ +package consume + +import ( + "applet/app/cfg" + utils2 "applet/app/utils" + "applet/app/utils/cache" + "applet/app/utils/logx" + "applet/consume/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git" + md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "time" +) + +func IMEggEnergyDelFriendCircleDataConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>IMEggEnergyDelFriendCircleDataConsume>>>>>>>>>>>>") + ch, err := rabbit.Cfg.Pool.GetChannel() + if err != nil { + logx.Error(err) + return + } + defer ch.Release() + //1、将自己绑定到交换机上 + ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) + //2、取出数据进行消费 + ch.Qos(1) + delivery := ch.Consume(queue.Name, false) + + egg_system_rules.Init(cfg.RedisAddr) + var res amqp.Delivery + var ok bool + for { + res, ok = <-delivery + if ok == true { + err = handleIMEggEnergyDelFriendCircleCommentDataConsume(res.Body) + if err != nil { + fmt.Println("IMEggEnergyDelFriendCircleDataConsume_ERR:::::", err.Error()) + utils2.FilePutContents("IMEggEnergyDelFriendCircleDataConsume_ERR", utils2.SerializeStr(map[string]interface{}{ + "body": res.Body, + "err": err.Error(), + })) + } + //_ = res.Reject(false) + err = res.Ack(true) + fmt.Println("err ::: ", err) + } else { + panic(errors.New("error getting message")) + } + } +} + +func handleIMEggEnergyDelFriendCircleCommentDataConsume(msgData []byte) error { + time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 + // 1.解析mq中queue的数据结构体 + var msg *md2.IMEggEnergyStructForDelFriendCircleCommentData + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + + //1、删除es数据 + _, err = es.DeleteDoc(md3.EggFriendCircleCommentEsAlias, msg.CommentIndexId) + if err != nil { + return err + } + + //2、删除redis数据 + key := fmt.Sprintf(md3.CommentLikeCacheKey, msg.CommentIndexId) + cache.Del(key) + return nil +} diff --git a/consume/init.go b/consume/init.go index f10ce26..6e1604b 100644 --- a/consume/init.go +++ b/consume/init.go @@ -22,6 +22,7 @@ func initConsumes() { jobs[consumeMd.EggEnergyDealFundDataFunName] = EggEnergyDealFundDataConsume jobs[consumeMd.EggEnergyDealUserVirtualCoinDataFunName] = EggEnergyDealUserVirtualCoinDataConsume jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume + jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume } func Run() { diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index 4674cb4..538de92 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -45,7 +45,7 @@ var RabbitMqQueueKeyList = []*MqQueue{ IsPersistent: false, RoutKey: "deal_user_virtual_coin", BindKey: "", - ConsumeFunName: "EggEnergyDealUserVirtualCoinDataConsume", + ConsumeFunName: "EggEnergyDealUserVirtualCoinDataConsume ", }, { ExchangeName: "im.egg.energy", @@ -56,6 +56,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "IMEggEnergyBatchSendMessageDataConsume", }, + { + ExchangeName: "im.egg.energy", + Name: "im_egg_energy_del_friend_comment_circle_queue", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "del_friend_circle_comment_data", + BindKey: "", + ConsumeFunName: "IMEggEnergyDelFriendCircleDataConsume", + }, } const ( @@ -64,4 +73,5 @@ const ( EggEnergyDealPlatformRevenueDataFunName = "EggEnergyDealPlatformRevenueDataConsume" EggEnergyDealUserVirtualCoinDataFunName = "EggEnergyDealUserVirtualCoinDataConsume" IMEggEnergyBatchSendMessageDataFunName = "IMEggEnergyBatchSendMessageDataConsume" + IMEggEnergyDelFriendCircleDataFunName = "IMEggEnergyDelFriendCircleDataConsume" ) diff --git a/go.mod b/go.mod index 5e88ebe..4aa97af 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( ) require ( + code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/bytedance/sonic v1.11.3 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect