-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
43 lines (37 loc) · 1.09 KB
/
register.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package consumer
import (
"github.com/stubborn-gaga-0805/prepare2go/internal/mq/consumer/handle"
"github.com/stubborn-gaga-0805/prepare2go/internal/mq/contruct"
"github.com/stubborn-gaga-0805/prepare2go/pkg/logger"
"github.com/stubborn-gaga-0805/prepare2go/pkg/rabbitmq"
)
type OrderMsg struct {
Id int64 `json:"id"`
Tid int64 `json:"tid"`
Cid int64 `json:"cid"`
Sid int64 `json:"sid"`
OrderSn string `json:"order_sn"`
}
type Consumer struct {
AMQP *rabbitmq.AMQP
Logger *logger.Logger
Handle *handle.MqHandle
// 声明消费者
OrderConsumer *rabbitmq.Consumer // 订单
}
// register 注册消费者
func (c *Consumer) register() *Consumer {
c.OrderConsumer = rabbitmq.NewConsumer(c.AMQP, rabbitmq.ConsumerConfig{
Exchange: contruct.ExchangeGoFrameOrder,
RoutingKey: contruct.RoutingGoFrameOrder,
Queue: contruct.QueueGoFrameOrder,
AutoAck: true,
ResStruct: OrderMsg{},
Handel: c.Handle.TestOrderSyncConsumer,
}).SetName("order-consumer").Start()
return c
}
func (c *Consumer) Run() *Consumer {
c.register().AMQP.StartConsumer()
return c
}