NATS in a Failover Environment
The failover design has not changed. Which node is active is still decided in the JAMS database, and the Scheduler still rebuilds its schedule from the database when it takes control. NATS replaces MSMQ as the transport that carries messages between the two nodes.
Setup does gain steps that MSMQ did not need. This page explains them. For the full failover install procedure, see Installing and Configuring the JAMS Failover.
What Is Different from MSMQ
| MSMQ | NATS | |
|---|---|---|
| Port between nodes | 1801 | 4222 |
| Broker | The MSMQ service | A JAMSNATSServer service on each node |
| Transport security | Inherited from Windows | Mutual TLS. Both nodes must trust the same root CA. |
| Extra setup on the secondary | Grant MSMQ permissions | Import the shared root CA, then issue the NATS certificate from it |
Each node runs its own NATS server with its own message store. The two brokers are not clustered and streams are not replicated between them.
Both nodes must present certificates that chain to the same root CA. The installer creates a per-machine root CA on each machine it installs, so out of the box the two nodes do not trust each other. Importing the primary's root CA onto the secondary, and issuing the secondary's NATS certificate from it, is manual. Skipping it leaves the pair unable to exchange messages.
Ports
Allow inbound TCP 4222 on both nodes and confirm each can reach the other:
New-NetFirewallRule -DisplayName "JAMS NATS Server" `
-Direction Inbound -Protocol TCP -LocalPort 4222 -Action Allow
Test-NetConnection <OtherNodeName> -Port 4222
Test-NetConnection <OtherNodeName> -Port 4773
The failover control port, 4773 by default, matters more than it used to. A passive node learns which node holds control over that channel, and only forwards messages once it knows. With 4773 blocked nothing is forwarded, however open 4222 is. Port 1801 is no longer used.
See NATS Ports and Firewall Requirements.
Setting Up the Secondary
Run JAMSRegister.exe as Administrator from the Scheduler folder, by default C:\Program Files\MVPSI\JAMS\Scheduler. The order matters.
1. Install the Primary
Install JAMS on the primary. The installer creates the root CA, issues the NATS certificate, writes the configuration, and starts the service. Nothing NATS-specific is needed by hand.
2. Export the Root CA from the Primary
Export Root CA /Filename="C:\root.pfx" /Prompt
You are prompted for a password. Copy root.pfx to the secondary. It contains the private key of the CA that signs every JAMS certificate in the environment, so protect it and delete both copies when setup is complete.
3. Install the Secondary
Install JAMS on the secondary against the same JAMS database. Setup reports in DBUpdate.log:
The Root CA is not available. TLS will have to be set up manually.
Review documentation on "Installing and Configuring the JAMS Failover".
This is expected. The shared root CA is not on this machine yet, and setup will not issue a certificate from the wrong root. The JAMS services start normally. NATS listens on loopback only until step 5 is done.
4. Import the Shared Root CA on the Secondary
Import Root CA /Filename="C:\root.pfx" /STOREKEY /MakeDefault /Prompt
Both qualifiers are required. /STOREKEY imports the CA's private key, without which this node cannot issue certificates. /MakeDefault makes the imported root the one new certificates are issued from.
An import without /STOREKEY looks like a success, and step 5 then fails with the same Root CA is not available message as if you had never imported it. If that happens, re-run the import with /STOREKEY.
5. Issue the Secondary's NATS Certificate
Create NATS Certificate
Update NATS Configuration /RESTART
The first command issues the certificate from the now-default shared root, installs it in the certificate store, and writes the three .pem files to the NATS folder. The second regenerates the NATS configuration with the tls block and restarts the JAMS NATS service and the JAMS services that depend on it. The certificate command never does that on its own.
If Create stops with NATS Certificate already exists in Certificate Store, this machine already holds a certificate chained to its own per-machine root. Remove it and try again:
Destroy NATS Certificate
Create NATS Certificate
Update NATS Configuration /RESTART
Once the root CA is imported, re-running the JAMS installer also issues a missing certificate and configures TLS. But if the machine already has a NATS certificate, setup keeps it and logs An existing NATS TLS certificate was found., even if that certificate chains to the wrong root. For that case only the destroy, create, update sequence above fixes it.
6. Verify
On each node, in JAMSRegister:
List NATS Configuration
List NATS Certificate
In the configuration report, check that Mutual TLS is on, Reachable From Other Machines is yes, Server Certificate In Store is yes, and the Trusted CA thumbprint is the same on both nodes. In the certificate report, check that the folder certificate shows In Certificate Store: Yes. Then confirm the services are up:
Get-Service JAMSNATSServer, JAMSScheduler, JAMSServer, JAMSExecutor
Finally, prove each node can reach the other's broker over TLS. From the NATS folder on each node:
cd "C:\Program Files\MVPSI\JAMS\Scheduler\NATS"
nats context add peer --server nats://<OtherNodeName>:4222 `
--tlsca nats-ca.pem --tlscert nats-server-cert.pem --tlskey nats-server-key.pem --select
nats server check connection
OK Connection OK proves the firewall, the shared root CA, and mutual TLS are all correct in that direction. Run it from both nodes. See Using the NATS Admin CLI.
Upgrading an Existing Failover Pair
A pair that was already set up for failover has the shared root CA on both nodes. When you upgrade, setup finds the root CA and issues each node's NATS certificate automatically. Two things are still yours to do:
- Open TCP 4222 between the nodes. Port 1801 can be closed.
- After upgrading, run
List NATS Configurationon both nodes and confirmMutual TLSis on. If the secondary shows it off, the root CA was imported without its private key. Re-import it with/STOREKEY /MakeDefault, then follow step 5 above.
The MSMQ permission step from earlier versions is no longer needed. See Upgrading JAMS Using a Primary-Failover Environment.
How Messages Move between the Nodes
The active node processes messages locally. Its Scheduler consumes its own reliable stream and its own transient subscription.
The passive node forwards reliable messages to the active node. A reliable message published on the passive node, such as a job submitted through its JAMS Server, is picked up by the passive node's Scheduler and republished to the active node's NATS server. It is acknowledged locally only after the active node has stored it, and each message keeps the same identity across the forward, so a message that arrives twice is processed once.
The active node reads the passive node's transient messages directly. While active, the Scheduler also subscribes to the peer node's transient subject. A definition change made through the passive node's JAMS Server, such as an Agent, Resource, or Queue edit, reaches the active Scheduler even if the passive node's Scheduler service is stopped. Agent state updates are not bridged, because they are high-volume and each node tracks its own Agents.
Forwarding targets the node confirmed to be active, not a fixed peer. If neither node is confirmed active, as during a switchover, forwarding pauses and messages wait on the passive node's local stream. Nothing is lost while there is no target.
The passive node's own Scheduler does the forwarding of reliable messages. If it is stopped, job submissions and other reliable work published on that node are accepted and queued on its local broker, but are not delivered to the active Scheduler until the passive Scheduler starts again or the node is promoted.
Recovery on Failover
Failover timing is unchanged. It is governed by the interval in Failover.config and the failover record in the JAMS database. NATS reconnects on its own and keeps retrying, so a broker that is briefly unavailable needs no intervention. Reliable messages that had been forwarded but not yet confirmed are still on the forwarding node's local stream, and when that node is promoted it processes them itself.
Keeping the Two Nodes the Same
- Same NATS port. Each node connects to its peer on the port it has configured itself. See Configuring the NATS Server.
- Same message size limit. If you raise
max_payloadon one node, raise it on both. - Same root CA. Each node has its own certificate, but both must chain to the same root.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
List NATS Configuration shows mutual TLS off, or the listen address is 127.0.0.1 | No certificate files on this node, so NATS refuses network connections | Step 5 above |
| TLS or certificate errors between nodes | The node's certificate chains to its own per-machine root, not the shared one | Import the shared root with /STOREKEY /MakeDefault, then destroy, create, and update as in step 5 |
| The JAMS services cannot connect after a certificate change | The store and the .pem files hold different certificates, or the service was never restarted | Run List NATS Certificate. If the folder certificate shows In Certificate Store: No, either rewrite the folder from the store with Export NATS Certificate /DIRECTORYNAME and then Update NATS Configuration /RESTART, or re-issue with destroy, create, and update as in step 5. Otherwise run Update NATS Configuration /RESTART. |
Update NATS Configuration stops with an error that the folder certificate is not in the store | The .pem files were copied from another machine, are stale, or were created into a different folder. The command refuses to configure NATS with a certificate the JAMS services cannot present. | Export NATS Certificate /DIRECTORYNAME if the store holds the right certificate, otherwise re-issue with destroy, create, and update as in step 5. /FORCE writes the configuration anyway, with a warning, but the JAMS services will not connect until the two agree. |
Create NATS Certificate stops with "already exists" | A certificate is already in the store | Destroy NATS Certificate first |
| Cannot reach the peer's NATS server and certificates are correct | Port 4222 blocked | Allow inbound TCP 4222 on both nodes |
| Job submissions made on the passive node never run | The passive node's Scheduler is stopped, or 4773 or 4222 is blocked | Start the Scheduler on both nodes, then check the ports |
| All three JAMS services fail to start | JAMSNATSServer is not running. Most often the configuration was never generated. | Add NATS Configuration in JAMSRegister, then step 5. Check nats-server.log for a port conflict or a syntax error. |
| Both nodes healthy but neither claims control | A Failover.config mismatch, unrelated to NATS | Make both files identical and restart the Scheduler. The file is read at startup. |
For more, see Troubleshooting NATS.
What NATS Does Not Provide
- The message layer is not replicated. Each node has its own broker and store. If a node's disk is lost, reliable messages queued on it and never forwarded are lost with it. Jobs, Entries, schedules, and history are in SQL Server and unaffected.
- NATS does not pick the active node. The JAMS database does.
- Only one Scheduler processes work at a time. The pair is active and passive, as it was under MSMQ.