Skip to content

Commit

Permalink
Update README.MD
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Mosciszko <[email protected]>
  • Loading branch information
Raezil authored Feb 20, 2025
1 parent 5b51458 commit 15f88ef
Showing 1 changed file with 1 addition and 57 deletions.
58 changes: 1 addition & 57 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -91,65 +91,9 @@ func main() {
log.Fatalf("Failed to start server: %v", err)
}
}
```

# Example 2.
```
package main
import (
"fmt"
"log"
gbus "github.com/Raezil/GoEventBus"
_ "github.com/lib/pq"
)
// HouseWasSold represents an event for when a house has been sold
type HouseWasSold struct{}
// NewDispatcher initializes the dispatcher with event handlers
func NewDispatcher() *gbus.Dispatcher {
return &gbus.Dispatcher{
HouseWasSold{}: func(m map[string]interface{}) (gbus.Result, error) {
price, ok := m["price"].(int)
if !ok {
return gbus.Result{}, fmt.Errorf("price not provided or invalid")
}
result := fmt.Sprintf("House was sold for %d", price)
log.Println(result)
return gbus.Result{
Message: result,
}, nil
},
}
}
func main() {
// Initialize dispatcher and event store
dispatcher := NewDispatcher()
eventstore := gbus.NewEventStore(dispatcher)
eventstore.Publish(gbus.NewEvent(
HouseWasSold{},
map[string]interface{}{
"price": 100,
},
))
eventstore.Publish(gbus.NewEvent(
HouseWasSold{},
map[string]interface{}{
"price": 100,
},
))
// Broadcast the event
eventstore.Broadcast()
}
```
# Example 3
# Example 2
run RabbitMQ
```
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4.0-management
Expand Down

0 comments on commit 15f88ef

Please sign in to comment.