You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`exchanges[]`: List of exchanges the stack should consume from.
25
+
-`name`: Exchange name.
26
+
-`kind`: Exchange type (e.g. `topic`).
27
+
-`durable`: Whether the exchange is durable.
28
+
-`declare_exchange`: If true, the exchange is declared on startup.
29
+
-`dlx_name`, `dlq_name`: Optional defaults for queues under this exchange.
30
+
-`queues[]`: List of queues to consume.
31
+
-`name`: Queue name.
32
+
-`bindings[]`: Routing keys to bind to the exchange.
33
+
-`declare`: If true, declare the queue on startup.
34
+
-`prefetch`: Per-consumer QoS prefetch.
35
+
-`delivery_limit`: x-delivery-limit for quorum queues.
36
+
-`dlx_name`, `dlq_name`: Optional overrides per queue.
37
+
38
+
Example:
39
+
40
+
```yaml
41
+
rabbitmq:
42
+
enabled: true
43
+
url: amqp://guest:guest@localhost:5672/
44
+
tls:
45
+
# root_ca: /etc/ssl/certs/ca.pem
46
+
insecure_skip_validation: false
47
+
# server_name: rabbit.internal
48
+
exchanges:
49
+
- name: auth
50
+
kind: topic
51
+
durable: true
52
+
declare_exchange: true
53
+
queues:
54
+
- name: user.password.updated
55
+
declare: true
56
+
prefetch: 8
57
+
delivery_limit: 5
58
+
bindings:
59
+
- password.changed
60
+
- name: user.created
61
+
declare: true
62
+
prefetch: 8
63
+
delivery_limit: 5
64
+
bindings:
65
+
- user.created
66
+
```
67
+
68
+
### Handlers
69
+
70
+
Handlers implement a simple interface:
71
+
72
+
```go
73
+
type Handler interface {
74
+
Handle(ctx context.Context, d amqp.Delivery) error
75
+
}
76
+
```
77
+
78
+
Returning `nil` acknowledges the message. Returning a non-nil error causes the message to be requeued (subject to broker policies and delivery limits).
79
+
80
+
Queue names are mapped to handlers in the stack. For example:
81
+
82
+
-`user.password.updated` → updates an instance passphrase when a `password.changed` routing key is received.
83
+
-`user.created` → validates and processes user creation events.
84
+
85
+
Message schemas are JSON and validated in the handler. Example payload for `user.password.updated`:
86
+
87
+
```json
88
+
{
89
+
"twakeId": "string",
90
+
"iterations": 100000,
91
+
"hash": "base64",
92
+
"publicKey": "base64",
93
+
"privateKey": "cipherString",
94
+
"key": "cipherString",
95
+
"timestamp": 1726040000,
96
+
"domain": "example.cozy.cloud"
97
+
}
98
+
```
99
+
100
+
Example payload for `user.created`:
101
+
102
+
```json
103
+
{
104
+
"twakeId": "string",
105
+
"mobile": "string",
106
+
"internalEmail": "string",
107
+
"iterations": 100000,
108
+
"hash": "base64",
109
+
"publicKey": "base64",
110
+
"privateKey": "cipherString",
111
+
"key": "cipherString",
112
+
"timestamp": 1726040000
113
+
}
114
+
```
115
+
116
+
### Lifecycle
117
+
118
+
On startup, if `rabbitmq.enabled` is true:
119
+
120
+
1. The manager creates an AMQP connection (TLS if configured) and retries with exponential backoff.
121
+
2. It declares configured exchanges and queues (if `declare_*` flags are set).
122
+
3. It binds queues to their routing keys and starts consumers.
123
+
4. It exposes a readiness channel internally so tests can wait until consumption is active.
124
+
5. It monitors the connection and restarts consumers upon reconnection.
125
+
126
+
### Adding a new queue handler
127
+
128
+
Follow these steps to introduce a new queue and its handler.
129
+
130
+
1) Define the message schema and the handler
131
+
132
+
Create a handler type that implements the `Handle(ctx, d)` method and an accompanying message struct.
133
+
134
+
```go
135
+
// Example message payload consumed from the queue
0 commit comments