88
99 "github.com/redis/go-redis/v9"
1010 "goa.design/ponos/streaming"
11+ "goa.design/ponos/streaming/options"
1112)
1213
1314// NOTE: the example below does not handle errors for brevity.
@@ -20,7 +21,7 @@ func main() {
2021 }
2122
2223 // Create stream
23- stream , err := streaming .NewStream (ctx , "pubsub-stream" , rdb )
24+ stream , err := streaming .NewStream ("pubsub-stream" , rdb )
2425 if err != nil {
2526 panic (err )
2627 }
@@ -32,14 +33,14 @@ func main() {
3233 id1 , err := stream .Add (ctx ,
3334 "event 1" ,
3435 []byte ("payload 1" ),
35- streaming .WithTopic ("my-topic" ))
36+ options .WithTopic ("my-topic" ))
3637 if err != nil {
3738 panic (err )
3839 }
3940 fmt .Printf ("event 1 id: %s\n " , id1 )
4041
4142 // Add a new event to topic "other-topic"
42- id2 , err := stream .Add (ctx , "event 2" , []byte ("payload 2" ), streaming .WithTopic ("other-topic" ))
43+ id2 , err := stream .Add (ctx , "event 2" , []byte ("payload 2" ), options .WithTopic ("other-topic" ))
4344 if err != nil {
4445 panic (err )
4546 }
@@ -48,8 +49,8 @@ func main() {
4849 // Create sink that reads from the beginning and waits for events for up
4950 // to 100ms
5051 sink , err := stream .NewSink (ctx , "pubsub-sink" ,
51- streaming .WithSinkStartAtOldest (),
52- streaming .WithSinkBlockDuration (100 * time .Millisecond ))
52+ options .WithSinkStartAtOldest (),
53+ options .WithSinkBlockDuration (100 * time .Millisecond ))
5354 if err != nil {
5455 panic (err )
5556 }
@@ -74,9 +75,9 @@ func main() {
7475 // Create reader that reads from the beginning, waits for events for up
7576 // to 100ms and only reads events whose topic match the pattern "my-*"
7677 reader , err := stream .NewReader (ctx ,
77- streaming .WithReaderStartAtOldest (),
78- streaming .WithReaderBlockDuration (100 * time .Millisecond ),
79- streaming .WithReaderTopicPattern ("my-*" ))
78+ options .WithReaderStartAtOldest (),
79+ options .WithReaderBlockDuration (100 * time .Millisecond ),
80+ options .WithReaderTopicPattern ("my-*" ))
8081 if err != nil {
8182 panic (err )
8283 }
@@ -87,24 +88,4 @@ func main() {
8788 // Read event from topic "my-topic"
8889 event = <- reader .Subscribe ()
8990 fmt .Printf ("reader topic pattern: my-*, topic: %s, event: %s, payload: %s\n " , event .Topic , event .EventName , event .Payload )
90-
91- // Create reader for stream "my-stream" that reads from the beginning,
92- // waits for events for up to 100ms and only reads events whose topic
93- // match the given custom filter.
94- reader2 , err := stream .NewReader (ctx ,
95- streaming .WithReaderStartAtOldest (),
96- streaming .WithReaderBlockDuration (100 * time .Millisecond ),
97- streaming .WithReaderEventMatcher (func (event * streaming.Event ) bool {
98- return event .Topic == "my-topic"
99- }))
100- if err != nil {
101- panic (err )
102- }
103-
104- // Don't forget to close the reader when done
105- defer reader2 .Close ()
106-
107- // Read event from topic "my-topic"
108- event = <- reader2 .Subscribe ()
109- fmt .Printf ("reader topic filter: my-topic, topic: %s, event: %s, payload: %s\n " , event .Topic , event .EventName , event .Payload )
11091}
0 commit comments