Integrate with RabbitMQ
Use Olares RabbitMQ middleware by declaring it in OlaresManifest.yaml, then mapping the injected values to your container environment variables.
Install RabbitMQ service
Install the RabbitMQ service from Market.
- Open Market from Launchpad and search for "RabbitMQ".
- Click Get, then Install, and wait for the installation to complete.
Once installed, the service and its connection details will appear in the Middleware list in Control Hub.
Configure OlaresManifest.yaml
In OlaresManifest.yaml, add the required middleware configuration.
- Use the
usernamefield to specify the RabbitMQ user. - Use the
vhostsfield to request one or more virtual hosts (vhosts). Each vhost name is used as the key in.Values.rabbitmq.vhosts.
Example
middleware:
rabbitmq:
username: rabbitmquser
vhosts:
- name: aaaMap to environment variables
In your deployment YAML, map the injected .Values.rabbitmq.* fields to the container environment variables your app requires.
Example
containers:
- name: my-app
# For RabbitMQ, the corresponding values are as follows
env:
- name: RABBITMQ_HOST
value: "{{ .Values.rabbitmq.host }}"
- name: RABBITMQ_PORT
value: "{{ .Values.rabbitmq.port }}"
- name: RABBITMQ_USER
value: "{{ .Values.rabbitmq.username }}"
- name: RABBITMQ_PASSWORD
value: "{{ .Values.rabbitmq.password }}"
# Vhost
# The vhost name configured in OlaresManifest (e.g., aaa)
- name: RABBITMQ_VHOST
value: "{{ .Values.rabbitmq.vhosts.aaa }}"Construct a RabbitMQ connection URI
After configuring the environment variables, you can read them in your application code to construct the connection string.
Below is an example of constructing an AMQP URL using the environment variables:
// Read environment variables
user := os.Getenv("RABBITMQ_USER")
password := os.Getenv("RABBITMQ_PASSWORD")
vhost := os.Getenv("RABBITMQ_VHOST")
host := os.Getenv("RABBITMQ_HOST")
portMQ := os.Getenv("RABBITMQ_PORT")
// Construct AMQP connection string
// Format: amqp://user:password@host:port/vhost
url := fmt.Sprintf("amqp://%s:%s@%s:%s/%s", user, password, host, portMQ, vhost)RabbitMQ values reference
RabbitMQ values are predefined runtime values injected into values.yaml during deployment. They are system-managed and not user-editable.
| Value | Type | Description |
|---|---|---|
.Values.rabbitmq.host | String | RabbitMQ host. |
.Values.rabbitmq.port | Number | RabbitMQ port. |
.Values.rabbitmq.username | String | RabbitMQ username. |
.Values.rabbitmq.password | String | RabbitMQ password. |
.Values.rabbitmq.vhosts | Map<String,String> | Requested vhosts, keyed by vhost name. For example, a request for myvhost is available at .Values.rabbitmq.vhosts.myvhost. |