# NATS

## Reference Links

| Description      | URL                                  |
| ---------------- | ------------------------------------ |
| Official website | <https://nats.io/>                   |
| DockerHub image  | <https://hub.docker.com/_/nats>      |
| NATS Go SDK      | <https://github.com/nats-io/nats.go> |
| NATS JS SDK      | <https://github.com/nats-io/nats.js> |
| NATS Python SDK  | <https://github.com/nats-io/nats.py> |
| NKeys repository | <https://github.com/nats-io/nkeys>   |
| NATS CLI tool    | <https://github.com/nats-io/natscli> |

## Configuration

### NKey generation

```makefile
nats-nkey:
	nk -gen user -pubout
```

### Server

This file should be available on the system running NATS. NATS should be started using the `--config` or `-c` flag pointing to the path of this file (eg. `nats-server -c /path/to/this.conf`

```properties
accounts: {
  $SYS: {
    users: [
      # generate using `nk-gen user -pubout`
      {nkey: "..."},
    ]
  }
}

authorization: {
  users: [
    # generate using `nk-gen user -pubout`
    {nkey: "..."},
  ]
}

cluster: {
  name: "example"
}

jetstream: {
  max_memory_store: 2GB
  max_file_store: 8GB
}
```

## Docker

### Image

{% embed url="<https://hub.docker.com/_/nats>" %}

### Compose&#x20;

The following starts NATS using the leanest image base (`scratch`) and with JetStream enabled:

<pre class="language-yaml"><code class="lang-yaml"><strong>version: "3.7"
</strong>services:
  nats: # access with `nats server info`
    # image reference: https://hub.docker.com/_/nats
    image: library/nats:2.9.20-scratch
    entrypoint:
      - /nats-server
      - -js
      - -c
      - /etc/nats/server.conf
    ports:
      - "4222:4222"
      # # enable as needed
      # - "6222:6222"
      # - "8222:8222"
    network_mode: host
    volumes:
      - ./.data/nats/config/server.conf:/etc/nats/server.conf
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.joeir.net/application-infrastructure/message-brokers/nats.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
