Skip to content

Commit 561a603

Browse files
weltekialexellis
authored andcommitted
Add documentation for the RabbitMQ connector
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
1 parent 559b341 commit 561a603

File tree

3 files changed

+95
-5
lines changed

3 files changed

+95
-5
lines changed

docs/openfaas-pro/rabbitmq-events.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Trigger function from RabbitMQ
2+
3+
Trigger OpenFaaS functions from RabbitMQ messages.
4+
5+
> Note: This feature is included for [OpenFaaS Standard & For Enterprises](https://openfaas.com/pricing/) customers.
6+
7+
## Installation
8+
9+
* Setup the connector
10+
11+
You can install the RabbitMQ connector using its [helm chart](https://github.com/openfaas/faas-netes/tree/master/chart/rabbitmq-connector).
12+
13+
The `values.yaml` file can be customised to suit your needs.
14+
15+
* Configure the connector for you needs by defining a values.yaml file
16+
17+
```yaml
18+
rabbitmqURL: "amqp://rabbitmq.rabbitmq.svc.cluster.local:5672"
19+
20+
queues:
21+
- name: queue1
22+
durable: true
23+
```
24+
25+
Use the `queues` parameter to configure a list of queues to which the connector should subscribe. When a message is received on a queue, the connector will invoke any function that has the queue name listed in its `topic` annotation.
26+
27+
Queue configuration:
28+
29+
* `name` - The name of the queue. (Required)
30+
* `durable` - Specifies whether the queue should survive broker restarts.
31+
* `nowait` - Whether to wait for confirmation from the server when declaring the queue.
32+
* `autodelete` - Whether the queue should be deleted automatically when no consumers are connected.
33+
* `exclusive` - Specifies whether the queue should be exclusive to the connection that created it.
34+
35+
If your RabbitMQ requires a TLS connection make sure to use `amqps://` as the scheme in the url.
36+
37+
## Usage
38+
39+
To test the connector, you can deploy the [printer function](https://github.com/openfaas/store-functions/blob/master/printer/handler.go). It prints out the HTTP headers and body of any invocation.
40+
41+
Add an annotation `topic=queue1` so that the function is invoked for any message published to the queue with name queue1.
42+
Each time a function is invoked by the connector it will receive the message from the queue as the HTTP body.
43+
44+
```bash
45+
faas-cli store deploy printer \
46+
--annotation topic=queue1
47+
```
48+
49+
Publish a message on the queue for testing. We will be using the [RabbitMQ management CLI](https://www.rabbitmq.com/docs/management-cli) for this.
50+
51+
```bash
52+
./rabbitmqadmin publish \
53+
routing_key="queue1" payload='Hello, Task Queue!' properties='{"message_id":"1"}'
54+
```
55+
56+
Take a look at the logs of the printer function to inspect the invocations made by the connector. You should see the following output:
57+
58+
```bash
59+
faas-cli logs printer
60+
61+
2024-12-02T16:58:49Z X-Forwarded-For=[10.42.0.4:58102]
62+
2024-12-02T16:58:49Z X-Msg-Id=[1]
63+
2024-12-02T16:58:49Z X-Start-Time=[1733158729048068067]
64+
2024-12-02T16:58:49Z X-Call-Id=[ea459d66-e1af-4846-9f73-18561f69074f]
65+
2024-12-02T16:58:49Z X-Connector=[connector-sdk]
66+
2024-12-02T16:58:49Z X-Topic=[queue1]
67+
2024-12-02T16:58:49Z User-Agent=[openfaas-gateway/0.4.34]
68+
2024-12-02T16:58:49Z Accept-Encoding=[gzip]
69+
2024-12-02T16:58:49Z Content-Type=[text/plain]
70+
2024-12-02T16:58:49Z X-Forwarded-Host=[gateway.openfaas:8080]
71+
2024-12-02T16:58:49Z
72+
2024-12-02T16:58:49Z Hello, Task Queue!
73+
2024-12-02T16:58:49Z
74+
2024-12-02T16:58:49Z 2024/12/02 16:58:49 POST / - 202 Accepted - ContentLength: 0B (0.0003s)
75+
```
76+
77+
Additional headers are made available to the request. These headers contain RabbitMQ message metadata.
78+
79+
* `X-Topic` - topic that triggered the function.
80+
* `X-Msg-Id` - the message identifier.
81+
82+
The default content-type is configured as `text/plain`, but can be changed to another content-type such as `application/json` or `application/octet-stream` by the [values.yaml file](https://github.com/openfaas/faas-netes/blob/master/chart/kafka-connector/values.yaml) for the connector.
83+
84+
## Would you like a demo?
85+
86+
Feel free to reach out to us for a demo or to ask any questions you may have.
87+
88+
* [Talk to us](https://openfaas.com/pricing/)

docs/reference/triggers.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ If you are unable to expose a public endpoint for any reason, and still need eve
8585

8686
[Read the documentation](/openfaas-pro/sns-events)
8787

88+
### RabbitMQ
89+
90+
Trigger your functions from messages published to RabbitMQ queues.
91+
92+
[Read the documentation](/openfaas-pro/rabbitmq-events)
93+
8894
### Cron Connector
8995

9096
The [cron-connector](https://github.com/openfaas/cron-connector) can be used to trigger functions on a timed schedule. It uses traditional cron expressions.
@@ -124,11 +130,6 @@ No connector is required to trigger OpenFaaS functions using CloudEvents.
124130

125131
Follow this example to learn how to trigger functions using the Azure EventGrid and CloudEvents: [johnmccabe/cloudevents-slack-demo](https://github.com/johnmccabe/cloudevents-slack-demo)
126132

127-
### RabbitMQ (third-party project)
128-
129-
Invoke functions from RabbitMQ topics. This is a third party project.
130-
131-
More information in the repository: [templum/rabbitmq-connector](https://github.com/Templum/rabbitmq-connector)
132133

133134
### VMware vCenter
134135

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ nav:
162162
- Postgres events: ./openfaas-pro/postgres-events.md
163163
- AWS SQS events: ./openfaas-pro/sqs-events.md
164164
- AWS SNS events: ./openfaas-pro/sns-events.md
165+
- RabbitMQ events: ./openfaas-pro/rabbitmq-events.md
165166
# - Federated Gateway: ./openfaas-pro/federated-gateway.md
166167
- Airgapped installation: ./openfaas-pro/airgap.md
167168
- Function Builder API: ./openfaas-pro/builder.md

0 commit comments

Comments
 (0)