Commit 337b8350 by huangchengyi

1.0

parent 5d847e7f
package main
import (
"fmt"
"github.com/ichunt2019/go-msgserver/utils/rabbitmq"
"time"
)
type RecvPro struct {
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
fmt.Println(string(dataByte))
//return errors.New("顶顶顶顶")
return nil
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(dataByte []byte) error {
fmt.Println(string(dataByte))
fmt.Println("任务处理失败了,我要进入db日志库了")
fmt.Println("任务处理失败了,发送钉钉消息通知主人")
return nil
}
func main() {
//消费者实现 下面接口即可
//type Receiver interface {
// Consumer([]byte) error
//}
print("开始")
t := &RecvPro{}
queueExchange := &rabbitmq.QueueExchange{
"szpurchase_message_tasks",
"szpurchase_message_tasks",
"szpurchase_message_tasks",
"direct",
"amqp://guest:guest@192.168.2.232:5672/",
}
print("3333434")
for{
print("")
mq := rabbitmq.New(queueExchange)
mq.RegisterReceiver(t)
err :=mq.Start()
if err != nil{
fmt.Println(err)
}
time.Sleep(time.Second)
}
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/ichunt2019/go-msgserver v1.0.5 // indirect
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/logger v1.0.5
github.com/imroc/req v0.3.0
......@@ -53,6 +54,7 @@ require (
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85
gopkg.in/yaml.v2 v2.3.0 // indirect
labix.org/v2/mgo v0.0.0-20140701140051-000000000287 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb
)
......
......@@ -108,6 +108,7 @@ type DullGoodsData struct {
GoodsUrl string `json:"goods_url"`
CompanyName string `json:"-"`
ProviderName string `json:"-"`
Attrs interface{} `json:"attrs"`
}
type Attr struct {
......
......@@ -185,7 +185,24 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
}
common.PrintDebugHtml(ctx,esResult)
goodsIds := GetGoodsIdsByEs(esResult)
goodsIds := make([]string,0) //goods_id
attrs := make(map[string][]map[string]string) //属性
gjArray := gjson.Get(esResult, "hits.hits.#._source").Array()
for _, item := range gjArray {
goods_id := item.Get("goods_id").String()
goodsIds = append(goodsIds, goods_id)
temp := make([]map[string]string,0)
for _,attr := range item.Get("attrs").Array() {
temp = append(temp, map[string]string{
"attr_name":attr.Get("attr_name").String(),
"attr_value":attr.Get("attr_value").String(),
})
}
attrs[goods_id] = temp
}
//判断返回总条数
total := gjson.Get(esResult, "hits.total").Int()
if total == 0 {
......@@ -229,6 +246,7 @@ func (qs *OptimumService) GetOptimumAttrInfo(ctx *gin.Context) (results model.Ly
ApiGoods:v,
GoodsUrl: GoodsUrl,
BrandUrl: BrandUrl,
Attrs: attrs[v.GoodsId],
})
}
......
......@@ -82,7 +82,7 @@ func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,type
}
}
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id")) //显示字段
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id","attrs")) //显示字段
source.Size(common.MyInt(page_size))
source.From(page_from)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment