activemq命令

ActiveMQ命令详解
本文详细介绍了ActiveMQ的命令行工具,包括浏览、统计、启动、停止、查询、清除消息等功能,以及如何创建生产者和消费者。

吐槽一下activemq的官网,信息少的可怜,也可能是鄙人的英文太差(心累......)。按照activemq --help一个一个命令查看总结一下。注意,这里写的并不全~

1.activemq browse [browse-options] <destinations>

在指定的目标中显示选定的消息。

用法 
activemq browse [browse-options] <destinations>

browse-options:

 --amqurl <url>                设置要连接的broker地址,默认tcp://localhost:61616
 --msgsel <msgsel1,msglsel2>   添加查找条件
 --factory <className>         指定javax.jms.ConnectionFactory用来创建连接的工厂
 --passwordFactory <className> 指定org.apache.activemq.console.command.PasswordFactory从keystore接受密码的工厂                         
 --user <username>             指定JMS连接的用户名
 --password <password>         指定JMS连接的密码
 -V<header|custom|body>        允许您查看消息头,自定义消息头或消息正文的预定义视图
 --view <attr1>,<attr2>,...    选择要查看的消息的特定属性
 --version                     查看版本
 -h,-?,--help                  查看帮助信息
eg:
activemq browse --amqurl tcp://localhost:61616 FOO.BAR
打印队列FOO.BAR的所有消息头,自定义消息头,和消息体

activemq browse --amqurl tcp://localhost:61616 -Vheader,body queue:FOO.BAR
仅打印队列FOO.BAR的所有消息头,和消息体

activemq browse --amqurl tcp://localhost:61616 -Vheader --view custom:MyField queue:FOO.BAR
仅打印队列FOO.BAR的所有消息头和自定义属性MyField

activemq browse --amqurl tcp://localhost:61616 --msgsel "JMSMessageID='*:10',JMSPriority>5" FOO.BAR
打印队列FOO.BAR中,消息头匹配匹配wildcard *:10,并且有一个JMSPriority(jms优先级)大于5的所有消息。使用--msgsel时,匹配条件必须是一个字符串

activemq browse --amqurl tcp://localhost:61616 --user someUser --password somePass FOO.BAR
打印队列FOO.BAR中,所有消息头,自定义消息头,和消息体,使用账号someUser,密码somePass。

activemq browse --amqurl tcp://localhost:61616 --user someUser --password somePass --factory org.apache.activemq.ActiveMQConnectionFactory --passwordFactory org.apache.activemq.AMQPasswordFactory FOO.BAR
打印队列FOO.BAR中,所有消息头,自定义消息头,和消息体,使用账号someUser,密码somePass发送,org.apache.activemq.AMQFactorySubClass创建JMS连接,org.apache.activemq.console.command.DefaultPasswordFactory转变somePass为password。

2.activemq bstat 展示指定broker的统计信息,如果没有指定broker则展示所有已注册的broker。

用法
activemq bstat [bstat-options] [broker-name] 

Bstat Options:
    --jmxurl <url>                Set the JMX URL to connect to.
    --pid <pid>                   Set the pid to connect to (only on Sun JVM).
    --jmxuser <user>              Set the JMX user used for authenticating.
    --jmxpassword <password>      Set the JMX password used for authenticating.
    --jmxlocal                    Use the local JMX server instead of a remote one.
    --version                     Display the version information.
    -h,-?,--help                  Display the query broker help information.

3.activemq dstat 以表格的形式展示broker的统计信息

用法
activemq dstat [dstat-options] [destination-type]

dstat Options:
    --jmxurl <url>                Set the JMX URL to connect to.
    --pid <pid>                   Set the pid to connect to (only on Sun JVM).
    --jmxuser <user>              Set the JMX user used for authenticating.
    --jmxpassword <password>      Set the JMX password used for authenticating.
    --jmxlocal                    Use the local JMX server instead of a remote one.
    --version                     Display the version information.
    -h,-?,--help                  Display the query broker help information.

4. activemq list 列出指定的JMX上下文中可用的broker

用法
activemq list [list-options]

List Options:
    --jmxurl <url>             Set the JMX URL to connect to.
    --pid <pid>                Set the pid to connect to (only on Sun JVM).
    --jmxuser <user>           Set the JMX user used for authenticating.
    --jmxpassword <password>   Set the JMX password used for authenticating.
    --jmxlocal                 Use the local JMX server instead of a remote one.
    --version                  Display the version information.
    -h,-?,--help               Display the stop broker help information.

5.activemq query 查询broker的属性

用法
 Main query [query-options]
Query Options:
    -Q<type>=<name>               查询type=name的对象
    -xQ<type>=<name>              过滤掉type=name的对象
    --objname <query>             Add to the search list objects matched by the query similar
                                  to the JMX object name format.
    --xobjname <query>            Remove from the search list objects matched by the query
                                  similar to the JMX object name format.
    --view <attr1>,<attr2>,...    选择需要展示的属性,默认展示所有。
    --invoke <operation>          对结果集执行操作operation。
    --jmxurl <url>                Set the JMX URL to connect to.
    --pid <pid>                   Set the pid to connect to (only on Sun JVM).
    --jmxuser <user>              Set the JMX user used for authenticating.
    --jmxpassword <password>      Set the JMX password used for authenticating.
    --jmxlocal                    Use the local JMX server instead of a remote one.
    --version                     Display the version information.
    -h,-?,--help                  Display the query broker help information.

6.activemq start 启动mq

7.activemq stop 停止mq

8.activemq purge 删除指定消息

用法
Main purge [browse-options] <destinations>

Purge Options:
    --msgsel <msgsel1,msglsel2>   添加查询条件
    --reset                       purge操作完以后重置destination统计。
    --jmxurl <url>                Set the JMX URL to connect to.
    --pid <pid>                   Set the pid to connect to (only on Sun JVM).
    --jmxuser <user>              Set the JMX user used for authenticating.
    --jmxpassword <password>      Set the JMX password used for authenticating.
    --jmxlocal                    Use the local JMX server instead of a remote one.
    --version                     Display the version information.
    -h,-?,--help                  Display the browse broker help information.

9.activemq producer 创建一个生产者

用法  
activemq producer [OPTIONS]
Options :
    [--brokerUrl                                   URL] -连接工厂url; 默认ActiveMQConnectionFactory.DEFAULT_BROKER_URL
    [--user                                         ..] - 用户名
    [--password                                     ..] - 密码
    [--destination               queue://..|topic://..] - 指定destination;默认queue://TEST
    [--persistent                           true|false] - 是否持久化,默认true
    [--messageCount                                  N] - 要发送的消息数,默认1000
    [--sleep                                         N] - 发送和响应休眠间隔,默认0.单位毫秒
    [--transactionBatchSize                          N] - 使用事务批量发送的size,默认0,无jms事务。
    [--parallelThreads                               N] - 并行执行的线程数,默认1
    [--msgTTL                                        N] - 消息存活的时间,毫秒
    [--messageSize                                   N] - 消息报文大小,字节数; 默认0, 一个简单的textMessage使用的.
    [--textMessageSize                               N] - TextMessage报文大小,字节数, a Lorem ipsum demo TextMessage is used
    [--message                                      ..] - 一个文本字符串使用message
    [--payloadUrl                                  URL] - 指向一个文本的url使用payloadUrl                                  
    [--msgGroupID                                   ..] - JMS message group identifier


eg:
 ./activemq producer --destination queue://TEST --messageCount 1 --persistent true --message test
创建一个生产者,向队列TEST推送一个持久化文本消息,消息内容是test。

10.activemq consumer 创建一个消费者

用法
activemq  consumer [OPTIONS]

Options :
    [--brokerUrl                                   URL] -指定brokerurl; default ActiveMQConnectionFactory.DEFAULT_BROKER_URL
    [--user                                         ..] - 连接账户
    [--password                                     ..] - 连接密码
    [--destination               queue://..|topic://..] - 要消费的destination; 默认queue://TEST
    [--messageCount                                  N] - 要消费的消息数,默认 1000
    [--sleep                                         N] - 发送和接受消息休眠间隔,单位毫秒; 默认0
    [--ackMode     AUTO_ACKNOWLEDGE|CLIENT_ACKNOWLEDGE] - message acknowledgement的类型; 默认auto acknowledge
    [--batchSize                                     N] - 事务批量执行的size和客户端acknowledgment(默认10)
    [--durable                              true|false] - 是否创建一个持久化topic
    [--clientId                                     ..] - 客户端id;持久化topics必填
    [--parallelThreads                               N] - 并行线程数; 默认1
    [--bytesAsText                          true|false] - 是否将字节流消息转化为文本消息

eg:
 ./activemq consumer queue://TEST --messageCount 1 --clientId test  --durable true
创建一个消费者监听队列TEST,消费一个消息,客户端id为test。

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值