概述:什么软件都需要一个管理和监控
JMX(Java Management Extension )API(监控java对象)
当然它自带web 控制界面
监控的任务主要有:
管理Bean 称之为MBeans
配置打开监控
...
ActiveMQ JMX 配置
...
public class Stats {
public static void main( String[] args ) throws Exception
{
JMXServiceURL url = new JMXServiceURL(
"service:jmx:rmi:///jndi/rmi://localhost:2011/jmxrmi" );
JMXConnector connector = JMXConnectorFactory.connect( url, null );
connector.connect();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName(
"my-broker:BrokerName=localhost,Type=Broker" );
BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler
.newProxyInstance( connection, name, BrokerViewMBean.class, true ); ·
System.out.println( "Statistics for broker " + mbean.getBrokerId()
+ " - " + mbean.getBrokerName() );
System.out.println( "\n-----------------\n" );
System.out.println( "Total message count: " + mbean.getTotalMessageCount() + "\n" );
System.out.println( "Total number of consumers: " + mbean.getTotalConsumerCount() );
System.out.println( "Total number of Queues: " + mbean.getQueues().length );
for ( ObjectName queueName : mbean.getQueues() )
{
QueueViewMBean queueMbean = (QueueViewMBean) MBeanServerInvocationHandler
.newProxyInstance( connection, queueName,
QueueViewMBean.class, true );
System.out.println( "\n-----------------\n" );
System.out.println( "Statistics for queue " + queueMbean.getName() );
System.out.println( "Size: " + queueMbean.getQueueSize() );
System.out.println( "Number of consumers: " + queueMbean.getConsumerCount() ); ¹
}
}
}
window下ActiveMQ启动脚本
if "%SUNJMX%" == "" set SUNJMX=-Dcom.sun.management.jmxremote.port=1099 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false
14.1.1.4.2、限制JMX获取特定主机
它通过JavaSE RMI属性来限制,而不是ActiveMQ自身,java.rmi.server.hostname
在window下
if "%SUNJMX%" == "" set SUNJMX=-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=localhost
14.1.1.4.3、配置JMX密码授权
在$JAVA_HOME/jre/lib/management/文件下进行设置
14.1.2、提示消息
配置提示信息支持
·
提示信息例子
public class Advisory {
protected static String brokerURL = "tcp://localhost:61616";
protected static transient ConnectionFactory factory;
protected transient Connection connection;
protected transient Session session;
public Advisory() throws Exception
{
factory = new ActiveMQConnectionFactory( brokerURL );
connection = factory.createConnection();
connection.start();
session = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );
}
public static void main( String[] args ) throws Exception
{
Advisory advisory = new Advisory();
Session session = advisory.getSession();
for ( String stock : args )
{
ActiveMQDestination destination =
(ActiveMQDestination) session.createTopic( "STOCKS." + stock );
Destination consumerTopic =
AdvisorySupport.getConsumerAdvisoryTopic( destination ); ·
System.out.println( "Subscribing to advisory " + consumerTopic );
MessageConsumer consumerAdvisory = session.createConsumer( consumerTopic );
consumerAdvisory.setMessageListener( new ConsumerAdvisoryListener() );
Destination noConsumerTopic =
AdvisorySupport.getNoTopicConsumersAdvisoryTopic( destination ); ¸
System.out.println( "Subscribing to advisory " + noConsumerTopic );
MessageConsumer noConsumerAdvisory = session.createConsumer( noConsumerTopic );
noConsumerAdvisory.setMessageListener( new NoConsumerAdvisoryListener() );
}
}
public Session getSession()
{
return(session);
}
}
active-admin.bat 文件
完成功能:
例如启动
$ ./bin/activemq-admin start
$ ./bin/activemq-admin list
$ ./bin/activemq-admin query -QQueue=*
-QQueue=* 打印所有所有队列代理器的状态信息
${ACTIVEMQ_HOME}/bin/activemq-admin browse --amqurl tcp://localhost:61616 JOBS.delete
简单命令行不能到达目的, 配置XMPP协议传输
命令代理配置
14.2.4、Web Console(web控制台)
http://localhost:8161/admin/
log4j.rootLogger=INFO, out, stdout
log4j.logger.org.apache.activemq.spring=WARN
log4j.logger.org.springframework=WARN
log4j.logger.org.apache.xbean.spring=WARN
log4j.logger.org.apache.activemq.transport.failover.FailoverTransport=DEBUG
log4j.logger.org.apache.activemq.transport.TransportLogger=DEBUG
ActiveMQ自带日志拦截器
在activemq.xml配置