8
8
9
9
"github.com/redis/go-redis/v9"
10
10
"goa.design/ponos/streaming"
11
+ "goa.design/ponos/streaming/options"
11
12
)
12
13
13
14
// NOTE: the example below does not handle errors for brevity.
@@ -20,7 +21,7 @@ func main() {
20
21
}
21
22
22
23
// Create stream
23
- stream , err := streaming .NewStream (ctx , "pubsub-stream" , rdb )
24
+ stream , err := streaming .NewStream ("pubsub-stream" , rdb )
24
25
if err != nil {
25
26
panic (err )
26
27
}
@@ -32,14 +33,14 @@ func main() {
32
33
id1 , err := stream .Add (ctx ,
33
34
"event 1" ,
34
35
[]byte ("payload 1" ),
35
- streaming .WithTopic ("my-topic" ))
36
+ options .WithTopic ("my-topic" ))
36
37
if err != nil {
37
38
panic (err )
38
39
}
39
40
fmt .Printf ("event 1 id: %s\n " , id1 )
40
41
41
42
// 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" ))
43
44
if err != nil {
44
45
panic (err )
45
46
}
@@ -48,8 +49,8 @@ func main() {
48
49
// Create sink that reads from the beginning and waits for events for up
49
50
// to 100ms
50
51
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 ))
53
54
if err != nil {
54
55
panic (err )
55
56
}
@@ -74,9 +75,9 @@ func main() {
74
75
// Create reader that reads from the beginning, waits for events for up
75
76
// to 100ms and only reads events whose topic match the pattern "my-*"
76
77
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-*" ))
80
81
if err != nil {
81
82
panic (err )
82
83
}
@@ -87,24 +88,4 @@ func main() {
87
88
// Read event from topic "my-topic"
88
89
event = <- reader .Subscribe ()
89
90
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 )
110
91
}
0 commit comments