JetStream KV

Detailed information on the JetStream KV state store component

Component format

To setup a JetStream KV state store create a component of type state.jetstream. See this guide on how to create and apply a state store configuration.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: state.jetstream
  8. version: v1
  9. metadata:
  10. - name: natsURL
  11. value: "nats://localhost:4222"
  12. - name: jwt
  13. value: "eyJhbGciOiJ...6yJV_adQssw5c" # Optional. Used for decentralized JWT authentication
  14. - name: seedKey
  15. value: "SUACS34K232O...5Z3POU7BNIL4Y" # Optional. Used for decentralized JWT authentication
  16. - name: bucket
  17. value: "<bucketName>"

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.

Spec metadatafield

FieldRequiredDetailsExample
natsURLYNATS server address URLnats://localhost:4222
jwtNNATS decentralized authentication JWTeyJhbGciOiJ…6yJV_adQssw5c
seedKeyNNATS decentralized authentication seed keySUACS34K232O…5Z3POU7BNIL4Y
bucketYJetStream KV bucket name“<bucketName>”

Create a NATS server

You can run a NATS Server with JetStream enabled locally using Docker:

  1. docker run -d -p 4222:4222 nats:latest -js

You can then interact with the server using the client port: localhost:4222.

Install NATS JetStream on Kubernetes by using the helm:

  1. helm repo add nats https://nats-io.github.io/k8s/helm/charts/
  2. helm install my-nats nats/nats

This installs a single NATS server into the default namespace. To interact with NATS, find the service with: kubectl get svc my-nats.

Creating a JetStream KV bucket

It is necessary to create a key value bucket, this can easily done via NATS CLI.

  1. nats kv add <bucketName>

Last modified June 23, 2022: Merge pull request #2550 from ItalyPaleAle/cosmosdb-harcoded-dapr-version (cf03237)