Skip to content

Commit 9f588c6

Browse files
author
laminar
committed
update
Signed-off-by: laminar <fangtian@kubesphere.io>
1 parent d07b3e5 commit 9f588c6

File tree

22 files changed

+1212
-345
lines changed

22 files changed

+1212
-345
lines changed

examples/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Examples
2+
3+
## OpenFunction Context Function
4+
5+
- Dapr bindings
6+
- [gRPC example](dapr-demos/README.md#bindings-via-grpc)
7+
- [HTTP example](dapr-demos/README.md#bindings-via-http)
8+
9+
- Dapr pubsub
10+
- [gRPC example](dapr-demos/README.md#pubsub-via-grpc)
11+
12+
- Dapr service invocation
13+
- [gRPC example](dapr-demos/README.md#service-invocation-via-grpc)
14+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
dapr "github.com/dapr/go-sdk/client"
7+
)
8+
9+
func main() {
10+
// just for this demo
11+
ctx := context.Background()
12+
json := `{ "message": "hello" }`
13+
data := []byte(json)
14+
pubsub := "msg"
15+
topic := "my_topic"
16+
17+
// create the client
18+
client, err := dapr.NewClient()
19+
if err != nil {
20+
panic(err)
21+
}
22+
defer client.Close()
23+
24+
// publish a message to the topic demo
25+
if err := client.PublishEvent(ctx, pubsub, topic, data); err != nil {
26+
panic(err)
27+
}
28+
fmt.Println("data published")
29+
30+
fmt.Println("DONE (CTRL+C to Exit)")
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
dapr "github.com/dapr/go-sdk/client"
7+
)
8+
9+
func main() {
10+
// just for this demo
11+
ctx := context.Background()
12+
13+
// create the client
14+
client, err := dapr.NewClient()
15+
if err != nil {
16+
panic(err)
17+
}
18+
defer client.Close()
19+
20+
// invoke a method called EchoMethod on another dapr enabled service
21+
content := &dapr.DataContent{
22+
ContentType: "text/plain",
23+
Data: []byte("hellow"),
24+
}
25+
resp, err := client.InvokeMethodWithContent(ctx, "serving_function", "echo", "post", content)
26+
if err != nil {
27+
panic(err)
28+
}
29+
fmt.Printf("service method invoked, response: %s\n", string(resp))
30+
31+
fmt.Println("DONE (CTRL+C to Exit)")
32+
}

examples/config/cron.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: cron_input
5+
spec:
6+
type: bindings.cron
7+
version: v1
8+
metadata:
9+
- name: schedule
10+
value: "@every 10s"

examples/config/pubsub.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: msg
5+
spec:
6+
type: pubsub.redis
7+
version: v1
8+
metadata:
9+
- name: redisHost
10+
value: localhost:6379
11+
- name: redisPassword
12+
value: ""

examples/config/statestore.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: statestore
5+
spec:
6+
type: state.redis
7+
version: v1
8+
metadata:
9+
- name: redisHost
10+
value: localhost:6379
11+
- name: redisPassword
12+
value: ""
13+
- name: actorStateStore
14+
value: "true"

0 commit comments

Comments
 (0)