The NATS stream source is failing because the JetStream server cannot find the stream definition it’s configured to use.

This typically happens when the stream exists on the server but the source configuration on the client side has a typo in the stream name, or the stream simply hasn’t been created on the JetStream server yet.

Common Causes and Fixes:

  1. Typo in Stream Name: The most frequent culprit is a simple misspelling of the stream name in your NATS client configuration.

    • Diagnosis: Check your NATS client configuration file (e.g., nats-streaming-client.conf, application code) for the stream parameter associated with your stream source. Compare this string exactly with the stream name as defined on the JetStream server.
    • Fix: Correct the typo in your client configuration. For example, if your stream is named orders on the server but your client config has order, change it to orders.
    • Why it works: NATS JetStream is case-sensitive and requires an exact name match to locate and access a stream.
  2. Stream Not Yet Created: The stream might not have been declared and created on the JetStream server before the stream source tried to connect to it.

    • Diagnosis: Use the nats CLI tool to list available streams on your JetStream server.
      nats context select <your_nats_context>
      nats stream ls
      
      If your stream isn’t listed, it needs to be created.
    • Fix: Create the stream using the nats CLI. For example, to create a stream named my-stream that can hold up to 1 million messages:
      nats stream add my-stream --storage file --max-msgs 1000000 --subjects "events.>"
      
      Adjust storage, max-msgs, and subjects as per your requirements.
    • Why it works: This explicitly defines the stream’s existence, metadata, and subject filtering on the JetStream server, making it discoverable by clients.
  3. Incorrect JetStream Server Endpoint: Your NATS client might be connecting to the wrong JetStream server, or the server it’s connecting to doesn’t have the stream defined.

    • Diagnosis: Verify the servers list in your NATS client configuration. Ensure it points to the correct NATS server URL where your JetStream instance is running and where the stream was created.
      # Example client config snippet
      servers:
        - nats://localhost:4222
      
    • Fix: Update the servers list in your client configuration to the correct NATS server address.
    • Why it works: Clients must establish a connection to the NATS server that hosts the JetStream service to access its streams.
  4. JetStream Not Enabled or Running: The JetStream feature might not be enabled on the NATS server, or the NATS server process itself is not running.

    • Diagnosis: Check the NATS server configuration file (e.g., nats-server.conf). Ensure the jetstream: { enabled: true } section is present and not commented out. Also, verify that the NATS server process is active.
      # On Linux/macOS
      ps aux | grep nats-server
      
    • Fix: Enable JetStream in the nats-server.conf and restart the NATS server.
      # nats-server.conf
      jetstream: {
        enabled: true
        max_memory: 256MiB
        max_storage: 1GiB
      }
      
      Then restart: nats-server -c nats-server.conf
    • Why it works: JetStream functionality is a feature that needs to be explicitly activated and configured on the NATS server.
  5. Permissions Issue (Less Common for "Not Found"): While less likely to cause a direct "Not Found" error and more often a "Permission Denied," in some edge cases, a misconfigured account or user might not have the necessary permissions to see or interact with the stream, leading to it appearing as if it doesn’t exist.

    • Diagnosis: Examine the NATS user/account configuration. Ensure the user or account your client is authenticating with has the jetstream permission enabled for the specific stream or for all streams in the relevant context.
    • Fix: Update the NATS account or user configuration to grant jetstream permissions. For example, in an account configuration:
      {
        "jetstream": {
          "max_memory": 1024,
          "max_storage": 1024,
          "domain": "my.domain",
          "streams": {
            "allow": ["my-stream", "another-stream"],
            "deny": []
          }
        }
      }
      
      Ensure the client is connecting using credentials associated with this account/user.
    • Why it works: Explicitly granting permissions allows the authenticated client to discover and operate on the stream.
  6. NATS Server Restarted After Stream Creation: If the NATS server was restarted after the stream was created, but before the client was fully initialized or reconnected, the client might still be trying to use an old, stale connection or internal state.

    • Diagnosis: Check the NATS server logs for startup messages and stream recovery. Verify the timestamp of the stream creation/recovery against the client’s uptime or last connection attempt.
    • Fix: Restart your NATS client application or force a reconnect if your client library supports it.
    • Why it works: A client restart ensures it establishes a fresh connection to the NATS server and re-queries the available JetStream streams.

After resolving the "stream source not found" error, the next common issue you might encounter is a "stream not found" error if the stream name is still incorrect, or a "permission denied" error if the client’s credentials lack the necessary JetStream access.

Want structured learning?

Take the full Nats course →