The documentation you are viewing is for Dapr v0.11 which is an older version of Dapr. For up-to-date documentation, see the latest version.

NATS streaming

Detailed documentation on the NATS pubsub component

Setup NATS


You can run a NATS server locally using Docker:

docker run -d -name nats-streaming -p 4222:4222 -p 8222:8222 nats-streaming

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


Install NATS on Kubernetes by using the kubectl:

# Single server NATS

kubectl apply -f https://raw.githubusercontent.com/nats-io/k8s/master/nats-server/single-server-nats.yml

kubectl apply -f https://raw.githubusercontent.com/nats-io/k8s/master/nats-streaming-server/single-server-stan.yml

This will install a single NATS-Streaming and Nats into the default namespace. To interact with NATS, find the service with: kubectl get svc stan.

For example, if installing using the example above, the NATS Streaming address would be:

<YOUR-HOST>:4222

Create a Dapr component

The next step is to create a Dapr component for NATS-Streaming.

Create the following YAML file named nats-stan.yaml:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: <NAME>
  namespace: <NAMESPACE>
spec:
  type: pubsub.natsstreaming
  version: v1
  metadata:
  - name: natsURL
    value: <REPLACE-WITH-NATS-SERVER-ADDRESS> # Required. example nats://localhost:4222
  - name: natsStreamingClusterID
    value: <REPLACE-WITH-NATS-CLUSTERID> # Required.
    # blow are subscription configuration.
  - name: subscriptionType
    value: <REPLACE-WITH-SUBSCRIPTION-TYPE> # Required. Allowed values: topic, queue.
  - name: deliverNew
    value: true
  # - name: ackWaitTime
    # value: "" # Optional. See: https://docs.nats.io/developing-with-nats-streaming/acks#acknowledgements
  # - name: maxInFlight
    # value: "" # Optional. See: https://docs.nats.io/developing-with-nats-streaming/acks#acknowledgements
  # - name: durableSubscriptionName
  #   value: ""
  # following subscription options - only one can be used
  # - name: startAtSequence
    # value: 1
  # - name: startWithLastReceived
    # value: false
  # - name: deliverAll
  #   value: false
  # - name: startAtTimeDelta
  #   value: ""
  # - name: startAtTime
  #   value: ""
  # - name: startAtTimeFormat
  #   value: ""

Apply the configuration

Visit this guide for instructions on configuring pub/sub components.

Last modified July 7, 2022: update nav bar v0.11 (#2633) (b309d3d)