Skip to content

Transports

Kafka, NATS, AMQP, AWS, Google Cloud, Azure, PostgreSQL, sinks and feeds

Besides HTTP, subscribers and dead-letter services can be Kafka topics, NATS subjects, AMQP exchanges, Amazon SQS queues and SNS topics, Google Cloud Pub/Sub topics, Azure Service Bus queues and topics, or other Cloud Streams gateways. Gateways can also consume events from Kafka topics, NATS subjects, AMQP queues, SQS queues, Pub/Sub subscriptions, Service Bus queues and subscriptions, and PostgreSQL databases, called feeds. The scheme of an address selects its transport:

Transport Address Delivers Consumes
HTTP https://orders.example.com/events yes through POST /api/events/pub
Kafka kafka://kafka:9092/orders to a topic from a topic
NATS nats://nats:4222/orders.placed?jetstream=true to a subject from a subject, wildcards allowed
AMQP 0-9-1 (RabbitMQ) amqp://rabbitmq/?exchange=orders, amqps:// over TLS to an exchange from a queue: amqp://rabbitmq/?queue=orders
Amazon SQS sqs://eu-west-1/123456789012/orders to a queue, FIFO included from a queue
Amazon SNS sns://eu-west-1/123456789012/orders to a topic, FIFO included through the SQS queues it notifies
Google Cloud Pub/Sub pubsub://my-project/topics/orders to a topic from a subscription: pubsub://my-project/subscriptions/gateway
Azure Service Bus servicebus://orders.servicebus.windows.net/orders to a queue or a topic from a queue, or a topic’s subscription: ...?subscription=gateway
Azure Event Hubs kafka://orders.servicebus.windows.net:9093/orders?tls=true to an event hub, through its Kafka endpoint from an event hub, through its Kafka endpoint
Cloud Streams cloudstreams://gateway.example.com to another gateway -

Endpoints

A subscriber, a dead-letter service or a feed is an endpoint: either an address, or an object with an address and how to authenticate to it, after the endpoints of the Serverless Workflow specification.

spec:
  subscriber:
    endpoint: https://orders.example.com/events          # an address
---
spec:
  subscriber:
    endpoint:
      uri: kafka://kafka:9092/orders
      authentication:
        basic:
          use: orders-kafka                              # the secret that holds the user name and the password

Sinks and feeds

An endpoint can also be kept in a resource of its own, which administrators manage. Subscriptions, dead-letter policies and gateways then refer to it by name, so that whoever edits them can deliver to the endpoint, or consume it, but can neither read its credentials nor send them elsewhere. A Sink is delivered to, and a Feed consumed by gateways:

apiVersion: cloud-streams.io/v1
kind: Sink
metadata:
  name: orders-kafka
spec:
  endpoint:
    uri: kafka://kafka:9092/orders
    authentication:
      oauth2:
        authority: https://login.example.com/realms/cloud-streams
        use: orders-kafka-client                         # client.id and client.secret
---
kind: Subscription
spec:
  subscriber:
    sink: orders-kafka                                   # instead of an endpoint
  deadLetter:
    sink: orders-dead-letters
---
kind: Gateway
spec:
  ingestion:
    feeds:
      - legacy-orders                                    # a Feed resource
      - name: payments                                   # a feed of the gateway's own
        endpoint: nats://nats:4222/payments.>?jetstream=true

Deleting a sink or a feed in use is allowed. What refers to it then fails to deliver or to consume, visibly: deliveries are retried, dead-lettered or fault the subscription, as with an unreachable endpoint, and the gateway logs that it cannot resolve the feed. A subscription may refer to a sink that does not exist yet, so that resources can be applied in any order.

Authentication follows the authentication policies of the Serverless Workflow specification, plus API keys. A policy holds its values, or names the secret that holds them with use:

Policy Values Transports
basic username, password HTTP (Basic authorization), Kafka (SASL PLAIN, or the mechanism of the address), NATS, AMQP, PostgreSQL, SQS and SNS (an access key id and its secret access key)
bearer token HTTP, Cloud Streams, Kafka (SASL OAUTHBEARER), NATS (token), AMQP (as the password, with RabbitMQ’s OAuth2 plugin)
apiKey key, header (X-Api-Key by default) HTTP, Cloud Streams, Pub/Sub (the JSON key of a service account), Service Bus (a connection string)
oauth2 authority, grant (client_credentials or password), client.id, client.secret, client.authentication, scopes, audiences, username, password, endpoints.token (/oauth2/token by default) HTTP, Cloud Streams, Kafka, AMQP, Service Bus (Entra ID, with the scope https://servicebus.azure.net/.default)
oidc as oauth2, whose token endpoint is discovered from the authority’s .well-known/openid-configuration HTTP, Cloud Streams, Kafka, AMQP, Service Bus

OAuth2 and OpenID Connect tokens are obtained by the broker or the gateway, cached, and renewed before they expire.

Secrets

A secret is a set of values, whose keys are the names of a policy’s properties, e.g. username and password, or client.id and client.secret. The values a secret holds take precedence over those of the policy, which may hold the others, such as an OAuth2 authority. Values written in the policy itself are allowed, but not recommended: anyone allowed to read the resource can see them.

use: orders-kafka                                  # the first configured provider that has it
use: { vault: cloud-streams/orders-kafka }         # an explicit provider, and its path

Secrets are read by the broker (to deliver) or the gateway (to consume), from the providers it is configured with, in order, and cached for a minute, so that rotated secrets are picked up:

Provider Reads What it can read
env environment variables CLOUDSTREAMS_SECRETS__{NAME}__{KEY}, e.g. CLOUDSTREAMS_SECRETS__ORDERS_KAFKA__PASSWORD variables with that prefix
file files {directory}/{name}/{key}, as Kubernetes mounts secrets; /var/run/secrets/cloud-streams by default files under the directory
kubernetes Kubernetes secrets, through the API, with the pod’s service account secrets of its namespace labelled cloud-streams.io/secret=true
vault the KV secrets engine of HashiCorp Vault, version 1 or 2, authenticated with a token, Kubernetes or an AppRole what its Vault policy allows

Names and keys are matched regardless of case, dashes, dots and underscores, which environment variables and file names cannot all contain. By default, only env and file are enabled:

CloudStreams:
  Secrets:
    Providers: [ env, file, kubernetes, vault ]    # the order in which a secret named without a provider is looked for
    CacheDuration: 00:01:00
    File:
      Directory: /var/run/secrets/cloud-streams
    Kubernetes:
      Namespace: cloud-streams                     # the pod's by default
      LabelSelector: cloud-streams.io/secret=true  # empty to read any secret the service account may
    Vault:
      Address: https://vault:8200
      Mount: secret
      KvVersion: 2
      Prefix: cloud-streams                        # prepended to the paths of secrets
      Authentication:
        Method: kubernetes                         # token (VAULT_TOKEN by default), kubernetes or approle
        Role: cloud-streams

Whoever can edit a subscription can make the broker send the secrets it can read to an endpoint of their choice. Only grant Cloud Streams the secrets its subscriptions need, or keep endpoints with credentials in sinks, which only administrators manage.

Parameters, in the query string of an address:

  • Kafka:
    • servers lists more bootstrap servers, comma-separated.
    • tls=true enables TLS. With basic authentication, the SASL mechanism is plain (default), scram-sha-256 or scram-sha-512.
    • For consumption: group sets the consumer group (the gateway’s name by default), and offset=latest skips the events published before the group’s first consumption.
  • NATS:
    • jetstream=true waits for JetStream to store each delivered event. Consumption then goes through a durable consumer of the stream that captures the subject, which must exist.
    • tls=true enables TLS, and queue sets the queue group, the gateway’s name by default.
  • AMQP:
    • The path is the virtual host.
    • exchange names the exchange to deliver to, which may be empty for the default exchange. routingKey sets the routing key, the event’s type by default.
    • queue names the queue to consume.
  • Cloud Streams: the path is that of the other gateway, if it is served under one, and tls=false connects over HTTP.
  • PostgreSQL (feeds only, see PostgreSQL feeds): the path is the database, and sslmode is that of PostgreSQL (disable, allow, prefer, require, verify-ca or verify-full).
    • outbox names the outbox table to consume, as [schema.]table. keep names the column to set, rather than deleting rows, notify the channel to listen to, and batch how many rows to read at once, 100 by default.
    • publication names the publication whose changes to capture. slot names the replication slot, cloudstreams_{gateway}_{namespace}_{feed} by default, and typeprefix prefixes the type of the events.

Addresses never carry credentials: one such as amqp://user:password@rabbitmq is refused.

Delivery:

  • Encoding: events are sent in the structured content mode of each transport’s CloudEvents binding, as application/cloudevents+json, with the cloudstreams-subscription and cloudstreams-offset headers. Kafka messages are keyed by the event’s partitionkey, or else its subject, so that events with the same key stay in order.
  • Confirmation: a delivery succeeds once the transport has confirmed it.
    • Kafka producers wait for every in-sync replica, and are idempotent.
    • AMQP uses publisher confirms, and publishes persistent, mandatory messages, so that an event no queue receives fails rather than vanishing.
    • NATS with JetStream waits for JetStream’s acknowledgement. Core NATS confirms nothing, and loses events no one listens to.
  • Failures: a transport that cannot be reached, or that refuses an event, fails the delivery like an unreachable HTTP subscriber. So does a sink that does not exist, a secret that cannot be read, or a token that cannot be obtained, since an operator may fix them. Retry policies, circuit breakers and dead letters therefore apply unchanged.
  • Batches: batches are sent as one message per event, except to another gateway, which receives them as application/cloudevents-batch+json.
  • Not supported: deferred acknowledgements (202 Accepted) are HTTP only.

Bridging gateways: cloudstreams:// delivers to another gateway’s POST /api/events/pub, authenticated with an API key, a bearer token, or a token obtained with OAuth2 or OpenID Connect.

  • Loops: the other gateway’s split-horizon policy recognizes events that come back, so two instances can forward events to each other.
  • Refused events in a batch: if the other gateway refuses one event of a batch, the whole batch is delivered again. Enable deduplication on the other gateway, so that the events it already stored are not stored twice.

Consumption: a gateway reconciles the feeds it consumes with its resource, and with the Feed resources it refers to, every few seconds. Credentials are read anew whenever the consumption of a feed starts.

  • Admission: consumed events go through admission like published ones. The feed’s name is their publisher, as feed:{name}, which publisher rate limits apply to.
  • Decoding: messages may carry an event in either content mode, or a batch. Attribute headers use each binding’s prefix: ce_ with Kafka, cloudEvents: or cloudEvents_ with AMQP, ce- with NATS.
  • Acknowledgement: a message is acknowledged once its events have been stored, ignored or refused. A refused event is logged.
  • Retries: a message whose event could not be stored for now is consumed again, with a growing delay, so that no event is lost. That happens when the event is rate limited, or when the event store is unavailable. Kafka retries the message in place, which keeps its partition in order. JetStream and AMQP redeliver it.
  • Shared consumption: replicas of a gateway share a feed, as a Kafka consumer group, a NATS queue group or a durable JetStream consumer, or competing AMQP consumers.
  • Failed consumption: a feed whose consumption fails, e.g. because its server is unreachable, is consumed again after a delay that grows up to a minute.

PostgreSQL feeds

Gateways turn what happens in a PostgreSQL database into cloud events, without Debezium nor a message broker, in either of two ways.

Transactional outbox

An application writes the cloud events it publishes to an outbox table, in the transaction of the changes they describe, so that both are committed, or neither. The gateway consumes the table:

CREATE TABLE cloudevents_outbox (id bigserial PRIMARY KEY, event jsonb NOT NULL);
-- optional: wakes the gateway as soon as rows are added, rather than at its next poll
CREATE FUNCTION cloudevents_outbox_notify() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN PERFORM pg_notify('cloudevents_outbox', ''); RETURN NULL; END $$;
CREATE TRIGGER cloudevents_outbox_notify AFTER INSERT ON cloudevents_outbox FOR EACH STATEMENT EXECUTE FUNCTION cloudevents_outbox_notify();
kind: Feed
metadata:
  name: orders-outbox
spec:
  endpoint:
    uri: postgres://db.example.com/orders?outbox=cloudevents_outbox&notify=cloudevents_outbox
    authentication: { basic: { use: orders-db } }
  • Rows: event holds a cloud event in the structured content mode, as jsonb, json or text, and id orders the rows. Other columns are ignored.
  • Order: rows are consumed in the order of their id. Only one replica of the gateway consumes the outbox at a time, the one that holds its advisory lock: the others stand by, and one of them takes over within seconds when it stops.
  • Once stored: a row is deleted once its cloud event has been stored, refused or ignored, or marked with keep={column}, which sets the column to the current time. A cloud event that cannot be stored for now is consumed again, from the same row, so that nothing is skipped.
  • Latency: the outbox is polled every second, or every 5 seconds when notify names the channel a trigger notifies, which wakes the gateway as soon as rows are committed.
  • Duplicates: a gateway that stops after storing a cloud event, and before deleting its row, consumes it again. Enable deduplication to store it only once.

Change data capture

The gateway captures the changes of the tables of a publication through logical replication, with PostgreSQL’s built-in pgoutput plugin, and turns each insert, update or delete into a cloud event:

-- requires wal_level = logical
CREATE PUBLICATION orders FOR TABLE orders, order_lines;
ALTER TABLE orders REPLICA IDENTITY FULL;   -- optional: deletes and updates then carry the whole previous row, rather than its key
uri: postgres://db.example.com/orders?publication=orders&slot=cloudstreams_orders&typeprefix=com.example.
{
  "specversion": "1.0",
  "id": "0/1A2B3C4D/0",
  "source": "postgres://db.example.com/orders",
  "type": "com.example.public.orders.update",
  "subject": "42",
  "time": "2026-11-30T10:00:00.0000000+00:00",
  "pglsn": "0/1A2B3C4D", "pgxid": "1234", "pgtable": "public.orders", "pgoperation": "update",
  "data": { "operation": "update", "schema": "public", "table": "orders", "key": { "id": 42 }, "before": { "id": 42, "status": "placed" }, "after": { "id": 42, "status": "paid" } }
}
  • Events: the type is {typeprefix}{schema}.{table}.{insert|update|delete}, the subject the row’s primary key, comma-separated if it has several columns, and the time that of the transaction’s commit. Booleans, numbers and JSON columns keep their type in data; other columns are strings. Unchanged TOAST values, which logical replication does not send, are left out. Truncations are logged and ignored.
  • Replication slot: the slot is created if it does not exist, and the publication must. The slot only moves past a transaction once the cloud events of all its changes have been stored: a gateway that stops resumes where it left off, and the ids of the events, derived from the transaction’s position, let deduplication drop those captured again.
  • One consumer: a slot only accepts one connection, so one replica of the gateway captures the changes, and another takes over when it stops.
  • Monitoring: the cloud_streams_gateway_feed_replication_lag_bytes gauge reports how much WAL the slot retains.
  • ⚠️ Removing a feed: PostgreSQL retains the WAL a slot has not consumed, forever, which can fill the database’s disk. Drop the slot of a feed that is removed for good, with SELECT pg_drop_replication_slot('cloudstreams_orders'), and consider setting max_slot_wal_keep_size. Cloud Streams never drops slots itself, so that a feed that is merely stopped loses nothing.
  • Permissions: the user needs the REPLICATION attribute, or the rds_replication role on Amazon RDS, and the SELECT privilege on the published tables.

Cloud transports

Subscriptions deliver to, and gateways consume from, the managed messaging services of AWS, Google Cloud and Azure.

Identity

An endpoint without authentication uses the ambient identity of the process, as each cloud’s SDK resolves it. That’s what’s recommended on Kubernetes:

Cloud Ambient identity Secrets
AWS the default credentials of the AWS SDK: environment variables, EKS Pod Identity, IAM roles for service accounts (a web identity), or the instance’s profile basic: an access key id as username, and its secret access key as password
Google Cloud the application default credentials, e.g. GKE’s Workload Identity, or GOOGLE_APPLICATION_CREDENTIALS apiKey: the JSON key of a service account
Azure DefaultAzureCredential, e.g. AKS’ Workload Identity, a managed identity, or environment variables apiKey: a connection string, whose namespace must be the address’; or oauth2 / oidc, e.g. the client credentials of an Entra ID application, with the scope https://servicebus.azure.net/.default

The identity of a broker or a gateway is the one of its pods: on Kubernetes, annotate the service accounts the operator creates, <name>-broker and <name>-gateway, as your cloud requires, e.g. with eks.amazonaws.com/role-arn, or use a secret.

  • Shared identity: every subscription and feed of a namespace that sets no authentication uses the same identity. Grant it only what they all may use, or give an endpoint credentials of its own, e.g. in a sink.
  • Never sent elsewhere: the ambient identity is only sent to the cloud. An SQS or SNS address with an endpoint, e.g. LocalStack’s, requires basic credentials. A Service Bus address whose host isn’t a namespace of Azure, e.g. *.servicebus.windows.net, requires a connection string. Otherwise, whoever edits a subscription could send the identity, or a token issued for the cloud, to a host of their own. Such endpoints are refused when they’re admitted.

Amazon SQS and SNS

sqs://{region}/{account}/{queue} and sns://{region}/{account}/{topic}:

  • Messages: cloud events are sent as structured cloud events, in batches of up to 10, whose message attributes carry the headers of the delivery, e.g. cloudstreams-subscription.
  • FIFO: to a queue or a topic whose name ends with .fifo, the message group is the value of the context attribute group names, by default the cloud event’s partitionkey or subject. The deduplication id is the cloud event’s id, so that a redelivery within SQS’ deduplication interval of 5 minutes is dropped.
  • Consumption: from SQS only, with long polling (wait, 20 seconds by default) and the queue’s visibility timeout, or visibility. A message is deleted once its cloud event is stored. One that isn’t is made visible again after a backoff, and, from a FIFO queue, so are the messages received after it, so that their order is kept. Configure a redrive policy on the queue to set messages aside after a number of receives.
  • SNS fan-out: consume the SQS queues a topic notifies. Their messages are unwrapped, whether raw message delivery is on or off.
  • Endpoint: endpoint targets another endpoint than AWS’, e.g. LocalStack’s: sqs://us-east-1/000000000000/orders?endpoint=http://localstack:4566.

Google Cloud Pub/Sub

pubsub://{project}/topics/{topic} to publish, and pubsub://{project}/subscriptions/{subscription} to consume:

  • Messages: cloud events are published as structured cloud events, whose attributes carry the headers of the delivery. A delivery succeeds once Pub/Sub confirmed the publication.
  • Ordering: with ordering=true, the ordering key of a message is the cloud event’s partitionkey or subject, so that a subscription with message ordering enabled receives the cloud events of a key in order.
  • Consumption: a message is acknowledged once its cloud event is stored, and negatively acknowledged otherwise, after a backoff, so that Pub/Sub redelivers it, following the subscription’s retry policy and dead-letter topic.
  • Emulator: emulator=localhost:8085 targets a Pub/Sub emulator.

Azure Service Bus

servicebus://{namespace}.servicebus.windows.net/{queue or topic}, and ?subscription={subscription} to consume a topic:

  • Messages: cloud events are sent as structured cloud events, in batches as large as the entity allows, whose application properties carry the headers of the delivery. The message id is the cloud event’s id, so that an entity with duplicate detection drops redeliveries.
  • Sessions: with sessions=true, the session of a message is the cloud event’s partitionkey or subject, which a session-enabled entity requires, and a session-enabled entity is consumed session by session, in order.
  • Consumption: with peek-lock. A message is completed once its cloud event is stored, and abandoned otherwise, after a backoff, until its maximum delivery count dead-letters it.
  • Emulator: the connection string of the Service Bus emulator, whose namespace is localhost, works as any other.

Azure Event Hubs

Event Hubs are Kafka topics, through the Kafka endpoint of their namespace, which every tier but Basic has:

endpoint:
  uri: kafka://orders.servicebus.windows.net:9093/orders?tls=true    # the event hub 'orders'
  authentication:
    basic:
      use: orders-event-hubs      # username: $ConnectionString, password: the namespace's connection string