Webhooks¶
A webhook pushes messages to an HTTPS endpoint of yours: every message of a topic (optionally filtered by routing key), or every message of one queue. Use it when the receiver cannot hold a connection open or poll.
API only for now
Webhooks are managed through the API. Console pages are not available yet.
Create¶
mutation {
createQueueWebhook(input: {
name: "orders-to-erp"
topic: "events" # or queue: "orders"
filter: "order.*" # topics only, optional
url: "https://erp.example.com/hooks/rso"
secret: "<a long random string>"
headers: [{ name: "X-Api-Key", value: "<value>" }]
}) { name state }
}
- The source is either a topic or a queue and cannot be changed later. A webhook on a queue takes that queue's messages, so do not also consume the queue yourself.
- The URL, the secret, the static headers and
enabledcan be changed withupdateQueueWebhook. The secret and header values are stored encrypted and are never returned.
The request¶
Each message is one POST whose body is the message exactly as it was published.
| Header | Value |
|---|---|
X-RSO-Webhook |
the webhook's name |
X-RSO-Delivery-Id |
stable for a message: the same on every retry and on a duplicate |
X-RSO-Attempt |
1 for the first attempt |
X-RSO-Topic, X-RSO-Routing-Key |
where the message was published |
X-RSO-Message-Id |
the publisher's message id, if it gave one |
X-RSO-Attributes |
the message attributes as JSON |
X-RSO-Timestamp |
Unix seconds when the request was signed |
X-RSO-Signature |
only with a secret: v1=<hex HMAC-SHA256(secret, "<timestamp>.<body>")> |
Answer with any 2xx within 10 seconds to accept the message. Redirects are not followed.
Verify the signature¶
import hashlib, hmac, time
def is_authentic(secret: str, timestamp: str, body: bytes, signature: str) -> bool:
if abs(time.time() - int(timestamp)) > 300: # reject old requests
return False
expected = "v1=" + hmac.new(
secret.encode(), timestamp.encode() + b"." + body, hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, signature)
Use the raw request body, before any JSON parsing.
Delivery guarantees¶
At-least-once. A message leaves its queue only after your endpoint answered 2xx, or after it
was moved to the webhook's dead-letter queue.
- Retries: up to 6 attempts per message, waiting 1 s, 5 s, 30 s, 2 min and 5 min between them (about eight minutes in all).
- Dead letters: a message that failed every attempt goes to the queue
rso-wh-<name>-deadwith the attributesrso-dead-reason,rso-dead-statusandrso-dead-attempts. Read it like any other queue. - Pausing: after 10 messages in a row end in the dead-letter queue the webhook is paused.
Messages wait (within the queue limits) until you call
resumeQueueWebhook. - Duplicates are possible, for example when a delivery is interrupted after your endpoint
processed the message. Deduplicate on
X-RSO-Delivery-Id. - Order is not guaranteed: several messages are in flight at once and a retried message is overtaken by later ones.
queueWebhook(name) reports the state (ACTIVE, PAUSED, DISABLED), the last status and
error, consecutive failures, delivered and dead-lettered counts, and how many messages are
waiting.
Where a webhook may point¶
HTTPS only, to a public address, on port 443 or a port from 1024 up. URLs with credentials in them, private and internal addresses, and names that resolve to them are refused.
Limits and permissions¶
webhooksquota: 10 per tenant by default.- At most 10 static headers; the
X-RSO-*headers cannot be overridden. - Response bodies are ignored beyond 64 KiB.
- Reading webhooks and managing them are separate permissions; editors hold both by default. They apply to the whole tenant and cannot be limited to single webhooks yet.