Back
EventBus
A decoupled event system. Useful for communication between apps without direct imports.
Publishing an event
// In any view or service:
fw.Events.Publish("usuario.criado", map[string]any{
"id": usuario.ID,
"email": usuario.Email,
})
Subscribing to an event
// In the app's init() or in Register():
func init() {
// fw must be accessible here (via a package variable or injection)
fw.Events.Subscribe("usuario.criado", func(payload any) {
dados := payload.(map[string]any)
email := dados["email"].(string)
enviarEmailBoasVindas(email)
})
}
Unsubscribing
fw.Events.Unsubscribe("usuario.criado")
EventBus handlers run in separate goroutines. Use synchronization if needed.
EventBus vs Queue
EventBus is fire-and-forget pub/sub: every subscriber receives it, no retry, no processing guarantee. For work that can't be lost during a spike (emails, webhooks, media processing), with automatic retry and one worker per task, see Queue.