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

相关推荐
Y1rong42 分钟前
C++ QT之记事本
开发语言·qt
吴佳浩3 小时前
大模型量化部署终极指南:让700亿参数的AI跑进你的显卡
人工智能·python·gpu
diegoXie4 小时前
Python / R 向量顺序分割与跨步分割
开发语言·python·r语言
程序员小白条4 小时前
0经验如何找实习?
java·开发语言·数据结构·数据库·链表
七牛云行业应用4 小时前
解决OSError: No space left... 给DeepSeek Agent装上无限云硬盘
python·架构设计·七牛云·deepseek·agent开发
liulilittle4 小时前
C++ 浮点数封装。
linux·服务器·开发语言·前端·网络·数据库·c++
BoBoZz195 小时前
CutWithScalars根据标量利用vtkContourFilter得到等值线
python·vtk·图形渲染·图形处理
失散135 小时前
Python——1 概述
开发语言·python
萧鼎5 小时前
Python 图像哈希库 imagehash——从原理到实践
开发语言·python·哈希算法
qq_251533595 小时前
使用 Python 提取 MAC 地址
网络·python·macos