ActiveMQ Artemis 有一個命令列介面 (CLI),可以用來管理訊息代理程式的某些方面,例如建立執行個體、基本使用者管理、佇列和位址管理等。此介面專為考慮到人類的簡單使用案例而設計。它不是一套完整的命令,用於完整的訊息代理程式管理。有一個全面的管理 API 可用,其中包含許多返回 JSON 格式輸出的操作,更適合在腳本和其他自動化流程中使用。

CLI 有兩種使用方式

  • 傳統的 CLI 命令,例如:./artemis [命令] [參數]

  • 使用 ./artemis./artemis shell 命令存取的自訂 Shell。

所有可透過傳統 CLI 命令使用的命令也可透過 Shell 介面使用。

Shell 的一個優點是,當您重複命令時,它會重複使用某些資訊。例如,一旦您為一個命令提供了訊息代理程式 URI 以及使用者名稱和密碼,這些值將會在同一個 Shell 會話中透明地應用於其他命令。當然,Shell 也讓您可以避免為每個命令重新輸入 ./artemis

1. 取得說明

您可以輸入以下內容取得可用命令的完整清單

$ ./artemis help
Usage: artemis [COMMAND]
ActiveMQ Artemis Command Line
Commands:
  help        use 'help <command>' for more information
  pwd         Information on current folder and instance.
  shell       JLine3 shell helping using the CLI
  producer    Send message(s) to a broker.
  transfer    Move messages from one destination towards another destination.
  consumer    Consume messages from a queue.
  browser     Browse messages on a queue.
  mask        Mask a password and print it out.
  version     Print version information.
  perf        use 'help perf' for sub commands list
  check       use 'help check' for sub commands list
  queue       use 'help queue' for sub commands list
  address     use 'help address' for sub commands list
  connect     Connect to the broker validating credentials for commands.
  disconnect  Clear previously typed user credentials.
  data        use 'help data' for sub commands list
  create      Create a new broker instance.
  upgrade     Update a broker instance to the current artemis.home, keeping all
                the data and broker.xml. Warning: backup your instance before
                using this command and compare the files.
  completion  Generates the auto complete script file to be used in bash or
                zsh. Usage: source <(./artemis completion)

也可以在特定命令或子命令中使用 help 以取得更多資訊。例如,若要取得 data 的子命令清單,請輸入 ./artemis help data

$ ./artemis help data
Usage: artemis data [COMMAND]
use 'help data' for sub commands list
Commands:
  recover  Recover (undelete) every message on the journal by creating a new
             output journal. Rolled back and acked messages will be sent out to
             the output as much as possible.
  print    Print data records information. WARNING: don't use while a
             production server is running.
  exp      Export all message-data using an XML that could be interpreted by
             any system.
  imp      Import all message-data using an XML that could be interpreted by
             any system.
  decode   Decode a journal's internal format into a new set of journal files.
  encode   Encode a set of journal files into an internal encoded data format.
  compact  Compact the journal of a non running server.

或者您可以取得特定命令的說明。例如,./artemis help create

Usage: artemis create [--aio] [--allow-anonymous] [--autocreate] [--autodelete]
                      [--backup] [--blocking] [--clustered]
                      [--disable-persistence] [--failover-on-shutdown]
                      [--force] [--jdbc] [--linux] [--mapped] [--nio]
                      [--no-amqp-acceptor] [--no-autocreate] [--no-autotune]
                      [--no-fsync] [--no-hornetq-acceptor] [--no-mqtt-acceptor]
                      [--no-stomp-acceptor] [--no-web] [--paging]
                      [--relax-jolokia] [--replicated] [--require-login]
                      [--shared-store] [--silent] [--slave]
                      [--support-advisory]
                      [--suppress-internal-management-objects]
                      [--use-client-auth] [--verbose] [--windows]
                      [--addresses=<addresses>]
                      [--cluster-password=<clusterPassword>]
                      [--cluster-user=<clusterUser>] [--data=<data>]
                      [--default-port=<defaultPort>] [--encoding=<encoding>]
                      [--etc=<etc>] [--global-max-messages=<globalMaxMessages>]
                      [--global-max-size=<globalMaxSize>] [--home=<home>]
                      [--host=<host>] [--http-host=<httpHost>]
                      [--http-port=<httpPort>] [--java-memory=<javaMemory>]
                      [--jdbc-bindings-table-name=<jdbcBindings>]
                      [--jdbc-connection-url=<jdbcURL>]
                      [--jdbc-driver-class-name=<jdbcClassName>]
                      [--jdbc-large-message-table-name=<jdbcLargeMessages>]
                      [--jdbc-lock-expiration=<jdbcLockExpiration>]
                      [--jdbc-lock-renew-period=<jdbcLockRenewPeriod>]
                      [--jdbc-message-table-name=<jdbcMessages>]
                      [--jdbc-network-timeout=<jdbcNetworkTimeout>]
                      [--jdbc-node-manager-table-name=<jdbcNodeManager>]
                      [--jdbc-page-store-table-name=<jdbcPageStore>]
                      [--journal-device-block-size=<journalDeviceBlockSize>]
                      [--journal-retention=<retentionDays>]
                      [--journal-retention-max-bytes=<retentionMaxBytes>]
                      [--max-hops=<maxHops>]
                      [--message-load-balancing=<messageLoadBalancing>]
                      [--name=<name>] [--password=<password>] [--ping=<ping>]
                      [--port-offset=<portOffset>] [--queues=<queues>]
                      [--role=<role>] [--security-manager=<securityManager>]
                      [--ssl-key=<sslKey>]
                      [--ssl-key-password=<sslKeyPassword>]
                      [--ssl-trust=<sslTrust>]
                      [--ssl-trust-password=<sslTrustPassword>]
                      [--staticCluster=<staticNode>] [--user=<user>]
                      [--java-options=<javaOptions>]... <directory>
Create a new broker instance.
      <directory>            The instance directory to hold the broker's
                               configuration and data. Path must be writable.
      --addresses=<addresses>
                             A comma separated list of addresses with the
                               option to specify a routing type, e.g.
                               --addresses myAddress1,myAddress2:anycast.
                               Routing-type default: multicast.
      --aio                  Set the journal as asyncio.
      --allow-anonymous      Allow connections from users with no security
                               credentials. Opposite of --require-login.
                               Default: input.
      --autocreate           Allow automatic creation of addresses & queues.
                               Default: true.
      --autodelete           Allow automatic deletion of addresses & queues.
                               Default: false.
      --backup               Be a backup broker. Valid for shared store or
                               replication.
      --blocking             Block producers when address becomes full.
                               Opposite of --paging. Default: false.
      --cluster-password=<clusterPassword>
                             The password to use for clustering. Default: input.
      --cluster-user=<clusterUser>
                             The user to use for clustering. Default: input.
      --clustered            Enable clustering.
      --data=<data>          Directory where ActiveMQ data are stored. Paths
                               can be absolute or relative to artemis.instance
                               directory. Default: data.
      --default-port=<defaultPort>
                             The port number to use for the main 'artemis'
                               acceptor. Default: 61616.
      --disable-persistence  Disable message persistence to the journal
      --encoding=<encoding>  The encoding that text files should use. Default:
                               UTF-8.
      --etc=<etc>            Directory where ActiveMQ configuration is located.
                               Paths can be absolute or relative to artemis.
                               instance directory. Default: etc.
      --failover-on-shutdown Whether broker shutdown will trigger failover for
                               clients using the core protocol. Valid only for
                               shared store. Default: false.
      --force                Overwrite configuration at destination directory.
      --global-max-messages=<globalMaxMessages>
                             Maximum number of messages that will be accepted
                               in memory before using address full policy mode.
                               Default: undefined.
      --global-max-size=<globalMaxSize>
                             Maximum amount of memory which message data may
                               consume. Default: half of the JVM's max memory.
      --home=<home>          Directory where ActiveMQ Artemis is installed.
      --host=<host>          Broker's host name. Default: 0.0.0.0 or input if
                               clustered).
      --http-host=<httpHost> Embedded web server's host name. Default:
                               localhost.
      --http-port=<httpPort> Embedded web server's port. Default: 8161.
      --java-memory=<javaMemory>
                             Define the -Xmx memory parameter for the broker.
                               Default: 2G.
      --java-options=<javaOptions>
                             Extra Java options to be passed to the profile.
      --jdbc                 Store message data in JDBC instead of local files.
      --jdbc-bindings-table-name=<jdbcBindings>
                             Name of the jdbc bindings table.
      --jdbc-connection-url=<jdbcURL>
                             The URL used for the database connection.
      --jdbc-driver-class-name=<jdbcClassName>
                             JDBC driver classname.
      --jdbc-large-message-table-name=<jdbcLargeMessages>
                             Name of the large messages table.
      --jdbc-lock-expiration=<jdbcLockExpiration>
                             Lock expiration (in milliseconds).
      --jdbc-lock-renew-period=<jdbcLockRenewPeriod>
                             Lock Renew Period (in milliseconds).
      --jdbc-message-table-name=<jdbcMessages>
                             Name of the jdbc messages table.
      --jdbc-network-timeout=<jdbcNetworkTimeout>
                             Network timeout (in milliseconds).
      --jdbc-node-manager-table-name=<jdbcNodeManager>
                             Name of the jdbc node manager table.
      --jdbc-page-store-table-name=<jdbcPageStore>
                             Name of the page store messages table.
      --journal-device-block-size=<journalDeviceBlockSize>
                             The block size of the journal's storage device.
                               Default: 4096.
      --journal-retention=<retentionDays>
                             Configure journal retention in days. If > 0 then
                               enable journal-retention-directory from broker.
                               xml allowing replay options.
      --journal-retention-max-bytes=<retentionMaxBytes>
                             Maximum number of bytes to keep in the retention
                               directory.
      --linux, --cygwin      Force Linux or Cygwin script creation. Default:
                               based on your actual system.
      --mapped               Set the journal as mapped.
      --max-hops=<maxHops>   Number of hops on the cluster configuration.
      --message-load-balancing=<messageLoadBalancing>
                             Message load balancing policy for cluster.
                               Default: ON_DEMAND. Valid values: ON_DEMAND,
                               STRICT, OFF, OFF_WITH_REDISTRIBUTION.
      --name=<name>          The name of the broker. Default: same as host name.
      --nio                  Set the journal as nio.
      --no-amqp-acceptor     Disable the AMQP specific acceptor.
      --no-autocreate        Disable auto creation for addresses & queues.
      --no-autotune          Disable auto tuning of the journal-buffer-timeout
                               in broker.xml.
      --no-fsync             Disable usage of fdatasync (channel.force(false)
                               from Java NIO) on the journal.
      --no-hornetq-acceptor  Disable the HornetQ specific acceptor.
      --no-mqtt-acceptor     Disable the MQTT specific acceptor.
      --no-stomp-acceptor    Disable the STOMP specific acceptor.
      --no-web               Whether to omit the web-server definition from
                               bootstrap.xml.
      --paging               Page messages to disk when address becomes full.
                               Opposite of --blocking. Default: true.
      --password=<password>  The user's password. Default: input.
      --ping=<ping>          A comma separated string to be passed on to the
                               broker config as network-check-list. The broker
                               will shutdown when all these addresses are
                               unreachable.
      --port-offset=<portOffset>
                             How much to off-set the ports of every acceptor.
      --queues=<queues>      A comma separated list of queues with the option
                               to specify a routing type, e.g. --queues
                               myQueue1,myQueue2:multicast. Routing-type
                               default: anycast.
      --relax-jolokia        Disable strict checking in jolokia-access.xml.
      --replicated           Enable broker replication.
      --require-login        Require security credentials from users for
                               connection. Opposite of --allow-anonymous.
      --role=<role>          The name for the role created. Default: amq.
      --security-manager=<securityManager>
                             Which security manager to use - jaas or basic.
                               Default: jaas.
      --shared-store         Enable broker shared store.
      --silent               Disable all the inputs, and make a best guess for
                               any required input.
      --slave                Deprecated for removal. Use 'backup' instead.
      --ssl-key=<sslKey>     Embedded web server's key store path.
      --ssl-key-password=<sslKeyPassword>
                             The key store's password.
      --ssl-trust=<sslTrust> The trust store path in case of client
                               authentication.
      --ssl-trust-password=<sslTrustPassword>
                             The trust store's password.
      --staticCluster, --static-cluster=<staticNode>
                             Cluster node connectors list separated by comma, e.
                               g. "tcp://server:61616,tcp://server2:61616,tcp:
                               //server3:61616".
      --support-advisory     Support advisory messages for the OpenWire
                               protocol.
      --suppress-internal-management-objects
                             Do not register any advisory addresses/queues for
                               the OpenWire protocol with the broker's
                               management service.
      --use-client-auth      Require client certificate authentication when
                               connecting to the embedded web server.
      --user=<user>          The username. Default: input.
      --verbose              Print additional information.
      --windows              Force Windows script creation. Default: based on
                               your actual system.

2. Bash 和 Zsh 自動完成

Bash 和 Zsh 提供自動完成命令的方法。若要與該功能整合,您可以選擇產生自動完成腳本,即:

$ source <(./artemis completion)

安裝自動完成後,您可以按下 TAB 來檢視自動完成資訊

$ ./artemis
activation    check         consumer      disconnect    mask          producer      run           transfer      version
address       completion    create        help          perf          pwd           shell         upgrade
browser       connect       data          kill          perf-journal  queue         stop          user

若要檢視可用的各種參數,您必須輸入 --,然後按下 TAB

$ ./artemis create --
--addresses                             --jdbc-bindings-table-name              --paging
--aio                                   --jdbc-connection-url                   --password
--allow-anonymous                       --jdbc-driver-class-name                --ping
--autocreate                            --jdbc-large-message-table-name         --port-offset
--autodelete                            --jdbc-lock-expiration                  --queues
--blocking                              --jdbc-lock-renew-period                --relax-jolokia
--cluster-password                      --jdbc-message-table-name               --replicated
--cluster-user                          --jdbc-network-timeout                  --require-login
--clustered                             --jdbc-node-manager-table-name          --role

3. 需要輸入

如果沒有透過參數明確提供,某些功能可能需要互動式使用者輸入。例如,在連線到訊息代理程式或建立訊息代理程式執行個體的情況下

$ ./artemis queue stat
Connection brokerURL = tcp://127.0.0.1:61616
Connection failed::AMQ229031: Unable to validate user from /127.0.0.1:56320. Username: null; SSL certificate subject DN: unavailable

--user:
Type the username for a retry
myUser

--password: is mandatory with this configuration:
Type the password for a retry

4. Artemis Shell

若要初始化 Shell 會話,請輸入 ./artemis shell (如果您喜歡,也可以只輸入 ./artemis)

$ ./artemis

ActiveMQ Artemis Shell 提供了一個介面,可用於直接執行命令而無需離開 Java 虛擬機器。

     _        _               _
    / \  ____| |_  ___ __  __(_) _____
   / _ \|  _ \ __|/ _ \  \/  | |/  __/
  / ___ \ | \/ |_/  __/ |\/| | |\___ \
 /_/   \_\|   \__\____|_|  |_|_|/___ /
 Apache ActiveMQ Artemis


For a list of commands, type help or press <TAB>:
Type exit or press <CTRL-D> to leave the session:
Apache ActiveMQ Artemis >

4.1. 互動式連線

可以對伺服器驗證您的 CLI 用戶端一次,並為其他命令重複使用連線資訊

Apache ActiveMQ Artemis > connect --user=myUser --password=myPass --url tcp://127.0.0.1:61616
Connection brokerURL = tcp://127.0.0.1:61616
Connection Successful!

現在,任何需要驗證的命令都會重複使用這些參數。

例如,子命令 queue stat 會重複使用先前的資訊來執行其與訊息代理程式的連線。

Apache ActiveMQ Artemis > queue stat
Connection brokerURL = tcp://127.0.0.1:61616
|NAME                     |ADDRESS                  |CONSUMER_COUNT|MESSAGE_COUNT|MESSAGES_ADDED|DELIVERING_COUNT|MESSAGES_ACKED|SCHEDULED_COUNT|ROUTING_TYPE|
|DLQ                      |DLQ                      |0             |0            |0             |0               |0             |0              |ANYCAST     |
|ExpiryQueue              |ExpiryQueue              |0             |0            |0             |0               |0             |0              |ANYCAST     |
|Order                    |Order                    |0             |4347         |4347          |0               |0             |0              |ANYCAST     |
|activemq.management.0b...|activemq.management.0b...|1             |0            |0             |0               |0             |0              |MULTICAST   |

4.2. 靜態連線

可以使用靜態設定的初始連線啟動 Shell,例如:

$ ./artemis shell --user <username> --password <password> --url tcp://<hostname>:<port>

CLI 不應要求任何其他命令提供訊息代理程式 URL 或使用者/密碼,例如:

$ ./artemis shell --user myUser --password myPass
...


Apache ActiveMQ Artemis > queue stat
Connection brokerURL = tcp://127.0.0.1:61616
|NAME                     |ADDRESS                  |CONSUMER_COUNT|MESSAGE_COUNT|MESSAGES_ADDED|DELIVERING_COUNT|MESSAGES_ACKED|SCHEDULED_COUNT|ROUTING_TYPE|
|DLQ                      |DLQ                      |0             |0            |0             |0               |0             |0              |ANYCAST     |
|ExpiryQueue              |ExpiryQueue              |0             |0            |0             |0               |0             |0              |ANYCAST     |
|TEST                     |TEST                     |0             |8743         |8743          |0               |0             |0              |ANYCAST     |
|activemq.management.2a...|activemq.management.2a...|1             |0            |0             |0               |0             |0              |MULTICAST   |