java activemq jmx_通过JMX 获取Activemq 队列信息

首先在 activemq.xml 中新增以下属性

在broker 节点新增属性 useJmx="true"

在managementContext 节点配置断开与访问服务iP

配置成功后启动

下面来看测试代码

/**

* @Title: ActivemqTest.java

* @Package activemq

* @Description: TODO(用一句话描述该文件做什么)

* @author LYL

* @date 下午2:25:59

* @version V1.0

*/

package activemq;

import java.io.IOException;

import java.net.MalformedURLException;

import java.util.HashMap;

import java.util.Map;

import javax.management.MBeanServerConnection;

import javax.management.MBeanServerInvocationHandler;

import javax.management.ObjectName;

import javax.management.remote.JMXConnector;

import javax.management.remote.JMXConnectorFactory;

import javax.management.remote.JMXServiceURL;

import org.apache.activemq.broker.jmx.BrokerViewMBean;

import org.apache.activemq.broker.jmx.QueueViewMBean;

/**

* @Title: ActivemqTest.java

* @Package activemq

* @Description: TODO(用一句话描述该文件做什么)

* @author LYL

* @date 下午2:25:59

* @version V1.0

*/

public class ActivemqTest {

public static void main(String[] args) throws Exception {

String ip = "127.0.0.1:8188";

String url = String.format("service:jmx:rmi:///jndi/rmi://%s/jmxrmi",ip);

Map credentials = new HashMap<>();

// credentials.put(JMXConnector.CREDENTIALS, new String[] {"admin", "admin"});

JMXServiceURL urls = new JMXServiceURL(url);

JMXConnector connector = JMXConnectorFactory.connect(urls,credentials);

connector.connect();

MBeanServerConnection conn = connector.getMBeanServerConnection();

ObjectName name = new ObjectName("org.apache.activemq:brokerName=localhost,type=Broker");

BrokerViewMBean mBean = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(conn, name, BrokerViewMBean.class, true);

ObjectName[] pAry = mBean.getQueueSubscribers();

for (ObjectName objectName : pAry) {

}

ObjectName[] ary = mBean.getQueues();

for (ObjectName objectName : ary) {

QueueViewMBean queueBean = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance(conn, objectName, QueueViewMBean.class, true);

System.out.println("队列的名称:"+queueBean.getName());

System.out.println("消息积压数:"+queueBean.getQueueSize());

System.out.println("入队:"+queueBean.getEnqueueCount());

System.out.println("出队:"+queueBean.getDequeueCount());

System.out.println("消费者数:"+queueBean.getConsumerCount());

System.out.println("生产者数:"+queueBean.getProducerCount());

}

}

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/392426.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

风能matlab仿真_发现潜力:使用计算机视觉对可再生风能发电场的主要区域进行分类(第1部分)

风能matlab仿真Github Repo: https://github.com/codeamt/WindFarmSpotterGithub回购&#xff1a; https : //github.com/codeamt/WindFarmSpotter This is a series:这是一个系列&#xff1a; Part 1: A Brief Introduction on Leveraging Edge Devices and Embedded AI to …

【Leetcode_easy】821. Shortest Distance to a Character

problem 821. Shortest Distance to a Character 参考 1. Leetcode_easy_821. Shortest Distance to a Character; 完转载于:https://www.cnblogs.com/happyamyhope/p/11214805.html

tdd测试驱动开发课程介绍_测试驱动开发的实用介绍

tdd测试驱动开发课程介绍by Luca Piccinelli通过卢卡皮奇内利 测试驱动开发很难&#xff01; 这是不为人知的事实。 (Test Driven Development is hard! This is the untold truth about it.) These days you read a ton of articles about all the advantages of doing Test …

软件安装(JDK+MySQL+TOMCAT)

一&#xff0c;JDK安装 1&#xff0c;查看当前Linux系统是否已经安装了JDK 输入 rpm -qa | grep java 如果有&#xff1a; 卸载两个openJDK&#xff0c;输入rpm -e --nodeps 要卸载的软件 2&#xff0c;上传JDK到Linux 3&#xff0c;安装jdk运行需要的插件yum install gl…

leetcode 205. 同构字符串(hash)

给定两个字符串 s 和 t&#xff0c;判断它们是否是同构的。 如果 s 中的字符可以被替换得到 t &#xff0c;那么这两个字符串是同构的。 所有出现的字符都必须用另一个字符替换&#xff0c;同时保留字符的顺序。两个字符不能映射到同一个字符上&#xff0c;但字符可以映射自己…

Java core 包_feilong-core 让Java开发更简便的工具包

## 背景在JAVA开发过程中,经常看到小伙伴直接从网上copy一长段代码来使用,又或者写的代码很长很长很长...**痛点在于:*** 难以阅读* 难以维护* sonar扫描结果债务长* codereview 被小伙伴鄙视* ....feilong-core focus on J2SE,是[feilong platform](https://github.com/venusd…

TensorFlow 2.X中的动手NLP深度学习模型准备

简介&#xff1a;为什么我写这篇文章 (Intro: why I wrote this post) Many state-of-the-art results in NLP problems are achieved by using DL (deep learning), and probably you want to use deep learning style to solve NLP problems as well. While there are a lot …

静态代码块

静态代码块 静态代码块&#xff1a;定义在成员位置&#xff0c;使用static修饰的代码块{ }。位置&#xff1a;类中方法外。执行&#xff1a;随着类的加载而执行且执行一次&#xff0c;优先于main方法和构造方法的执行。格式&#xff1a;作用&#xff1a; 给类变量进行初始化赋值…

异步api_如何设计无服务器异步API

异步apiby Garrett Vargas通过Garrett Vargas 如何设计无服务器异步API (How To Design a Serverless Async API) I recently ran a workshop to teach developers how to create an Alexa skill. The workshop material centered around a project to return car rental sear…

C# 序列化与反序列化json

与合作伙伴讨论问题&#xff0c;说到的c与c#数据的转换调用&#xff0c;正好就说到了序列化与反序列化&#xff0c;同样也可用于不同语言间的调用&#xff0c;做了基础示例&#xff0c;作以下整理&#xff1a; 1 using System.Data;2 using System.Drawing;3 using System.Linq…

学java 的要点_零基础学Java,掌握Java的基础要点

对于程序员群体来说&#xff0c;了解一定的技巧会对学习专业技能更有帮助&#xff0c;也更有助于在自己的职业发展中处于有利地位&#xff0c;无限互联Java培训专家今天就为大家总结Java程序员入门时需要掌握的基础要点&#xff1a;掌握静态方法和属性静态方法和属性用于描述某…

实验人员考评指标_了解实验指标

实验人员考评指标In the first part of my series on experimental design Thinking About Experimental Design, we covered the foundations of an experiment: the goals, the conditions, and the metrics. In this post, we will move away from the initial experimental…

leetcode 188. 买卖股票的最佳时机 IV(dp)

给定一个整数数组 prices &#xff0c;它的第 i 个元素 prices[i] 是一支给定的股票在第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你最多可以完成 k 笔交易。 注意&#xff1a;你不能同时参与多笔交易&#xff08;你必须在再次购买前出售掉之前的股票&#xf…

kotlin编写后台_在Kotlin编写图书馆的提示

kotlin编写后台by Adam Arold亚当阿罗德(Adam Arold) 在Kotlin编写图书馆的提示 (Tips for Writing a Library in Kotlin) Writing a library in Kotlin seems easy but it can get tricky if you want to support multiple platforms. In this article we’ll explore ways f…

1.Swift教程翻译系列——关于Swift

英文版PDF下载地址http://download.csdn.net/detail/tsingheng/7480427 我本来是做JAVA的。可是有一颗折腾的心&#xff0c;苹果公布Swift以后就下载了苹果的开发文档。啃了几天。朦朦胧胧的看了个几乎相同&#xff0c;想静下心看能不能整个翻译出来。我英语一般般&#xff0c;…

核心技术java基础_JAVA核心技术I---JAVA基础知识(集合set)

一&#xff1a;集合了解(一)确定性&#xff0c;互异性&#xff0c;无序性确定性&#xff1a;对任意对象都能判定其是否属于某一个集合互异性&#xff1a;集合内每个元素都是无差异的&#xff0c;注意是内容差异无序性&#xff1a;集合内的顺序无关(二)集合接口HashSet&#xff…

nba数据库统计_NBA板块的价值-从统计学上讲

nba数据库统计The idea is not to block every shot. The idea is to make your opponent believe that you might block every shot. — Bill Russel这个想法不是要阻止每一个镜头。 这个想法是让你的对手相信你可能会阻挡每一个投篮。 —比尔罗素 The block in basketball ha…

leetcode 330. 按要求补齐数组(贪心算法)

给定一个已排序的正整数数组 nums&#xff0c;和一个正整数 n 。从 [1, n] 区间内选取任意个数字补充到 nums 中&#xff0c;使得 [1, n] 区间内的任何数字都可以用 nums 中某几个数字的和来表示。请输出满足上述要求的最少需要补充的数字个数。 示例 1: 输入: nums [1,3], …

【炼数成金 NOSQL引航 三】 Redis使用场景与案例分析

验证redis的主从复制&#xff0c;将实验过程抓图 复制配置文件 更改slave的端口 和相关master配置 主从复制测试 研究在OAuth中的“一次数”nonce有什么用途&#xff1f;怎样使用&#xff1f;以此熟悉OAuth的全流程 nonce &#xff0c;一个随机的混淆字符串&#xff0c;仅仅被…

SQL Server需要监控哪些计数器 ---指尖流淌

http://www.cnblogs.com/zhijianliutang/p/4174697.html转载于:https://www.cnblogs.com/zengkefu/p/7044095.html