The events gateway
The other plugins put one connection behind a route, in one direction. The Events gateway puts channels behind a route: each one has a name callers use, is bound to a connection with the options the route fixes there, and offers some operations. One route is then a whole event API, with its AsyncAPI document.
| Endpoint | Operation | Does |
|---|---|---|
GET /channels | the channels the caller may use, with what it may do there | |
POST /channels/<name>/events | publish | publishes the body, as the ingester does |
GET /channels/<name>/events | subscribe | streams the events as newline-delimited JSON, as the consumer does, or as server-sent events with Accept: text/event-stream |
/channels/<name>/ws | publish, subscribe | a websocket: what the client sends is published, what the channel delivers is sent |
POST /channels/<name>/request | request | request reply |
GET /asyncapi.json | the AsyncAPI 3.0 document of the channels the caller may use |
The endpoints are read from the end of the path: a route on api.example.com/events serves
/events/channels/orders/events.
Configuration
{
"channels": [
{
"name": "orders",
"description": "Orders, as they are placed",
"enabled": true,
"operations": ["publish", "subscribe"],
"ref": "connection_...",
"options": { "topic": "orders.v1", "group": "${apikey.clientId}", "delivery": "at-least-once" },
"allowed_overrides": ["take", "drop", "duration", "format", "heartbeat"],
"allowed_topics": []
},
{
"name": "quotes",
"operations": ["request"],
"ref": "connection_...",
"options": { "topic": "quote-requests", "reply_to": "quote-replies", "timeout": "5000" }
}
]
}
name: what callers use, a segment of the paths: letters, digits,.,_,~and-.operations:publish,subscribe,request. Without it,publishandsubscribe.enabled: a disabled channel does not exist for callers.ref,options,allowed_overrides,allowed_topics,include_query,include_headers: what any other plugin is configured with (The plugins): the connection, what the route fixes there, what callers may ask. Each channel has its own.
A channel is served exactly as the plugin of a single connection serves it: the same options, the same policy, the same errors.
Websockets
/channels/<name>/ws publishes what the client sends and sends what the channel delivers, on one
socket. ?mode=publish or ?mode=subscribe opens one side only (a client that only publishes gets
nothing back). Without mode, the socket does what the channel offers and the caller may do.
Api keys and their scopes
The route's security applies first, as for any plugin. An api key may then be narrowed to some
channels and operations by its event_brokers_scopes metadata: scopes separated by spaces or commas,
each <channel>:<operation>, * standing for anything.
event_brokers_scopes | The key may |
|---|---|
| (no metadata) | everything the channels offer |
orders:subscribe | read orders, nothing else |
orders:* payments:publish | everything on orders, publish to payments |
eu-*:subscribe | read the channels whose name starts with eu- |
audit | everything on audit |
| (empty) | nothing |
A channel the key may do nothing on does not exist for it (404), and is left out of /channels and
of the AsyncAPI document. A call without an api key (a route without api keys) may do everything.
Errors
On top of the errors of the plugins:
| Status | When |
|---|---|
403 | the api key may not do this operation on this channel |
404 | no such channel (or disabled, or none of the caller's business), or a path the gateway does not serve |
405 | the channel does not offer this operation (Allow says what it answers), or a method the endpoint does not serve |
426 | /channels/<name>/ws called without opening a websocket |