Connect with the NATS CLI on CloudFerro Cloud
A processing worker needs to reach NATS before it can send useful events. First check the account connection, then use two terminals to send a small JSON message and watch it arrive. This separates connection problems from stream and consumer configuration.
Prerequisites
No. 1 The NATS CLI
Install the client using the NATS CLI installation instructions. The examples use Bash and were checked with NATS CLI 0.5.0. Confirm that the nats command is available:
nats --version
The client must support --tlsfirst. Use a current CLI if your installed version does not recognize that option.
No. 2 Account endpoint and credentials
Obtain the account’s connection command from My Portal and the .creds file prepared in Generate and replace NATS credentials on CloudFerro Cloud. Use the endpoint for that account and region. The machine running the command must be able to reach the public TLS endpoint on port 4222 and read the credentials file.
Set the connection values
My Portal generates a connection command with the account’s exact endpoint:
Connection command provided by My Portal for the NATS account.
export NATS_URL='tls://YOUR_ACCOUNT_HOST:4222'
export NATS_CREDS='/absolute/path/to/nats1.creds'
Replace the whole NATS_URL value with the URL shown by your account in My Portal. Replace NATS_CREDS with the absolute path to the downloaded file. The CLI reads these two environment variables, so later commands can use the same account without repeating the address and path.
Set both variables in each terminal used below. Keep the tls:// scheme, port 4222, and --tlsfirst option.
Check the connection
Run the check from the terminal where the application or its client will run:
nats --tlsfirst server check connection
Check that the command reports a successful connection. This verifies access to the account; it does not create a stream or validate an application’s consumer settings.
Watch a message arrive
In terminal 1, subscribe to a subject reserved for this connection exercise:
nats --tlsfirst sub docs.connection.check --count=1
Wait for the subscription notice. The command then waits for a message.
In terminal 2, with the same connection variables set, publish a JSON event:
nats --tlsfirst pub docs.connection.check \
'{"job_id":"job-001","status":"connected"}'
Terminal 1 should display the received subject and this payload, then exit after one message:
{"job_id":"job-001","status":"connected"}
If it keeps waiting, compare the endpoint and subject in both terminals and confirm that the subscriber was running before publication. Press Ctrl+C to stop a waiting subscriber.
This is a live subscription. The exercise does not create a stream, and starting the subscriber after publishing does not replay the earlier message. The next article stores events so a reader can return later.
Connect an application
An application using an SDK needs the same account endpoint and credentials, with TLS-first enabled in that client. The NATS_URL and NATS_CREDS variables above configure the CLI; application code must explicitly pass the corresponding values to its SDK. A browser session in My Portal does not supply the application’s NATS credentials.
What to do next
Continue with Work with streams and consumers on CloudFerro Cloud to retain job-status events and give two readers their own progress. Keep the connection variables available. If the check fails, follow Troubleshoot Message Streaming on CloudFerro Cloud before changing stream settings.