From d5be5422b414e808b97b599f6df828efd23be237 Mon Sep 17 00:00:00 2001 From: Yao Yao <870000@163.com> Date: Fri, 9 Apr 2021 05:14:51 +0800 Subject: [PATCH] fix readme.md (#153) * fix readme.md * fix readme.md * fix readme.md * fix readme.md * fix grpc readme.md * fix grpc readme.md Co-authored-by: Yaron Schneider --- service/grpc/Readme.md | 10 +++++++--- service/http/Readme.md | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/service/grpc/Readme.md b/service/grpc/Readme.md index 21f9072f..f6393a95 100644 --- a/service/grpc/Readme.md +++ b/service/grpc/Readme.md @@ -44,7 +44,11 @@ if err := s.Start(); err != nil { To handle events from specific topic you need to add at least one topic event handler before starting the service: ```go -if err := s.AddTopicEventHandler("messages", "topic1", eventHandler); err != nil { +sub := &common.Subscription{ + PubsubName: "messages", + Topic: "topic1", + } +if err := s.AddTopicEventHandler(sub, eventHandler); err != nil { log.Fatalf("error adding topic subscription: %v", err) } ``` @@ -52,10 +56,10 @@ if err := s.AddTopicEventHandler("messages", "topic1", eventHandler); err != nil The handler method itself can be any method with the expected signature: ```go -func eventHandler(ctx context.Context, e *daprd.TopicEvent) error { +func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) { log.Printf("event - PubsubName:%s, Topic:%s, ID:%s, Data: %v", e.PubsubName, e.Topic, e.ID, e.Data) // do something with the event - return nil + return true, nil } ``` diff --git a/service/http/Readme.md b/service/http/Readme.md index 435df3c4..6ef200c5 100644 --- a/service/http/Readme.md +++ b/service/http/Readme.md @@ -19,13 +19,13 @@ Or with address and an existing `http.ServeMux` in case you want to combine exis ```go mux := http.NewServeMux() mux.HandleFunc("/", myOtherHandler) -s := daprd.NewService(":8080", mux) +s := daprd.NewServiceWithMux(":8080", mux) ``` Once you create a service instance, you can "attach" to that service any number of event, binding, and service invocation logic handlers as shown below. Onces the logic is defined, you are ready to start the service: ```go -if err = s.Start(); err != nil && err != http.ErrServerClosed { +if err := s.Start(); err != nil && err != http.ErrServerClosed { log.Fatalf("error: %v", err) } ``` @@ -49,10 +49,10 @@ if err != nil { The handler method itself can be any method with the expected signature: ```go -func eventHandler(ctx context.Context, e *common.TopicEvent) error { +func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) { log.Printf("event - PubsubName:%s, Topic:%s, ID:%s, Data: %v", e.PubsubName, e.Topic, e.ID, e.Data) // do something with the event - return nil + return true, nil } ```