|
| 1 | +# Setup RabbitMQ |
| 2 | + |
| 3 | +## Locally |
| 4 | + |
| 5 | +You can run a RabbitMQ server locally using Docker: |
| 6 | + |
| 7 | +``` |
| 8 | +docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3 |
| 9 | +``` |
| 10 | + |
| 11 | +You can then interact with the server using the client port: `localhost:5672`. |
| 12 | + |
| 13 | +## Kubernetes |
| 14 | + |
| 15 | +The easiest way to install RabbitMQ on Kubernetes is by using the [Helm chart](https://github.com/helm/charts/tree/master/stable/rabbitmq): |
| 16 | + |
| 17 | +``` |
| 18 | +helm install --name rabbitmq stable/rabbitmq |
| 19 | +``` |
| 20 | + |
| 21 | +Look at the chart output and get the username and password. |
| 22 | + |
| 23 | +This will install RabbitMQ into the `default` namespace. |
| 24 | +To interact with RabbitMQ, find the service with: `kubectl get svc rabbitmq`. |
| 25 | + |
| 26 | +For example, if installing using the example above, the RabbitMQ server client address would be: |
| 27 | + |
| 28 | +`rabbitmq.default.svc.cluster.local:5672` |
| 29 | + |
| 30 | +## Create a Dapr component |
| 31 | + |
| 32 | +The next step is to create a Dapr component for RabbitMQ. |
| 33 | + |
| 34 | +Create the following YAML file named `rabbitmq.yaml`: |
| 35 | + |
| 36 | +``` |
| 37 | +apiVersion: dapr.io/v1alpha1 |
| 38 | +kind: Component |
| 39 | +metadata: |
| 40 | + name: <name> |
| 41 | +spec: |
| 42 | + type: pubsub.rabbitmq |
| 43 | + metadata: |
| 44 | + - name: host |
| 45 | + value: <REPLACE-WITH-HOST> # Required. Example: "rabbitmq.default.svc.cluster.local:5672" |
| 46 | + metadata: |
| 47 | + - name: consumerID |
| 48 | + value: <REPLACE-WITH-CONSUMER-ID> # Required. Any unique ID. Example: "myConsumerID" |
| 49 | + metadata: |
| 50 | + - name: durable |
| 51 | + value: <REPLACE-WITH-DURABLE> # Optional. Default: "false" |
| 52 | + metadata: |
| 53 | + - name: deletedWhenUnused |
| 54 | + value: <REPLACE-WITH-DELETE-WHEN-UNUSED> # Optional. Default: "false" |
| 55 | + metadata: |
| 56 | + - name: autoAck |
| 57 | + value: <REPLACE-WITH-AUTO-ACK> # Optional. Default: "false" |
| 58 | + metadata: |
| 59 | + - name: deliveryMode |
| 60 | + value: <REPLACE-WITH-DELIVERY-MODE> # Optional. Default: "0". Values between 0 - 2. |
| 61 | + metadata: |
| 62 | + - name: requeueInFailure |
| 63 | + value: <REPLACE-WITH-REQUEUE-IN-FAILURE> # Optional. Default: "false". |
| 64 | +``` |
| 65 | + |
| 66 | +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) |
| 67 | + |
| 68 | + |
| 69 | +## Apply the configuration |
| 70 | + |
| 71 | +### In Kubernetes |
| 72 | + |
| 73 | +To apply the RabbitMQ pub/sub to Kubernetes, use the `kubectl` CLI: |
| 74 | + |
| 75 | +``` |
| 76 | +kubectl apply -f rabbitmq.yaml |
| 77 | +``` |
| 78 | + |
| 79 | +### Running locally |
| 80 | + |
| 81 | +The Dapr CLI will automatically create a directory named `components` in your current working directory with a Redis component. |
| 82 | +To use RabbitMQ, replace the redis_messagebus.yaml file with rabbitmq.yaml above. |
0 commit comments