diff --git a/README.MD b/README.MD index 29facd7..82b2636 100644 --- a/README.MD +++ b/README.MD @@ -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