diff --git a/rabbit/pool.go b/rabbit/pool.go index 218a421..846e7d8 100644 --- a/rabbit/pool.go +++ b/rabbit/pool.go @@ -400,6 +400,27 @@ func (ch *Channel) Publish(exchange string, body interface{}, key string) { 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 { c, e := ch.Channel.Consume(