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

相关推荐
Warson_L10 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅10 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅10 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L10 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅10 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L11 小时前
python的类&继承
python
Warson_L11 小时前
类型标注/type annotation
python
ThreeS13 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵15 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏