Skills
Chapter 24 of 28
Asynchronous messaging in Encore.ts via Topic and Subscription from encore.dev/pubsub — broadcast events, decouple producers from consumers, and run background handlers.
1 minute · 138 words · 9 sections
Pub/Sub is for asynchronous messaging between services. Producers publish events to a Topic; consumers attach Subscriptions to react. Resources must be declared at package level — never inside functions.
import { Topic } from "encore.dev/pubsub";
interface OrderCreatedEvent {
orderId: string;
userId: string;
total: number;
}
// Package level declaration
export const orderCreated = new Topic<OrderCreatedEvent>("order-created", {
deliveryGuarantee: "at-least-once",
});await orderCreated.publish({
orderId: "123",
userId: "user-456",
total: 99.99,
});import { Subscription } from "encore.dev/pubsub";
const _ = new Subscription(orderCreated, "send-confirmation-email", {
handler: async (event) => {
await sendEmail(event.userId, event.orderId);
},
});Use Attribute<T> for fields that should be treated as message attributes (for filtering/ordering):
import { Topic, Attribute } from "encore.dev/pubsub";
interface CartEvent {
cartId: Attribute<string>; // Used for ordering
userId: string;
action: "add" | "remove";
productId: string;
}
// Ordered topic: events with same cartId delivered in order
export const cartEvents = new Topic<CartEvent>("cart-events", {
deliveryGuarantee: "at-least-once",
orderingAttribute: "cartId",
});Pass topic access to other code while maintaining static analysis:
import { Publisher } from "encore.dev/pubsub";
const publisherRef = orderCreated.ref<Publisher>();
async function notifyOrder(ref: typeof publisherRef, orderId: string) {
await ref.publish({ orderId, userId: "123", total: 99.99 });
}at-least-once (default): may deliver duplicates → handlers must be idempotent.exactly-once: stricter, capped throughput (AWS 300 msg/s/topic, GCP 3000+ msg/s/region). Does not deduplicate on the publish side.Attribute<T> for fields meant for filtering/ordering, not for arbitrary metadata.publish callers — publish returns once the message is queued.Install this repository
npx skills add encoredev/skills/plugin marketplace add encoredev/skillsSkills install per repository, not per chapter — the CLI has no documented per-skill form, so we do not print one.
Asynchronous messaging in Encore.ts via `Topic` and `Subscription` from `encore.dev/pubsub` — broadcast events, decouple producers from consumers, and run background handlers.
The verbatim description from this skill’s front matter — the string an agent matches on to decide whether to load it.
main, last pushed 15 May 2026.SKILL.md, not by matching a directory convention. One layout observed: encore/*/SKILL.md.h1 and no skipped levels:.claude-plugin/marketplace.json by Encore, declaring 1 plugin. It is read for editorial metadata only — never as the skill index, which is always the repository tree./encoredev/skills.md, and each chapter at its own .md URL.