Events Bus
Subscribing to events
package foo
import (
"github.com/roadrunner-server/events"
)
func foo() {
// Get the (global) instance of the event bus. Make sure to
// unsubscribe the event handler when you don't need it anymore: eh.Unsubscribe(id).
eh, id := events.Bus()
defer eh.Unsubscribe(id)
// Create an events channel.
ch := make(chan events.Event, 100)
// Subscribe to the events that fit your pattern (e.g., `http.EventJobOK`).
err := eh.SubscribeP(id, "http.EventJobOK", ch)
if err != nil {
panic(err)
}
// Send an event to the channel.
eh.Send(events.NewEvent(events.EventJobOK, "http", "foo"))
// Receive an event from the channel.
evt := <-ch
// evt.Message() -> "foo"
// evt.Plugin() -> "http"
// evt.Type().String() -> "EventJobOK"
}Event Payload
Property
Description
Method
Description
Wildcards
How to implement a custom event
Step 1: Define a Custom Event Type
Step 2: Implement the fmt.Stringer Interface
fmt.Stringer InterfaceStep 3: Create an enumeration with actual events
Usage
Last updated