2 Star 2 Fork 0

Super 9du/ezmq

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
easy_test.go 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
Wolf Liu 提交于 2022-06-28 14:50 . add license to head of all sourse code
// ezmq: An easy golang amqp client.
// Copyright (C) 2022 super9du
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; If not, see <https://www.gnu.org/licenses/>.
package ezmq
import (
"github.com/streadway/amqp"
"log"
"time"
)
func ExampleConsumer_Receive() {
conn := getConnection()
consumer := conn.Consumer()
consumer.Receive(
"queue.direct",
NewReceiveOptsBuilder().SetAutoAck(false).Build(),
&AbsReceiveListener{
ConsumerMethod: func(delivery *amqp.Delivery) (brk bool) {
log.Println("queue.direct ", delivery.DeliveryTag, " ", string(delivery.Body))
err := delivery.Ack(false)
if err != nil {
log.Println(err)
}
return
},
FinishMethod: func(err error) {
if err != nil {
// 处理错误
return
}
// defer xxx.close() // 关闭资源操作等
},
})
time.Sleep(time.Minute) // 由于 Consumer.Receive() 内部采用了异步方式处理,因此 Receive 方法不会阻塞等待
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/super9du/ezmq.git
git@gitee.com:super9du/ezmq.git
super9du
ezmq
ezmq
main

搜索帮助