encore-go-pubsub — Claude Code skill: events and setup
Guides asynchronous messaging in Encore Go with topics and subscriptions. Use it for background handlers, event fan-out, and service-to-service messages.
npx skills add encoredev/skills --skill encore-go-pubsub -a claude-code
npx skills add encoredev/skills --skill go-pubsub -a claude-codeWhat encore-go-pubsub does
This skill shows how to define pubsub.NewTopic and pubsub.NewSubscription in Encore Go. A producer sends an event to a topic, while one or more consumers handle it through subscriptions. Both resources belong at package scope rather than inside functions.
It covers Publish, handlers that receive context.Context and return error, and restricted publishing through pubsub.TopicRef. Delivery can use pubsub.AtLeastOnce or pubsub.ExactlyOnce. With at-least-once delivery, duplicate messages are possible, so handlers must be idempotent. Publish returns after the message is queued; heavy synchronous work should stay out of the caller.
What it helps with
- publish events between Go services
- fan one event out to several handlers
- run background reactions to messages
- configure message delivery guarantees
- pass publish access into library code
Example prompts for the agent
- Create an Encore Go topic named
OrderCreatedwithpubsub.AtLeastOncedelivery and a subscription that sends a confirmation email. - Write a handler that accepts
context.Contextand*OrderCreatedEvent, returningerrorwhen processing fails. - Show how to pass publishing permission through
pubsub.TopicRefto a library function.
How to install encore-go-pubsub
1Skills CLI (Vercel)
npx skills add encoredev/skills --skill encore-go-pubsub -a claude-codenpx skills add encoredev/skills --skill go-pubsub -a claude-code2Manually: put the files in place
~/.claude/skills/go-pubsub/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/go-pubsub/
1Skills CLI (Vercel)
npx skills add encoredev/skills --skill go-pubsub -a codex2Manually: put the files in place
.agents/skills/go-pubsub/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add encoredev/skills --skill go-pubsub -a cursor2Manually: put the files in place
.cursor/skills/go-pubsub/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install encoredev/skills go-pubsub2Manually: put the files in place
.github/skills/go-pubsub/SKILL.md1Skills CLI (Vercel)
npx skills add encoredev/skills --skill go-pubsub -a gemini-cli2Platform CLI
gemini skills install https://github.com/encoredev/skills --path encore/go-pubsubManually: put the files in place
.devin/skills/go-pubsub/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add encoredev/skills --skill go-pubsub -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about encore-go-pubsub
How do I install encore-go-pubsub in Claude Code?
Run npx skills add encoredev/skills --skill encore-go-pubsub -a claude-code, then use ~/.claude/skills/go-pubsub/SKILL.md.
What does encore-go-pubsub do?
It guides asynchronous event handling in Encore Go. Topics publish messages, while subscriptions attach background handlers and let one event reach multiple consumers.
What should handlers do with pubsub.AtLeastOnce delivery?
They must tolerate duplicate messages by being idempotent. A handler receives context.Context and the event, and returning an error lets the topic retry according to its retry policy.
Source text
SKILL.md · Apache-2.0
---
name: encore-go-pubsub
description: Asynchronous messaging in Encore Go via `pubsub.NewTopic` and `pubsub.NewSubscription` from `encore.dev/pubsub` — broadcast events, decouple producers from consumers, and run background handlers.
when_to_use: >-
User wants to publish/broadcast events, fan out a single event to many handlers, fire-and-forget messages between Go services, react to something asynchronously, set up a worker that consumes events, configure delivery guarantees (at-least-once, exactly-once), or use ordering attributes. Trigger phrases: "publish an event", "broadcast", "subscribe to", "topic", "Pub/Sub", "pubsub", "event bus", "OrderCreated event", "send to anyone listening", "background event handler", "queue", "fan out".
---
# Encore Go Pub/Sub
## Instructions
Pub/Sub is for asynchronous messaging between services. Producers publish events to a `Topic`; consumers attach `Subscription`s to react. Resources must be declared as package-level variables — never inside functions.
## Topics
```go
package events
import "encore.dev/pubsub"
type OrderCreatedEvent struct {
OrderID string `json:"order_id"`
UserID string `json:"user_id"`
Total int `json:"total"`
}
// Package level declaration
var OrderCreated = pubsub.NewTopic[*OrderCreatedEvent]("order-created", pubsub.TopicConfig{
DeliveryGuarantee: pubsub.AtLeastOnce,
})
```
### Publishing
```go
msgID, err := events.OrderCreated.Publish(ctx, &events.OrderCreatedEvent{
OrderID: "123",
UserID: "user-456",
Total: 9999,
})
```
### Subscriptions
```go
package notifications
import (
"context"
"myapp/events"
"encore.dev/pubsub"
)
var _ = pubsub.NewSubscription(events.OrderCreated, "send-confirmation-email",
pubsub.SubscriptionConfig[*events.OrderCreatedEvent]{
Handler: sendConfirmationEmail,
},
)
func sendConfirmationEmail(ctx context.Context, event *events.OrderCreatedEvent) error {
// Send email...
return nil
}
```
### Topic References
Pass topic access to library code while maintaining static analysis:
```go
// Create a reference with publish permission
ref := pubsub.TopicRef[pubsub.Publisher[*OrderCreatedEvent]](OrderCreated)
// Use the reference in library code
func publishEvent(ref pubsub.Publisher[*OrderCreatedEvent], event *OrderCreatedEvent) error {
_, err := ref.Publish(ctx, event)
return err
}
```
## Delivery Guarantees
- `pubsub.AtLeastOnce` (default): may deliver duplicates → handlers must be idempotent.
- `pubsub.ExactlyOnce`: stricter, capped throughput (AWS 300 msg/s/topic, GCP 3000+ msg/s/region). Does not deduplicate on the publish side.
## Guidelines
- Topics and subscriptions must be declared as package-level variables.
- Subscription handlers must be idempotent (at-least-once delivery is the default).
- Subscription handlers receive a `context.Context` and the event pointer; return an `error` to retry per the topic's retry policy.
- Don't do heavy synchronous work in `Publish` callers — `Publish` returns once the message is queued.
© encoredev · Apache-2.0 · encoredev/skills