|
@@ -16,6 +16,8 @@ import ( |
|
|
"xorm.io/xorm" |
|
|
"xorm.io/xorm" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var data []*model.MasterAreaVisitsFlows |
|
|
|
|
|
|
|
|
func ZhiOsUserVisitIpAddressConsume(queue md.MqQueue) { |
|
|
func ZhiOsUserVisitIpAddressConsume(queue md.MqQueue) { |
|
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>") |
|
|
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>") |
|
|
ch, err := rabbit.Cfg.Pool.GetChannel() |
|
|
ch, err := rabbit.Cfg.Pool.GetChannel() |
|
@@ -27,7 +29,7 @@ func ZhiOsUserVisitIpAddressConsume(queue md.MqQueue) { |
|
|
//1、将自己绑定到交换机上 |
|
|
//1、将自己绑定到交换机上 |
|
|
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) |
|
|
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) |
|
|
//2、取出数据进行消费 |
|
|
//2、取出数据进行消费 |
|
|
ch.Qos(1) |
|
|
|
|
|
|
|
|
ch.Qos(10) |
|
|
delivery := ch.Consume(queue.Name) |
|
|
delivery := ch.Consume(queue.Name) |
|
|
|
|
|
|
|
|
var res amqp.Delivery |
|
|
var res amqp.Delivery |
|
@@ -40,6 +42,10 @@ func ZhiOsUserVisitIpAddressConsume(queue md.MqQueue) { |
|
|
err = handleUserVisitIpAddress(res.Body) |
|
|
err = handleUserVisitIpAddress(res.Body) |
|
|
//_ = res.Reject(false) |
|
|
//_ = res.Reject(false) |
|
|
_ = res.Ack(true) |
|
|
_ = res.Ack(true) |
|
|
|
|
|
if len(data) >= 100 { |
|
|
|
|
|
db.BatchAddMasterAreaVisitsFlows(db.DataDb, data) |
|
|
|
|
|
data = []*model.MasterAreaVisitsFlows{} |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
panic(errors.New("error getting message")) |
|
|
panic(errors.New("error getting message")) |
|
|
} |
|
|
} |
|
@@ -78,7 +84,7 @@ func handleUserVisitIpAddress(msg []byte) error { |
|
|
if cityName == "" { |
|
|
if cityName == "" { |
|
|
cityName = msgStruct.City |
|
|
cityName = msgStruct.City |
|
|
} |
|
|
} |
|
|
db.MasterAreaVisitsFlowsInsert(db.DataDb, &model.MasterAreaVisitsFlows{ |
|
|
|
|
|
|
|
|
data = append(data, &model.MasterAreaVisitsFlows{ |
|
|
Ip: msgStruct.Ip, |
|
|
Ip: msgStruct.Ip, |
|
|
MasterId: utils.StrToInt(msgStruct.MasterId), |
|
|
MasterId: utils.StrToInt(msgStruct.MasterId), |
|
|
Date: today, |
|
|
Date: today, |
|
@@ -90,6 +96,7 @@ func handleUserVisitIpAddress(msg []byte) error { |
|
|
CreateAt: now, |
|
|
CreateAt: now, |
|
|
UpdateAt: now, |
|
|
UpdateAt: now, |
|
|
}) |
|
|
}) |
|
|
|
|
|
//db.MasterAreaVisitsFlowsInsert(db.DataDb, ) |
|
|
} |
|
|
} |
|
|
//4、加入到缓存map中 |
|
|
//4、加入到缓存map中 |
|
|
cache.HSet(cacheKey, msgStruct.Ip, msgStruct.MasterId) |
|
|
cache.HSet(cacheKey, msgStruct.Ip, msgStruct.MasterId) |
|
|