Skip to content

Commit f4a3b65

Browse files
committed
examples correction
Signed-off-by: sadath-12 <[email protected]>
1 parent 0f2d9bb commit f4a3b65

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

examples/pubsub/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This folder contains two Go files that use the Go SDK to invoke the Dapr Pub/Sub
1818
name: Run Subscriber Server
1919
output_match_mode: substring
2020
expected_stdout_lines:
21+
- 'event - PubsubName: messages, Topic: newbulkorder'
2122
- 'event - PubsubName: messages, Topic: neworder'
2223
background: true
2324
sleep: 15
@@ -49,9 +50,6 @@ sleep: 15
4950
#### Note: pub/pub.go contains both PublishEvents (used for publish of messages) and PublishEvent (used for bulkPublish of messages)
5051

5152
```bash
52-
export DAPR_PUBSUB_NAME=messages
53-
54-
5553
dapr run --app-id pub \
5654
--log-level debug \
5755
--resources-path ./config \
@@ -80,6 +78,6 @@ dapr stop --app-id sub
8078

8179
```shell
8280
== APP == 2023/03/29 21:36:07 event - PubsubName: messages, Topic: neworder, ID: 82427280-1c18-4fab-b901-c7e68d295d31, Data: ping
83-
== APP == 2023/03/29 21:36:07 event - PubsubName: messages, Topic: neworder, ID: cc13829c-af77-4303-a4d7-55cdc0b0fa7d, Data: multi-pong
84-
== APP == 2023/03/29 21:36:07 event - PubsubName: messages, Topic: neworder, ID: 0147f10a-d6c3-4b16-ad5a-6776956757dd, Data: multi-ping
81+
== APP == 2023/03/29 21:36:07 event - PubsubName: messages, Topic: newbulkorder, ID: cc13829c-af77-4303-a4d7-55cdc0b0fa7d, Data: multi-pong
82+
== APP == 2023/03/29 21:36:07 event - PubsubName: messages, Topic: newbulkorder, ID: 0147f10a-d6c3-4b16-ad5a-6776956757dd, Data: multi-ping
8583
```

examples/pubsub/pub/pub.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ package main
1616
import (
1717
"context"
1818
"fmt"
19-
"os"
2019

2120
dapr "github.com/dapr/go-sdk/client"
2221
)
2322

2423
var (
2524
// set the environment as instructions.
26-
pubsubName = os.Getenv("DAPR_PUBSUB_NAME")
27-
topicName = "neworder"
28-
bulkTopicName = "newbulkorder"
25+
pubsubName = "messages"
26+
bulkpubsubName = "bulkmessages"
27+
topicName = "neworder"
28+
bulkTopicName = "newbulkorder"
2929
)
3030

3131
func main() {

examples/pubsub/sub/sub.go

+5-19
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,22 @@ var defaultSubscription = &common.Subscription{
3636
}
3737

3838
var bulkSubscription = &common.Subscription{
39-
PubsubName: "bulkmessages",
39+
PubsubName: "messages",
4040
Topic: "newbulkorder",
4141
Route: "/bulkorders",
4242
}
4343

44-
var importantSubscription = &common.Subscription{
45-
PubsubName: "messages",
46-
Topic: "neworder",
47-
Route: "/important",
48-
Match: `event.type == "important"`,
49-
Priority: 1,
50-
}
51-
5244
func main() {
5345
s := daprd.NewService(":8080")
5446

55-
// use this for bulk subscription
56-
// if err := s.AddBulkTopicEventHandler(defaultSubscription, eventHandler, 10, 100); err != nil {
57-
// log.Fatalf("error adding topic subscription: %v", err)
58-
// }
59-
6047
if err := s.AddTopicEventHandler(defaultSubscription, eventHandler); err != nil {
6148
log.Fatalf("error adding topic subscription: %v", err)
6249
}
6350

51+
if err := s.AddBulkTopicEventHandler(bulkSubscription, eventHandler, 10, 100); err != nil {
52+
log.Fatalf("error adding topic subscription: %v", err)
53+
}
54+
6455
if err := s.Start(); err != nil && err != http.ErrServerClosed {
6556
log.Fatalf("error listenning: %v", err)
6657
}
@@ -70,8 +61,3 @@ func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err er
7061
log.Printf("event - PubsubName: %s, Topic: %s, ID: %s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
7162
return false, nil
7263
}
73-
74-
func importantEventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
75-
log.Printf("important event - PubsubName: %s, Topic: %s, ID: %s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
76-
return false, nil
77-
}

0 commit comments

Comments
 (0)