add How To for pub-sub (#143)

This commit is contained in:
Yaron Schneider 2019-10-16 07:57:43 -07:00 committed by GitHub
parent d32456cb32
commit 8f1b8f0ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 121 additions and 8 deletions

View File

@ -0,0 +1,45 @@
# Setup a Dapr pub/sub
Dapr integrates with existing message buses to provide apps with the ability to create event-driven, loosely coupled architectures where producers send events to consumers via topics.
Currently, Dapr supports the configuration of one message bus per cluster.
Pub/Sub message buses are extensible and can be found in the [components-contrib repo](https://github.com/dapr/components-contrib).
A pub/sub in Dapr is described using a `Component` file:
```
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: messagebus
spec:
type: pubsub.<NAME>
metadata:
- name: <KEY>
value: <VALUE>
- name: <KEY>
value: <VALUE>
...
```
The type of message bus is determined by the `type` field, and things like connection strings and other metadata are put in the `.metadata` section.
Even though you can put plain text secrets in there, it is recommended you use a [secret store](../../concepts/components/secrets.md).
## Running locally
When running locally with the Dapr CLI, a component file for a Redis Streams pub/sub will be automatically created in a `components` directory in your current working directory.
You can make changes to this file the way you see fit, whether to change connection values or replace it with a different pub/sub.
## Running in Kubernetes
Dapr uses a Kubernetes Operator to update the sidecars running in the cluster with different components.
To setup a pub/sub in Kubernetes, use `kubectl` to apply the component file:
```
kubectl apply -f pubsub.yaml
```
## Reference
[Setup Redis Streams](./setup-redis-streams.md)

View File

@ -1,3 +1,3 @@
# documentation
# Setup Kafka
Content for this file to be added

View File

@ -1,3 +1,74 @@
# documentation
# Setup Redis Streams
Content for this file to be added
## Creating a Redis instance
Dapr can use any Redis instance - containerized, running on your local dev machine, or a managed cloud service, provided the version of Redis is 5.0.0 or later. If you already have a Redis instance > 5.0.0 installed, move on to the [Configuration](#configuration) section.
### Running locally
The Dapr CLI will automatically create and setup a Redis Streams instance for you when you.
The Redis instance will be installed via Docker when you run `dapr init`, and the component file will be setup with `dapr run`.
### Creating a Redis instance in your Kubernetes Cluster using Helm
We can use [Helm](https://helm.sh/) to quickly create a Redis instance in our Kubernetes cluster. This approach requires [Installing Helm](https://github.com/helm/helm#install).
1. Install Redis into your cluster: `helm install stable/redis --name redis --set image.tag=5.0.5-debian-9-r104`. Note that we're explicitly setting an image tag to get a version greater than 5, which is what Dapr' pub-sub functionality requires.
2. Run `kubectl get pods` to see the Redis containers now running in your cluster.
3. Run `kubectl get svc` and copy the cluster IP of your `redis-master`. Add this IP as the `redisHost` in your redis.yaml file, followed by ":6379". For example:
```yaml
metadata:
- name: redisHost
value: "10.0.125.130:6379"
```
4. Next, we'll get our Redis password, which is slightly different depending on the OS we're using:
- **Windows**: Run `kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" > encoded.b64`, which will create a file with your encoded password. Next, run `certutil -decode encoded.b64 password.txt`, which will put your redis password in a text file called `password.txt`. Copy the password and delete the two files.
- **Linux/MacOS**: Run `kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 --decode` and copy the outputted password.
Add this password as the `redisPassword` value in your redis.yaml file. For example:
```yaml
- name: redisHost
value: "lhDOkwTlp0"
```
### Other ways to create a Redis Database
- [AWS Redis](https://aws.amazon.com/redis/)
- [GCP Cloud MemoryStore](https://cloud.google.com/memorystore/)
## Configuration
To setup Redis, you need to create a component for `pubsub.redis`.
<br>
The following yaml files demonstrates how to define each. **Note:** yaml files below illustrate secret management in plain text. In a production-grade application, follow [secret management](../../concepts/components/secrets.md) instructions to securely manage your secrets.
### Configuring Redis Streams for Pub/Sub
Create a file called pubsub.yaml, and paste the following:
```yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: messagebus
spec:
type: pubsub.redis
metadata:
- name: redisHost
value: <HOST>
- name: redisPassword
value: <PASSWORD>
```
## Apply the configuration
### Kubernetes
```
kubectl apply -f pubsub.yaml
```
### Standalone
By default the Dapr CLI creates a local Redis instance when you run `dapr init`. When you run an app using `dapr run`, the component file will automatically be created for you in a `components` dir in your current working directory.

View File

@ -1,3 +0,0 @@
# documentation
Content for this file to be added

View File

@ -23,7 +23,7 @@ spec:
```
The type of database is determined by the `type` field, and things like connection strings and other metadata are put in the `.metadata` section.
Even though you can put plain text secrets in there, it is recommended you use a s[ecret store](../../concepts/components/secrets.md).
Even though you can put plain text secrets in there, it is recommended you use a [secret store](../../concepts/components/secrets.md).
## Running locally
@ -34,7 +34,7 @@ You can make changes to this file the way you see fit, whether to change connect
## Running in Kubernetes
Dapr uses a Kubernetes Operator to update the sidecars running in the cluster with different components.
To setup a state store to Kubernetes, use `kubectl` to apply the component file:
To setup a state store in Kubernetes, use `kubectl` to apply the component file:
```
kubectl apply -f statestore.yaml