Skip to content

Commit

Permalink
fix readme.md (#153)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Yao Yao and yaron2 authored Apr 8, 2021
1 parent 7f6e8c9 commit d5be542
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions service/grpc/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ 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)
}
```

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
}
```

Expand Down
8 changes: 4 additions & 4 deletions service/http/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```
Expand All @@ -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
}
```

Expand Down

0 comments on commit d5be542

Please sign in to comment.