Python。如何从队列/主题ActiveMQ中删除任何消息

2024-09-28 20:17:29 发布

您现在位置:Python中文网/ 问答频道 /正文

ActiveMQ用于发送主题(topic)和队列(queue)中的消息。在

我有两个问题:

  1. 如何delete(取消操作)发送到队列或 主题。在
  2. 如何remove和{}完全所有队列/主题。在

使用通过协议STOMP stompy库组织的AMQ,但是没有合适的functions

告诉我应该使用什么库或解决方案本身。在

非常感谢。在


Tags: 消息协议主题topic队列queue解决方案functions
1条回答
网友
1楼 · 发布于 2024-09-28 20:17:29

如何删除消息我知道,但只是理论上的(通过WireShark分析包流量的结果,工作浏览器在页面中本地主机:8161\admin在AMQ管理页面ActiveMQ),我不能以编程方式删除msg(Python)。在

理论上我可以在AMQ中用param.[id,secret]调用(我在packege中看到这个,packege在删除时发送到\admin AMQ)deleteMessage(), 在哪里

  • id-队列\主题中消息的唯一名称
  • secret-唯一号码(可能是一些“令牌”),每次更新时都会更改(例如F5)\admin\browse页。我说不出是什么。。。。在

请看图片:https://ru.stackoverflow.com/q/618697/228254在我的回答下来的帖子。在

示例测试队列:

  • id:id:##################################
  • 机密:1dbd2916-337a-48cc-bce7-63000D38BA3

此时,我的设计变体是:getallmsg in the queue and ACK msg,我想将其从队列中删除。在

这是我的简单客户代码:

from stompy import stomp
import json


s = stomp.Stomp(amq_ip, amq_port)

try:
    s.connect(username=amq_user, password=amq_pass)
    s.subscribe({'destination': '%s' % amq_queue, 'ack': 'client'})
except Exception as e:
    print "ActiveMQ error\n %s" % e

while True:
    try:
        frame = s.receive_frame()
        body = json.loads(frame.body)

        # это сообщение для меня?
        if body["interested_atr_in_msg"] == "interested_value_of_attr_in_msg":
            print "Its for me. I receive it"
            # Это сообщение для меня. Я его приму и обработаю
            s.ack(frame)
        else:
            # Это сообщение предназначено для кого-то другого и мне не подходит
            print "Its not for me"
    except Exception as e:
        print e

还添加了从队列中删除消息的实验测试代码(不起作用,不删除)

^{pr2}$

相关问题 更多 >