Skip to content

CLI

Overview

The SwiftMQ CLI is a command-line interface for administrating SwiftMQ routers. It allows users to connect to routers, navigate the configuration tree, view and modify configuration, and execute administrative commands and scripts. The CLI can be started interactively or in batch mode with a script file, and supports scripting features such as variables, aliases, and output redirection.

CLI Startup and Invocation

The CLI is started using provided shell scripts such as ./cli, ./clis, or ./cliamqp (depending on protocol and environment). These scripts invoke the CLI Java application with the required parameters. The CLI requires at least two arguments: the JNDI provider URL (e.g., smqp://localhost:4001/timeout=10000) and the name of the queue connection factory (e.g., QueueConnectionFactory@router1). An optional third argument specifies a script file containing CLI commands to execute in batch mode. There is no interactive username/password prompt when a script file is provided; credentials can be set via the cli.username and cli.password system properties.

./cli smqp://localhost:4001/timeout=10000 QueueConnectionFactory@router1
./cli smqp://localhost:4001/timeout=10000 QueueConnectionFactory@router1 /path/to/script.cli

Tree Navigation and Context

The CLI operates on a hierarchical configuration tree. Navigation is performed using the cc (change context) command, which sets the current context to a specific node (e.g., /sys$queuemanager/queues). The sr command switches the active router. The prompt reflects the current router and context. Many administrative commands operate on the current context, so it is important to navigate to the correct node before issuing commands.

cc /sys$queuemanager/queues
sr router1

Viewing and Modifying Configuration

Configuration properties and entities can be listed and modified using CLI commands. The show command displays properties and sub-entities of the current context. Properties can be set or deleted using the set and del commands. Some commands are specific to certain contexts (e.g., queue operations under /sys$queuemanager/queues).

show
set maxmessages 10000
del oldproperty

Scripting Features

The CLI supports scripting via script files and interactive commands. Scripts can contain any CLI command, comments (lines starting with #), and support variables and aliases. Variables are managed with the var command and can be substituted into commands when substitution is enabled (substitute on). Aliases are managed with the aset, adel, alist, and asave commands. Output can be redirected to a file using the output command. Scripts can be executed with the execute command.

# Set a variable
var myqueue testqueue
# Enable substitution
substitute on
# Use variable in a command
cc /sys$queuemanager/queues/${myqueue}
# Set an alias
aset qinfo show
# Use the alias
qinfo
# Redirect output
output results.txt
# Execute another script
execute /path/to/otherscript.cli

Router Management and Availability

The CLI can manage multiple routers and monitor their availability. The ar command lists all available routers, and wr <router> waits for a router to become available (optionally with a timeout). The sr command switches the active router context. Router availability events can be handled programmatically by registering a RouterListener.

ar
wr router1 10000
sr router2

Batch Mode and Initialization

When a script file is provided as a CLI argument, the CLI runs in batch mode, executing commands from the file without interactive prompts. An initialization script (by default ~/.init.cli) is executed on startup if present. This can be overridden with the swiftmq.cli.init system property.

./cli smqp://localhost:4001/timeout=10000 QueueConnectionFactory@router1 /path/to/batchscript.cli
./cli -Dswiftmq.cli.init=/custom/init.cli smqp://localhost:4001/timeout=10000 QueueConnectionFactory@router1