Cloud.KafkaTopic
A topic on a managed Kafka cluster. Create topics here: the
brokers don’t create them automatically and clients can’t create them, so
topics a library would create on its own (Kafka Streams’ -changelog and
-repartition topics) must exist before the application starts.
cleanupPolicy, maxMessageBytes, partitions, retentionBytes and
retentionMs change in place; partitions can only grow (the API refuses
a decrease with a 422). All topics together must fit the cluster plan’s
partitions and storage budget. name, kafkaId and availabilityZone
replace the topic. A topic is gone with its cluster.
Ownership. The API keeps no metadata for it, so the generated name (it ends
in the resource instance’s random suffix) is what identifies an object this stack
created: a create interrupted before its state was saved is found by that name on
the next deploy. An explicitly named object can’t be told apart from someone
else’s (it is taken over only with --adopt), and list returns every object.
Zone. A child doesn’t take its zone from its parent: it uses its own
availabilityZone, else the credentials’ zone. When the parent lives in
another zone, pass the parent’s along (availabilityZone: parent.availabilityZone), or every call for it answers NotFound.
Creating a topic
Section titled “Creating a topic”A topic keeping a week of messages
const kafka = yield* BetterStack.Cloud.Kafka("events", { type: "KA1", brokerCount: 3 });const orders = yield* BetterStack.Cloud.KafkaTopic("orders", { kafkaId: kafka.id, name: "orders", partitions: 6, retentionMs: 7 * 24 * 60 * 60 * 1000,});A compacted topic
yield* BetterStack.Cloud.KafkaTopic("customers", { kafkaId: kafka.id, cleanupPolicy: "compact",});Looking up an existing topic
Section titled “Looking up an existing topic”Reference a topic by cluster and id
const existing = BetterStack.Cloud.KafkaTopic.lookup({ kafkaId: "42", id: "7" });kafkaId string required
The ID of the parent this kafka belongs to.
availabilityZone string
Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.
cleanupPolicy "delete" | "compact" | "compact_delete" | string
How Kafka removes old messages. - delete: Deletes messages older than the retention time or past the retention size. - compact: Keeps only the latest message for each key. - compact_delete: Keeps only the latest message for each key, and also deletes messages past retention. Kafka calls it compact,delete.
maxMessageBytes number
The largest message the topic accepts, in bytes, from 1024 to 8388608.
name string
The topic's name, unique in the cluster: 1-249 letters, digits, dots, hyphens and underscores, not . or .. and not starting with __. Defaults to a unique name generated from the stack, stage and logical id. Changing it replaces the topic (and drops its messages).
partitions number
The number of partitions, at least 1. All topics together must fit within the cluster type's max_partitions. On update, you can only increase it.
retentionBytes number
The most data to keep in each partition, in bytes, at least 1048576. All topics together, plus one segment for each partition, must fit in the cluster's storage budget.
retentionMs number
How long to keep messages, in milliseconds, at least 60000. -1 keeps them with no time limit, and retention_bytes still limits their size.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
id string always set
The topic's ID.
kafkaId string always set
The ID of the Kafka cluster the topic belongs to.
name string always set
The topic's name, which clients produce to and consume from.
budgetBytes number
The most disk space the topic can use on each broker, in bytes. The budget is partitions times retention_bytes, plus one segment for each partition.
cleanupPolicy "delete" | "compact" | "compact_delete"
How Kafka removes old messages. - delete: Deletes messages older than the retention time or past the retention size. - compact: Keeps only the latest message for each key. - compact_delete: Keeps only the latest message for each key, and also deletes messages past retention. Kafka calls it compact,delete.
createdAt string | null
When the topic was created.
maxMessageBytes number
The largest message the topic accepts, in bytes, from 1024 to 8388608.
partitions number
The number of partitions, at least 1. All topics together must fit within the cluster type's max_partitions. On update, you can only increase it.
replicationFactor number
The number of copies of each partition, the same as the cluster's number of brokers.
retentionBytes number
The most data to keep in each partition, in bytes, at least 1048576. All topics together, plus one segment for each partition, must fit in the cluster's storage budget.
retentionMs number
How long to keep messages, in milliseconds, at least 60000. -1 keeps them with no time limit, and retention_bytes still limits their size.
updatedAt string | null
When the topic was last updated.
Lookup
Section titled “Lookup”KafkaTopic.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
id string required
The topic's ID.
kafkaId string required
The ID of the Kafka cluster.
availabilityZone string
Zone the cluster lives in. Defaults to the credentials' zone.