From e712d3a07b8db531ed74a774934456658b58058a Mon Sep 17 00:00:00 2001 From: stanipetrosyan Date: Sun, 10 Nov 2024 15:34:08 +0100 Subject: [PATCH] docs: update readme --- README.md | 14 ++++++-------- message.go | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 90045f0..88e35ec 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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()) @@ -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) ``` diff --git a/message.go b/message.go index 19a25b1..067ebed 100644 --- a/message.go +++ b/message.go @@ -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 }