Skip to main content

Using the NATS Admin CLI

JAMS installs the NATS administration CLI, nats.exe, alongside the server in the NATS folder, by default C:\Program Files\MVPSI\JAMS\Scheduler\NATS. It is the tool for inspecting streams, consumers, and individual messages, and it replaces the role the Get-JMMsmq cmdlet played under MSMQ.

The bundled version is 0.4.0, matched to the bundled nats-server 2.14.1.

This is an administrative tool

nats.exe can purge streams, delete consumers, and consume messages. Used carelessly against a running JAMS system it destroys scheduling messages. Everything under Inspecting is read-only and safe. Everything under Commands That Change Things is not.

One-Time Setup: Create a TLS Context​

NATS requires mutual TLS, so the CLI cannot connect until you tell it which certificate to present. Save that once as a named context, and every later command uses it. Run this from the NATS folder in an elevated prompt so the relative filenames resolve:

cd "C:\Program Files\MVPSI\JAMS\Scheduler\NATS"

nats context add jams --server nats://localhost:4222 `
--tlsca nats-ca.pem --tlscert nats-server-cert.pem --tlskey nats-server-key.pem --select

Confirm it works:

nats context info
nats server check connection

OK Connection OK proves the certificate, the CA, and the connection are all good. If it fails, the problem is TLS or the port. See Troubleshooting NATS.

nats server info and nats server report do not work here

They query the server through its system account, and the JAMS configuration defines no accounts. They fail with:

nats: error: no results received, ensure the account used has system privileges and appropriate permissions

This is expected. Use nats server check connection or nats rtt for connectivity, the stream and consumer commands below for JetStream state, and the monitoring endpoint for server-level information.

Contexts are stored per Windows user under %USERPROFILE%\.config\nats\context. Each administrator creates their own and needs read access to the three .pem files, which setup restricts.

To inspect the other node of a failover pair, add a second context pointing at it. You present this machine's certificate to the peer's broker:

nats context add jams-peer --server nats://<OtherNodeName>:4222 `
--tlsca nats-ca.pem --tlscert nats-server-cert.pem --tlskey nats-server-key.pem

nats context select jams-peer
nats server check connection
nats stream ls
nats context select jams

This needs TCP 4222 open between the nodes and both certificates chaining to the same root CA, so it doubles as the test that a failover pair is wired correctly. See NATS in a Failover Environment.

Inspecting​

All of these are read-only.

# Which streams exist? Expect JAMS_RELIABLE, and JAMS_SCOM if SCOM is in use.
nats stream ls

# Depth, disk usage, configuration, and sequence numbers
nats stream info JAMS_RELIABLE

# A summary table across all streams
nats stream report

# Which message types are in the stream, with counts
nats stream subjects JAMS_RELIABLE

# Just the counts
nats stream state JAMS_RELIABLE

# Watch one message type go by, live
nats sub "jams.reliable.EntryComplete"
nats sub "jams.transient.AgentChanged"

# The Scheduler's consumer: how many are waiting, how many are unacknowledged
nats consumer info JAMS_RELIABLE JAMS_SCHEDULER
nats consumer report JAMS_RELIABLE

# Connectivity
nats server check connection
nats rtt

Reading the Numbers​

From nats consumer info JAMS_RELIABLE JAMS_SCHEDULER:

FieldMeaning
Unprocessed MessagesWaiting to be delivered to the Scheduler. Should be at or near zero.
Outstanding AcksDelivered but not yet acknowledged. Normally 0 or 1, because the Scheduler processes one at a time.
Redelivered MessagesDelivered more than once. A non-zero value after a restart is normal. JAMS recognizes duplicates.

From nats stream info JAMS_RELIABLE, Messages is the closest equivalent to MSMQ queue depth. It should be at or near zero.

Diagnosing "the Scheduler isn't processing anything"

If Unprocessed Messages is climbing while Outstanding Acks stays at 0, messages are arriving and nothing is collecting them. Look at the Scheduler service. If Outstanding Acks is stuck at 1, the Scheduler took a message and is stuck on it. Look at the Scheduler log for what it is working on.

Replacing Get-JMMsmq​

The Get-JMMsmq cmdlet has been removed along with MSMQ.

What you used it forNATS equivalent
How many messages are queued?nats stream info JAMS_RELIABLE or nats consumer info JAMS_RELIABLE JAMS_SCHEDULER
Does the queue exist?nats stream ls
What kinds of message are in it?nats stream subjects JAMS_RELIABLE
Look at the messagesnats stream get JAMS_RELIABLE <seq>, see below
Empty the queuenats stream purge JAMS_RELIABLE, see below
Is the transport up?nats server check connection, or Invoke-RestMethod http://127.0.0.1:8222/healthz

Transient messages have no queue to inspect. To watch them live, as a normal subscriber that takes nothing away from the Scheduler:

nats sub "jams.transient.>"
You cannot add your own consumer to a JAMS stream

JAMS_RELIABLE and JAMS_SCOM use work-queue retention, which allows one consumer per subject. Creating a second consumer is rejected with multiple non-filtered consumers not allowed on workqueue stream (10099) or filtered consumer not unique on workqueue stream (10100). Use nats stream get to look at message contents instead.

Commands That Change Things​

Viewing Message Contents​

To read a message without consuming it, fetch it by sequence number. Get a sequence number from nats stream state, then:

nats stream state JAMS_RELIABLE
nats stream get JAMS_RELIABLE 1042

This does not move the consumer, change the acknowledgement floor, or alter the message count.

Two commands to avoid

nats stream view needs an interactive terminal and fails with interactive stream paging requires a valid terminal in any remote shell or scheduled context. Use nats stream get instead.

Never run nats consumer next against JAMS_RELIABLE. It fetches from the Scheduler's own consumer, which takes the message away from the Scheduler. Because the acknowledgement wait is 24 hours, the message stays invisible to JAMS for a full day even with --no-ack, and the work in it is not done.

Avoid nats stream edit on a JAMS stream. The JAMS services reset stream configuration to their expected settings on the next start, so the change is silently reverted.

Purging​

nats stream purge JAMS_RELIABLE
danger

Purging deletes unprocessed scheduling messages permanently. Job submissions, completions, and state changes that had not been processed are lost. Only do this at the direction of JAMS Support, with the JAMS services stopped.

Collecting Information for Support​

cd "C:\Program Files\MVPSI\JAMS\Scheduler\NATS"
$out = "$env:TEMP\jams-nats-diag.txt"

"=== connection ===" | Out-File $out
nats server check connection | Out-File $out -Append
"=== streams ===" | Out-File $out -Append
nats stream report | Out-File $out -Append
nats stream info JAMS_RELIABLE | Out-File $out -Append
"=== consumer ===" | Out-File $out -Append
nats consumer info JAMS_RELIABLE JAMS_SCHEDULER | Out-File $out -Append
"=== varz ===" | Out-File $out -Append
Invoke-RestMethod http://127.0.0.1:8222/varz | ConvertTo-Json -Depth 4 | Out-File $out -Append
"=== jsz ===" | Out-File $out -Append
Invoke-RestMethod "http://127.0.0.1:8222/jsz?streams=1&consumers=1" | ConvertTo-Json -Depth 6 | Out-File $out -Append

$out

Send that file with nats-server.log and the JAMS Scheduler log.

Full Command Reference​

nats --help
nats stream --help
nats consumer --help