From 54a50dfa5bd3619691b2685a9ed69a31d55724dc Mon Sep 17 00:00:00 2001 From: Yaron Schneider Date: Mon, 11 Nov 2019 12:24:58 -0800 Subject: [PATCH] Add NATS How To (#239) --- howto/setup-pub-sub-message-broker/README.md | 1 + .../setup-nats.md | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 howto/setup-pub-sub-message-broker/setup-nats.md diff --git a/howto/setup-pub-sub-message-broker/README.md b/howto/setup-pub-sub-message-broker/README.md index 1c1f8bdb8..c0c849efe 100644 --- a/howto/setup-pub-sub-message-broker/README.md +++ b/howto/setup-pub-sub-message-broker/README.md @@ -43,3 +43,4 @@ kubectl apply -f pubsub.yaml ## Reference [Setup Redis Streams](./setup-redis.md) +[Setup NATS](./setup-nats.md) diff --git a/howto/setup-pub-sub-message-broker/setup-nats.md b/howto/setup-pub-sub-message-broker/setup-nats.md new file mode 100644 index 000000000..d417f0ff7 --- /dev/null +++ b/howto/setup-pub-sub-message-broker/setup-nats.md @@ -0,0 +1,62 @@ +# Setup NATS + +## Locally + +You can run a NATS server locally using Docker: + +``` +docker run -d --name nats-main -p 4222:4222 -p 6222:6222 -p 8222:8222 nats +``` + +You can then interact with the server using the client port: `localhost:4222`. + +## Kubernetes + +The easiest way to install NATS on Kubernetes is by using the [Helm chart](https://github.com/helm/charts/tree/master/stable/nats): + +``` +helm install --name nats stable/nats +``` + +This will install NATS into the `default` namespace. +To interact with NATS, find the service with: `kubectl get svc nats-client`. + +For example, if installing using the example above, the NATS server client address would be: + +`nats-client.default.svc.cluster.local:4222` + +## Create a Dapr component + +The next step is to create a Dapr component for NATS. + +Create the following YAML file named `nats.yaml`: + +``` +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: +spec: + type: pubsub.nats + metadata: + - name: natsURL + value: # Required. Example: "nats-client.default.svc.cluster.local:4222" +``` + +The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described [here](../../concepts/components/secrets.md) + + +## Apply the configuration + +### In Kubernetes + +To apply the NATS pub/sub to Kubernetes, use the `kubectl` CLI: + +``` +kubectl apply -f nats.yaml +``` + +### Running locally + +The Dapr CLI will automatically create a directory named `components` in your current working directory with a Redis component. +To use NATS, replace the redis_messagebus.yaml file with nats.yaml above.