python rabbitmq 手动ack

python 复制代码
# -*- coding: utf-8 -*-
# @Time    : 2023/8/10 21:27
# @Author  : Cocktail_py
import json

import pika

url = "amqp://user:pass@host:port"
queue_name = "myquename"
connection = pika.BlockingConnection(pika.URLParameters(url))
channel = connection.channel()


def get_queue_list():
    """批量获取数据"""
    queue_list = []
    # durable是否绑定队列
    channel.queue_declare(queue=queue_name, durable=True)

    # 绑定交换机
    # channel.queue_bind(queue=queue_name,exchange="",routing_key="")

    def callback(ch, method, properties, body):
        print(f" [x] Received {body}")
        queue_list.append(json.loads(body))
        # ch.basic_ack(delivery_tag=method.delivery_tag)

    # 单次获取数量
    channel.basic_qos(prefetch_count=100)
    channel.basic_consume(on_message_callback=callback, queue=queue_name)
    connection.process_data_events()
    return queue_list


channel.basic_ack(multiple=True)
connection.close()

Centos 安装 RabbitMQ

rabbitmq-doc

相关推荐
音符犹如代码2 小时前
Java动态线程池:避坑原生线程池,吃透Dynamic-TP,手写一个Demo
java·开发语言
喜欢就别2 小时前
平均风险:Rényi DP 和零集中 DP
开发语言·r语言
千天夜2 小时前
深入剖析 `Path(path).parent.mkdir(parents=True, exist_ok=True)` —— 优雅处理目录创建的终极方案
python
无足鸟ICT2 小时前
【RHCA+】bash命令
linux·开发语言·bash
简~7682 小时前
python for in循环不能遍历整数怎么解决
python·大学生
aiqianji3 小时前
垂直专业的AI短篇小说写作软件有哪些特点?
人工智能·python
方华世界3 小时前
企业级Java AI Agent应用平台
java·开发语言·人工智能
aqi003 小时前
15天学会AI应用开发(十三)上下文与RAG的阶段性总结
人工智能·python·大模型·ai编程·ai应用
程序员杰哥3 小时前
接口测试知识总结
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试