-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (33 loc) · 952 Bytes
/
main.go
File metadata and controls
42 lines (33 loc) · 952 Bytes
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
/*
Copyright 2021 The CloudEvents Authors
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"context"
"fmt"
"log"
cestan "github.com/cloudevents/sdk-go/protocol/stan/v2"
cloudevents "github.com/cloudevents/sdk-go/v2"
)
func main() {
receiver, err := cestan.NewConsumer("test-cluster", "test-client", "test-subject", cestan.StanOptions())
if err != nil {
log.Fatalf("failed to create protocol: %v", err)
}
defer receiver.Close(context.Background())
c, err := cloudevents.NewClient(receiver, cloudevents.WithTimeNow(), cloudevents.WithUUIDs())
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
log.Printf("will listen consuming topic test-topic\n")
err = c.StartReceiver(context.TODO(), receive)
if err != nil {
log.Fatalf("failed to start receiver: %s", err)
} else {
log.Printf("receiver stopped\n")
}
}
func receive(_ context.Context, event cloudevents.Event) {
fmt.Printf("%s", event)
}