ActiveMQ官方文档翻译-命令行工具指南

原创
2015/06/04 20:56
阅读数 340

当前的脚本包含了所有管理activemq的功能。

在5.4.1之前的版本,一些超过了控制服务本身的管理功能被包含在"activemq-admin"脚本当中。

这个脚本现在仍有部分提供给了windows用户使用

在5.0之前的版本这些管理消息中间件的脚本(activemq-admin)被分割为多个脚本,如:

  • shutdown - 停止消息中间件

  • list - 列出所有在指定的JMX上下文内的正在运行的消息中间件

  • query - 查询统计和信息

  • bstat - predefined query that displays useful broker statistics

  • browse - 浏览指定队列的信息

  • purge - 删除与消息选择器匹配的消息

activemq脚本

注:这个脚本只能用在windows平台以及5.4.0版本之前的unix平台。5.4.0及以后的版本activemq提供了一个加强版的unix shell脚本

脚本名称 activemq.bat, activemq
使用方式 activemq [options] [config] or java -jar run.jar start [options] [config]
描述

用于启动activemq消息中间件的脚本,该脚本即可以通过指定一个配置文件也可以通过URI配置的方式来运行

选项:

选项名称
语法 例子 描述
系统定义的选项
-D<key>=<value> -Dactivemq.home=c:/ActiveMQ 设置系统属性。比如这个例子中当在代码中调用Systems.getProperty("activemq.home")时会返回c:/ActiveMQ
帮助选项
-h or -? or --help activemq --help 显示activemq脚本的帮助信息
版本信息选项
--version activemq --version 显示activemq的版本信息

例子:

例子
描述
activemq

使用默认的'xbena:activemq.xml‘配置文件启动消息中间件

activemq xbean:myconfig.xml

使用在classpath下的myconfig.xml文件作为配置文件启动消息中间件

activemq xbean:file:./conf/broker1.xml

使用在相对路径./conf/broker1.xml下的broker1.xml文件作为配置文件启动消息中间件

activemq xbean:file:C:/ActiveMQ/conf/broker2.xml

使用绝对路径C:/ActiveMQ/conf/下的broker2.xml文件作为配置文件启动消息中间件。

activemq broker:(tcp://localhost:61616,tcp://localhost:5000)?useJmx=true

使用url的方式来启动消息中间件,这个例子中启动了两个传输通道(分别在61616和5000端口上监听)并且启用了jmx特性。

activemq broker:(tcp://localhost:61616,network:tcp://localhost:5000)?persistent=false

Runs a broker with 1 transport connector and 1 network connector with persistence disabled.Â

使用url的方式来启动消息中间件,这个例子中启动了1个传输通道(在61616端口上监听)和一个网络通道(在5000端口监听)并且明确禁用了持久化特性。

译者注:在5.11.1及后的版本中上面的这些例子在activemq后要增加一个start参数,如activemq start xbean:myconfig.xml,并且要特别注意url参数不能有空格,在官方提供的原文档中多个地方中间有空格导致执行不成功)

更多有关配置和使用broker URI的信息可参看:Broker Configuration URI

activemq-admin

ActiveMQ 5.x版本以后,上面那些单独的脚本都被并入到activemq-admin当中(除了active脚本外),如下:

  • activemq-admin stop

  • activemq-admin list

  • activemq-admin query

  • activemq-admin bstat

  • activemq-admin browse

每个任务的语法如下所述。要注意的是activemq这个命令还是保留的。

stop task

任务名称 stop
使用方法
activemq-admin stop [options] [broker names]
描述 用来停止一个正在运行的消息中间件。这个任务能执行的前提是在启动消息中间件时开启了jmx特性

选项

选项名称
语法 例子 描述
停止所有选项
--all stop --all 停止所有被注册在指定的jmx上下文内的消息中间件
JMX URL --jmxurl <url>  --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
JMX Authentication --jmxuser user --jmxpassword password --jmxuser smx --jmxpassword smx
System Define -D<key>=<value>  -Dactivemq.home=c:/ActiveMQ
Help -h or -? or --help --help
Version --version activemq --version

例子

例子
描述
activemq-admin stop 停止默认的jmx上下文内正在运行的消息中间件。假设只有一个正在运行的消息中间件
activemq-admin stop --jmxurl service:jmx:rmi:///jndi/rmi://remotehost:1099/jmxrmi --all 停止所有在指定的jmx上下文内的下在运行的消息中间件
activemq-admin stop localhost 停止在默认的jmx上下文内正在运行的叫'localhost'的消息中间件
activemq-admin stop localhost remotehost 停止在默认的jmx上下文内正在运行的叫'localhost'和'remotehost'的消息中间件

list task

任务名称 list
使用方法
activemq-admin list [options]
描述 列出在指定的jmx上下文内运行的所有正在运行的消息中间件的名字。这个任务能执行的前提是在启动消息中间件时开启了jmx特性

选项

选项名称 语法 例子 描述
JMX URL  --jmxurl <url>  --jmxurl service:jmx:rmi:///jndi/rmi://remotehost:1099/jmxrmi
JMX Authentication --jmxuser user --jmxpassword password --jmxuser smx --jmxpassword smx
System Define -D<key>=<value>  -Dactivemq.home=c:/ActiveMQ 
Help -h or -? or --help  --help
Version --version activemq --version

例子

例子 描述
activemq-admin list 列出默认的jmx上下文内所有正在运行的消息中间件的名称
activemq-admin list --jmxurl service:jmx:rmi:///jndi/rmi://remotehost:1099/jmxrmi 列出指定的jmx上下文内所有正在运行的消息中间件的名称

query task

任务名称 query
使用方法
activemq-admin query [options]
描述 Script to query the specified JMX context for mbean attributes and information。这个任务能执行的前提是在启动消息中间件时开启了jmx特性

选项

选项名称 语法 例子 描述
Predefined Query Option -Q<type>=<name> -QTopic=TEST.FOO, -QBroker=*host 预定义对象名称查询选项,查询基于其类型和选择特定的MBean对象类型标识符。具体请参考下面给出的mbean参考表格。

-xQ<type>=<name> -xQTopic=ActiveMQ.Advisory.*, -xQNetworkConnector=* 预定义对象名称查询选项,不显示所有匹配的查询的搜索结果MBeans。具体请参考下面给出的mbean参考表格。
Object Name Query Option --objname <object name query> --objname Type=Connect,BrokerName=local* 格式不严格的基于JMX对象名称格式的查询选项,它可以让你过滤基于对象名称信息MBean。具体请参考下面给出的mbean参考表格。

--xobjname <object name query> --xobjname Type=Topic,Destination=ActiveMQ.Advisory.* 对象名称查询,在搜索结果中不显示所有匹配查询选项的mbean。具体请参考下面给出的mbean参考表格。
View Option --view <view list> --view Type,BrokerName,Destination,EnqueueCount,DequeueCount 让你可以指定对象和属性名称来查看信息。如果view后没有选项则会显示所有的信息。

例子

例子
描述
activemq-admin query 显示所有在默认的jmx上下文中注册的mbean的所有属性和对象名。
activemq-admin query -QTopic=TEST.FOO 显示所有目的主题名称为TEST.FOO的所有属性和对象名。
activemq-admin query -QQueue=* 显示所有注册队列的所有属性和对象名。
activemq-admin query -QTopic=*.FOO -xQTopic=ActiveMQ.Advisory.* 显示所有主题名称以'.FOO'结尾的并且不以''ActiveMQ.Advisory.'开头的所有属性和对象名。
activemq-admin query -QBroker=local???? --view Type,BrokerName,EnqueueCount,DequeueCount 显示所有消息中间件的名称为9个字母的并且以'local'开头的对象类型,中间件名称,入队列数据的数目,出队列数据的数目信息。
activemq-admin query --objname Type=Connect,BrokerName=localhost -xQNetworkConnector=* 显示名字为'localhost'的消息中间件的所有的连接和连接器的所有属性和对象名称(除了网络连接器)。
activemq-admin query --objname Type=Connection --xobjname Type=Connection,BrokerName=localhost 显示所有已注册的连接的所有属性和对象名称信息(除了那些属于名字为'localhost’的broker的)。
activemq-admin query -QQueue=???? --objname Type=Connection --xobjname BrokerName=remote* 显示所有名字为四个字母的队列和连接的所有的属性和对象名称的信息(除了那些属于以'remote'开头的消息中间件的)。

ActiveMQ MBean 参考

MBean类型 属性/对象名 属性
Broker
  • Type=Broker

  • BrokerName=<broker identifier>

  • BrokerId

  • TotalEnqueueCount

  • TotalDequeueCount

  • TotalConsumerCount

  • TotalMessages

  • TotalMessagesCached

  • MemoryLimit

  • MemoryPercentageUsed

Destination
  • Type=Queue|Topic

  • Destination=<destination identifier>

  • BrokerName=<name of broker>

  • EnqueueCount

  • DequeueCount

  • ConsumerCount

  • Messages

  • MessagesCached

NetworkConnector
  • Type=NetworkConnector

  • BrokerName=<connector identifierr>


Connector
  • Type=Connector

  • ConnectorName=<connector identifier>

  • BrokerName=<name of broker>

  • EnqueueCount

  • DequeueCount

Connection
  • Type=Connection

  • Connection=<connection identifier>

  • BrokerName=<name of broker>

  • EnqueueCount

  • DequeueCount

  • DispatchQueueSize

  • Active

  • Blocked

  • Connected

  • Slow

bstat task

任务名称 bstat
使用方法 activemq-admin bstat [broker name]
描述 显示对消息中间件及它的组件有用的统计的预定义脚本。

例子

例子 描述
activemq-admin bstat 显示默认的jmx上下文中所有注册的消息中间件的有用的统计信息。
activemq-admin bstat localhost 显示注册的名字叫'localhost'的消息中间件的有用的统计信息

browse task

任务名称
browse
使用方法 activemq-admin browse --amqurl <broker url> [options] <destinations> or java -jar run.jar browse --amqurl <broker url> [options] <destinations>
描述 用来浏览选中的目的消息的脚本

选项

选项名称 表达式 例子 描述
Broker URL --amqurl <url>  --amqurl tcp://localhost:61616 指定要连接的broker URL
消息选择器 --msgsel "<msgsel1,msgsel2,...>" --msgsel "JMSMessageID='*:10',JMSPriority>5" Allows you to filter the specific messages to view. Place the entire selector criteria in double quotes " ". You can use wildcard queries by enclosing the string message property in ' '. Other than using wildcard queries to filter string properties, other queries follows the message selector format.
视图组 -V[header | custom | body] -Vheader, -Vcustom, -Vbody Let's you specify a specific group of message attributes to view. The header view shows all the standard JMS message headers. The custom view shows all the custom fields added to each JMS message. The body view shows the message body of the JMS message.
指定的视图 --view <attr1>,[header:|custom:]<attr2>,... --view JMSMessageID='*:10',custom:MyCustomField Let's you specifically select a specific message attribute. It allows you to select specific attributes from the JMS and custom headers. You could add the tags header: and custom: to explicitly specify where the attribute belongs to. Refer to the message header table below for details.

例子

例子
描述
activemq-admin browse --amqurl tcp://localhost:61616 TEST.FOO 打印所有在名字叫'TEST.FOO'的队列里的消息的JMS消息头,自定义消息头和消息体
activemq-admin browse --amqurl tcp://localhost:61616 -Vheader,body TEST.FOO 打印所有在名字叫'TEST.FOO'的队列里的消息的JMS消息头和消息体
activemq-admin browse --amqurl tcp://localhost:61616 -Vheader --view custom:MyCustomField TEST.FOO TEST.BAR 打印所有在名字叫'TEST.FOO'和'TEST.BAR'的队列里的消息的JMS消息头和自定义字段'MyCustomField'
activemq-admin browse --amqurl tcp://localhost:61616 --msgsel "JMSMessageID='*:10',JMSPriority>5" TEST.FOO 打印所有在队列'TEST.FOO'里的所有消息里的JMSMessageID能够模糊匹配'*:10'的以及JMSPriority(消息优先级)大于5的消息属性。 

JMS消息头参考

消息头名称
消息头类别
JMSCorrelation ID String
JMSDelivery Mode int (1-Non-Persistent, 2-Persistent)
JMSDestination javax.jms.Destination
JMSExpiration long
JMSMessageID String
JMSPriority int
JMSRedelivered boolean
JMSReplyTo javax.jms.Destination
JMSTimestamp long

JMSType String

purge task

任务名称 purge
使用方法 activemq-admin purge [purge-options] <destinations>
描述 删除匹配消息选择器的所有目的消息

选项

选项名称
表达式 例子 描述
JMX URL --jmxurl <url>   --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi Change the JMX service url to connect to. By default it connects to: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
JMX Authentication --jmxuser user --jmxpassword password --jmxuser smx --jmxpassword smx For cases where username/password based authentication of the JMX client is required. Not set by default
消息选择器 --msgsel "<msgsel1,msgsel2,...>" --msgsel "JMSMessageID='*:10',JMSPriority>5" Allows you to filter the specific messages to view. Place the entire selector criteria in double quotes " ". You can use wildcard queries by enclosing the string message property in ' '. Other than using wildcard queries to filter string properties, other queries follows the message selector format.

例子

例子 描述
activemq-admin purge FOO.BAR 删除所有在队列'FOO.BAR'里的消息
activemq-admin purge --msgsel "JMSMessageID='*:10',JMSPriority>5" FOO.*

Delete all the messages in the destinations that matches FOO.* and has a JMSMessageID in", the header field that matches the wildcard *:10, and has a JMSPriority field > 5 in the", queue FOO.BAR 

To use wildcard queries, the field must be a string and the query enclosed in ''

dstat task

任务名称
dstat
使用方法 activemq-admin dstat [destination type]
描述 用来显示对于一个消息中间件有用的统计信息的脚本

例子

例子 描述
activemq-admin dstat 显示在默认的jmx上下文中所有的在消息中间件中的目的消息的有用统计信息
activemq-admin dstat topics 显示所有在消息中间件中的主题的有用的统计信息

原文链接

ActiveMQ Command Line Tools Reference

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部