Selaa lähdekoodia

update

master
dengbiao 3 kuukautta sitten
vanhempi
commit
2506cac17a
1 muutettua tiedostoa jossa 28 lisäystä ja 30 poistoa
  1. +28
    -30
      consume/one_circles_sign_in_consume.go

+ 28
- 30
consume/one_circles_sign_in_consume.go Näytä tiedosto

@@ -12,8 +12,6 @@ import (
"errors"
"fmt"
"github.com/streadway/amqp"
"os"
"runtime/pprof"
)

func OneCirclesSignInGreenEnergyConsume(queue md.MqQueue) {
@@ -34,44 +32,44 @@ func OneCirclesSignInGreenEnergyConsume(queue md.MqQueue) {

var res amqp.Delivery
var ok bool
//for {
res, ok = <-delivery
if ok == true {
err = handleOneCirclesSignInGreenEnergy(ch, res.Body)
if err != nil {
fmt.Println("err ::: ", err)
utils.FilePutContents("OneCirclesSignInGreenEnergyConsume_ERR", "[err]:"+err.Error())
_ = res.Reject(true)
//_ = res.Reject(false)
////TODO::重新推回队列末尾,避免造成队列堵塞
//var msg *md.OneCirclesStructForSignIn
//json.Unmarshal(res.Body, &msg)
//ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
for {
res, ok = <-delivery
if ok == true {
err = handleOneCirclesSignInGreenEnergy(ch, res.Body)
if err != nil {
fmt.Println("err ::: ", err)
utils.FilePutContents("OneCirclesSignInGreenEnergyConsume_ERR", "[err]:"+err.Error())
_ = res.Reject(true)
//_ = res.Reject(false)
////TODO::重新推回队列末尾,避免造成队列堵塞
//var msg *md.OneCirclesStructForSignIn
//json.Unmarshal(res.Body, &msg)
//ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
} else {
_ = res.Ack(true)
}
} else {
_ = res.Ack(true)
panic(errors.New("error getting message"))
}
} else {
panic(errors.New("error getting message"))
}
//}
fmt.Println("get msg done")
}

func handleOneCirclesSignInGreenEnergy(ch *rabbit.Channel, msgData []byte) error {
cpuProfile, err := os.Create("./cpu_profile")
if err != nil {
fmt.Printf("创建文件失败:%s", err.Error())
return err
}
defer cpuProfile.Close()
//采集CPU信息
pprof.StartCPUProfile(cpuProfile)
defer pprof.StopCPUProfile()
//cpuProfile, err := os.Create("./cpu_profile")
//if err != nil {
// fmt.Printf("创建文件失败:%s", err.Error())
// return err
//}
//defer cpuProfile.Close()
//
////采集CPU信息
//pprof.StartCPUProfile(cpuProfile)
//defer pprof.StopCPUProfile()

//1、解析mq中queue的数据结构体
var msg *md.OneCirclesStructForSignIn
err = json.Unmarshal(msgData, &msg)
err := json.Unmarshal(msgData, &msg)
if err != nil {
return err
}


Ladataan…
Peruuta
Tallenna