Browse Source

update

tags/v0.0.5
DengBiao 10 months ago
parent
commit
1705a83fd1
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      rabbit/pool.go

+ 21
- 0
rabbit/pool.go View File

@@ -400,6 +400,27 @@ func (ch *Channel) Publish(exchange string, body interface{}, key string) {
failOnError(e, "向路由发送消息失败!") failOnError(e, "向路由发送消息失败!")
} }


// PublishV2 向exchange发送消息
// 可以往某个exchange发送消息
func (ch *Channel) PublishV2(exchange string, body interface{}, key string) error {
str, e := json.Marshal(body)
if e != nil {
return e
}
e = ch.Channel.Publish(
exchange,
key,
false,
false,
amqp.Publishing{
ContentType: "text/plain",
DeliveryMode: amqp.Transient,
Priority: 0,
Body: []byte(str)},
)
return e
}

// 接收某个消息队列的消息 // 接收某个消息队列的消息
func (ch *Channel) Consume(name string, autoAck bool) <-chan amqp.Delivery { func (ch *Channel) Consume(name string, autoAck bool) <-chan amqp.Delivery {
c, e := ch.Channel.Consume( c, e := ch.Channel.Consume(


Loading…
Cancel
Save