Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
stanipetrosyan committed Nov 10, 2024
1 parent 3956448 commit e712d3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Simple example of publish/subscribe pattern.
eventbus = goeventbus.NewEventBus()

address := "topic"
options := goeventbus.NewMessageOptions().AddHeader("header", "value")
message := goeventbus.CreateMessage().SetBody("Hi Topic").SetOptions(options)
options := goeventbus.NewMessageHeadersBuilder().SetHeader("header", "value").Build()
message := goeventbus.NewMessageBuilder().SetPayload("Hi Topic").SetHeaders(options).Build()

eventbus.Channel(address).Subscriber().Listen(func(dc goeventbus.Context) {
fmt.Printf("Message %s\n", dc.Result().Data)
Expand All @@ -56,7 +56,7 @@ Simple example of request/response pattern.
eventbus = goeventbus.NewEventBus()

address := "topic"
message := goeventbus.CreateMessage().SetBody("Hi Topic")
message := goeventbus.NewMessageBuilder().SetPayload("Hi Topic").Build()

eventbus.Channel(address).Subscriber().Listen(func(context goeventbus.Context) {
fmt.Printf("Message %s\n", context.Result().Extract())
Expand All @@ -73,16 +73,14 @@ eventbus.Channel(address).Publisher().Request(message, func(context goeventbus.C
For publishing, you need to create a Message object using this method.

```go
message := goeventbus.CreateMessage().SetBody("Hi Topic")
message := goeventbus.NewMessageBuilder().SetPayload("Hi Topic").SetHeaders(options).Build()
```
Each message can have some options:

```go

options := goeventbus.NewMessageOptions().AddHeader("header", "value")
message := goeventbus.CreateMessage()

message.SetOptions(options)
options := goeventbus.NewMessageHeadersBuilder().SetHeader("header", "value").Build()
message := goeventbus.NewMessageBuilder().setHeaders(options).Build()

eventBus.Channel("address").Publisher().Publish(message)
```
Expand Down
1 change: 1 addition & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (m Message) Extract() any {
return m.Payload
}

// Returns headers of the message
func (m Message) ExtractHeaders() MessageHeaders {
return m.Headers
}

0 comments on commit e712d3a

Please sign in to comment.