如何在activemq中杀死消费者

2024-01-01

我试图摆脱某个队列中的所有“消费者数量”。每当我清除/删除队列时,如果我再次创建同名的队列,消费者的数量仍然保留。即使有 0 条待处理消息,仍然有 6 个消费者。

我的问题可能源于我的 java 代码,但没有关闭会话或连接。

我已经尝试过重新启动和重新安装服务器。

这是我的生产者代码:

 private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;

    public static String addElementToQueue(String queueName,String param1, String param2) throws JMSException, NamingException {
  // Getting JMS connection from the server and starting it
        ConnectionFactory connectionFactory =
                new ActiveMQConnectionFactory(url);
        Connection connection = connectionFactory.createConnection();

// JMS messages are sent and received using a Session. We will
        // create here a non-transactional session object. If you want
        // to use transactions you should set the first parameter to 'true'
        Session session = connection.createSession(false,
                Session.AUTO_ACKNOWLEDGE);

        // Destination represents here our queue on the
        // JMS server. You don't have to do anything special on the
        // server to create it, it will be created automatically.
        Destination destination = session.createQueue(queueName);

        // MessageProducer is used for sending messages (as opposed
        // to MessageConsumer which is used for receiving them)
        MessageProducer producer = session.createProducer(destination);   

        String queueMessage = param1+ "-" + param2;

        TextMessage message = session.createTextMessage(queueMessage);

        // Here we are sending the message!
        producer.send(message);

        connection.close();
        session.close();      // added after problem came up
        producer.close();     // added after problem came up

        return commandID;
}

这是我的消费者代码:

 // URL of the JMS server
    private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;

    public static Pair consumeNextElement(String queueName) throws JMSException {
        // Getting JMS connection from the server
        ConnectionFactory connectionFactory
                = new ActiveMQConnectionFactory(url);
        Connection connection = connectionFactory.createConnection();
        connection.start();   

        // Creating session for seding messages
        Session session = connection.createSession(false,
                Session.AUTO_ACKNOWLEDGE);

        // Getting the queue
        Destination destination = session.createQueue(queueName);

        // MessageConsumer is used for receiving (consuming) messages
        MessageConsumer consumer = session.createConsumer(destination);


        // Here we receive the message.
        // By default this call is blocking, which means it will wait
        // for a message to arrive on the queue.
        Message message = consumer.receive();

        // There are many types of Message and TextMessage
        // is just one of them. Producer sent us a TextMessage
        // so we must cast to it to get access to its .getText()
        // method.

        String[] parts = ((TextMessage)message).getText().split("-");
        Pair retVal = new Pair(parts[0], parts[1]);

        connection.close();
        session.close();        // added after problem came up
        consumer.close();      // added after problem came up  

        return retVal;
    }

有什么想法吗?

Thanks.


消费者的数量是队列上侦听器的数量。清除队列应该只删除排队的消息 - 那些监听的消费者将不受影响。

消费者维持/重新建立连接的能力可能取决于用于连接的传输,并且运输设置 http://activemq.apache.org/configuring-transports.html可能允许对连接属性进行一些调整。

坦率地说,我对这些没有太多经验,但你可以调查一下咨询信息 http://activemq.apache.org/advisory-message.html作为帮助调试连接的一种方法。除了报告消费者数量之外,JMX 界面或 Web 控制台似乎没有什么帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在activemq中杀死消费者 的相关文章

随机推荐

  • 在 PHP 中使用heredoc有什么好处? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • Jquery 如果单选按钮被选中

    可能的重复 检查特定单选按钮是否已选中 https stackoverflow com questions 2195125 check of specific radio button is checked 我目前有这 2 个单选按钮 以便
  • nginx 和带有代理传递的尾部斜杠

    我对 nginx 1 4 1 使用以下配置 server listen 8000 server name correct name gr location test register proxy set header X Forwarded
  • WPF 按钮图标被镜像,为什么?

    当按如下方式定义图像时 此按钮看起来不错 请参见屏幕截图 请注意 带有字母 T 的盾形图标已正确显示
  • getnameinfo() - 反向 DNS 查找(IP 地址到主机名)C/C++

    对于 IPAddress 66 249 68 9 dig x 正确地说 crawl 66 249 68 9 googlebot com 我可爱的程序声称它是 ip68 9 0 0 ri ri cox net 我不在乎我最终是否会采用类似于下
  • 获取内存制造商

    有谁知道如何以编程方式检索 RAM 内存制造商 Thanks 现代 RAM 芯片上有一个附加的 EPROM 其中包含有关 RAM 的大量信息 其标准是 SPD 即串行存在检测 至少某些版本的 SPD 包含 JDEC 制造商代码 Look a
  • VBA“编译错误:语句在类型块之外无效”

    我正在 Excel 2010 中运行 VBA 宏并进行大量计算 因此数据类型非常重要 以尽可能缩短宏执行时间 我的优化想法是让用户选择所有数字将被声明为什么数据类型 同时指出每种数据类型的优缺点 准确性 灵活性和CPU密集度 宏执行时间之间
  • 为什么 matplotlib.pyplot.imshow 改变它的轴?

    我尝试在不同的子图中绘制图像 但由于某种原因 图像的轴在绘制时发生变化 为了演示这一点 在下面的示例中 我将图像绘制在 4 2 子图网格中 并不断检查第一张图像的轴是否保持不变 import matplotlib pyplot as plt
  • 为什么 WildFly 10 + JSF 2.3 无法与 Omnifaces 2.6.1 配合使用?

    我一直在尝试在 Wildfly 10 上使用 jsf 2 3 primefaces 6 和omnifaces 2 6 1 启动并运行一个应用程序 我已经拆分了 jsf 2 3 api 和 impl 并完成了 WildFly 的设置 应用程序
  • onItemClick strings.xml(不是 ListView/ArrayList)

    我有一个 on strings xml 文件 所有条目都显示在 ListView 上 现在我想对每个项目触摸 单击进行处理 我已经纠正了这段代码 gt public void onCreate Bundle savedInstanceSta
  • iOS 7 iAd 插页式广告无法被用户关闭

    当我显示插页式广告时 interstitial presentFromViewController self 我收到警告说此方法在 iOS 7 中已弃用 但它仍然可以正常工作 当我显示广告视图时 self requestInterstiti
  • SWIFT ALAssetsLibrary 未枚举组

    我试图将所有用户图像的缩略图收集到一个数组中 但是当我调用enumerateAssetsUsingBlock的方法ALAssetsLibrary似乎什么也没发生 import UIKit import AssetsLibrary class
  • Swing:GlassPane 防止鼠标指针改变

    我有一个 JTabbedPane 其中有一些选项卡以及选项卡旁边有很多未使用的额外空间 所以我尝试使用它并在那里放置一些按钮 就像在 Eclipse 中一样 我将按钮放在 GlassPane 上 JPanel glasspane getPa
  • Keras 中的自定义损失函数应该为批次返回单个损失值,还是为训练批次中的每个样本返回一系列损失?

    我正在学习tensorflow 2 3 中的keras API 在这个guide https www tensorflow org guide keras train and evaluate custom losses在tensorflo
  • 在 R 中使用 apply 和 allocate

    考虑以下示例 Vars lt c car bike lorry Dat lt c 10 20 22 for i in 1 length Vars assign Vars i Dat i 在这里 我想在工作区中生成三个变量 根据中的条目命名V
  • 如何使用正则表达式忽略空格?

    这是我的正则表达式 SK 1 0 9 8 但我想要这样的文字 SK 283 92758 SK 283 92 7 58 可以这样理解 SK28392758 有可能的 使用 可选 量词 每个字符之间有一个空格 S K d 7 d 这允许字符之间
  • Visual Studio 代码格式化程序

    我使用 Visual Studio 2008 来处理 C 和 JavaScript AJAXy 的东西 这是我的问题 我喜欢 Eclipse 尤其是格式化的代码 Ctrl Shift F 相比之下 Visual Studio 的 Ctrl
  • 有人能为我解释一下这个递归吗?

    我从 leetcode 得到了这个代码 class Solution object def myPow self x n if n 0 return 1 if n 1 return 1 x return self myPow x x n 2
  • 将 #define 常量转换为字符串

    我定义了一个常量 define MAX STR LEN 100 我正在尝试这样做 scanf MAX STR LEN s p buf 但这当然行不通 可以使用什么预处理器技巧将 MAX STR LEN 数字转换为字符串 以便我可以在上面的
  • 如何在activemq中杀死消费者

    我试图摆脱某个队列中的所有 消费者数量 每当我清除 删除队列时 如果我再次创建同名的队列 消费者的数量仍然保留 即使有 0 条待处理消息 仍然有 6 个消费者 我的问题可能源于我的 java 代码 但没有关闭会话或连接 我已经尝试过重新启动