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

相关推荐
渣渣xiong1 小时前
从零开始:前端转型AI agent直到就业第五十七天-第五十八天
前端·人工智能·python
吃好睡好便好1 小时前
创建魔方矩阵和单位矩阵
开发语言·人工智能·学习·线性代数·matlab·矩阵
影寂ldy2 小时前
C#数组的属性和方法(Clear / Copy / IndexOf )
开发语言·javascript·c#
i7i8i9com2 小时前
Hermes Agent 安装记录
开发语言·bash·hermes
小娄~~2 小时前
C语言卷子错题集
c语言·开发语言·数据结构
小L~~~2 小时前
基于贪心策略的混合遗传算法求解01背包问题
python·算法
才兄说2 小时前
机器人二次开发机器人动作定制?动作迁移数据优化
python
用户8356290780513 小时前
用 Python 实现 Excel 散点图绘制与定制
后端·python
PAK向日葵3 小时前
从零实现 Python 虚拟机(一):PVM 基本原理介绍
python
神所夸赞的夏天3 小时前
创建虚拟环境提示SSLError错误
python