-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsmart_stream.go
More file actions
50 lines (42 loc) · 1.29 KB
/
smart_stream.go
File metadata and controls
50 lines (42 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"github.com/avinassh/fluvio-go/fluvio"
)
func main() {
fluvioClient, err := fluvio.Connect()
if err != nil {
fmt.Println("error while connecting", err)
return
}
defer fluvioClient.Close()
topic := "hello-smartstreams"
// file generated from the official example: https://www.fluvio.io/docs/smartstreams/quick-start/#create-a-new-smartstream
// this filter lets any record of string which contains character `a`
wasmFile := "example/filter.wasm"
config, err := fluvioClient.ConsumerConfigWithWasmFilter(wasmFile)
if err != nil {
fmt.Println("error while getting consumer config", err)
return
}
defer config.Close()
// create a consumer, for the same topic, on partition 0
partitionConsumer, err := fluvioClient.PartitionConsumer(topic, 0)
if err != nil {
fmt.Println("error while getting partition consumer", err)
return
}
defer partitionConsumer.Close()
// create a stream object
stream, err := partitionConsumer.StreamWithConfig(fluvio.NewOffsetFromBeginning(0), config)
if err != nil {
fmt.Println("error while getting stream on partition consumer", err)
return
}
defer stream.Close()
// loop over streamer to fetch all the records
for i := 0; i <= 10; i++ {
r, _ := stream.Next()
fmt.Printf("Got record: value=%s\n", string(r.Value))
}
}