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

相关推荐
过期动态1 分钟前
Java开发中的@EnableWebMvc注解和WebMvcConfigurer接口
java·开发语言·spring boot·spring·tomcat·maven·idea
CoLiuRs1 分钟前
语义搜索系统原理与实现
redis·python·向量·es
zhihuaba4 分钟前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python
u0109272715 分钟前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
csbysj202022 分钟前
Web 标准
开发语言
老姚---老姚38 分钟前
在windows下编译go语言编写的dll库
开发语言·windows·golang
diediedei1 小时前
模板编译期类型检查
开发语言·c++·算法
Stream_Silver1 小时前
【Agent学习笔记3:使用Python开发简单MCP服务】
笔记·python
穿过锁扣的风1 小时前
零基础入门 Python 爬虫:从基础到实战,爬取虎扑 / 豆瓣 / 图片全掌握
开发语言·爬虫·python
Stream_Silver1 小时前
【Agent学习笔记2:深入理解Function Calling技术:从原理到实践】
笔记·python