Skip to content

Instantly share code, notes, and snippets.

@StarpTech
Last active January 4, 2020 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StarpTech/3947d8ce649089cea3c2c7d56324a57c to your computer and use it in GitHub Desktop.
Save StarpTech/3947d8ce649089cea3c2c7d56324a57c to your computer and use it in GitHub Desktop.
Replay events
// Subscribe starting with most recently published value
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
}, stan.StartWithLastReceived())
// Receive all stored values in order
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
}, stan.DeliverAllAvailable())
// Receive messages starting at a specific sequence number
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
}, stan.StartAtSequence(22))
// Subscribe starting at a specific time
var startTime time.Time
...
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
}, stan.StartAtTime(startTime))
// Subscribe starting a specific amount of time in the past (e.g. 30 seconds ago)
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
}, stan.StartAtTimeDelta(time.ParseDuration("30s")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment