Something went wrong. Try again.
wip outbox library design
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041package outpost
import ( "context" "fmt")
func Example() { ctx := context.Background() st := &memStore{}
// Request path: the message is appended in the same unit of work as the // business write. Here the store itself provides the appender. for _, to := range []string{"ada@example.com", "grace@example.com"} { err := Emit(ctx, st.appender(), "email.send", sendEmail{To: to, Subject: "welcome"}, Key(to)) if err != nil { panic(err) } }
// Worker path: the same handler runs whatever the producer is. d := NewDispatcher() Handle(d, "email.send", func(_ context.Context, e sendEmail) error { fmt.Println("send to", e.To) return nil })
relay, err := NewRelay(st, ProducerFunc(d.Dispatch), WithWorkers(1)) if err != nil { panic(err) } if _, err := relay.RunOnce(ctx); err != nil { panic(err) }
// Output: // send to ada@example.com // send to grace@example.com}