> For the complete documentation index, see [llms.txt](https://docs.greenstand.org/application-platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.greenstand.org/application-platform/rabbitmq.md).

# RabbitMQ

Instructions for setup of rabbitmq on local docker desktop

## Configuration

Until requirements make more advanced configurations necessary, the following patterns shall be followed:

* All message producers and consumers shall  use the default direct exchange, named 'amq.direct'
* Queues are created and bound to amq.direct by consumer microservices
  * In most cases the default routing is enough.  Default routing states that the queue name and routing key are a direct match.
* Producers emit messages with documented routing keys

## Resources

Terraform configuration

{% embed url="<https://registry.terraform.io/providers/cyrilgdn/rabbitmq/latest/docs/resources/exchange>" %}

Background on rabbitmq configuration: <https://www.cloudamqp.com/blog/part4-rabbitmq-for-beginners-exchanges-routing-keys-bindings.html>

### Running RabbitMQ on Docker Kubernetes&#x20;

#### Required

* Docker Desktop with Kubernetes Enabled
* Fork/Clone the current Greenstand [Greenstand Infrastructure Repo](https://github.com/Greenstand/treetracker-infrastructure/tree/master/rabbitmq), the code for the Greenstand RabbitMQ infrastructure is in the RabbitMQ folder
* kubectl

#### How to run

In the deployment folder the deploy-dev.sh file contains the scripts to set up the RabbitMQ cluster and PodMonitor for the RabbitMQ pods.

Since we're running on local docker-desktop kubernetes cluster, we'll need to change the name cluster name in the deploy-dev.sh.&#x20;

```
# kubectl config use-context do-sfo2-dev-k8s-treetracker
kubectl config use-context docker-desktop
```

#### Install CRDs&#x20;

RabbitmqCluster CRD &#x20;

```
kubectl apply -f https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml
```

PodMonitor CRD

```
LATEST=$(curl -s https://api.github.com/repos/prometheus-operator/prometheus-operator/releases/latest | jq -cr .tag_name) curl -sL https://github.com/prometheus-operator/prometheus-operator/releases/download/${LATEST}/bundle.yaml | kubectl create -f - 
```

#### Create Namespace

For Rabbitmq Greenstand is using the "rabbitmq-cluster" namespace, to create the namespace on your docker kubernetes cluster refer to the docs [here](https://kubernetes.io/docs/tasks/administer-cluster/namespaces-walkthrough/).
