Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ozgen/eventbus
EventBus is a lightweight, efficient, and easy-to-use publish/subscribe event bus system implemented in Go
https://github.com/ozgen/eventbus
event-driven eventbus events go golang publisher pubsub subscriber
Last synced: about 2 months ago
JSON representation
EventBus is a lightweight, efficient, and easy-to-use publish/subscribe event bus system implemented in Go
- Host: GitHub
- URL: https://github.com/ozgen/eventbus
- Owner: ozgen
- License: mit
- Created: 2024-08-04T20:09:16.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-04T21:47:56.000Z (5 months ago)
- Last Synced: 2024-08-30T10:39:49.504Z (4 months ago)
- Topics: event-driven, eventbus, events, go, golang, publisher, pubsub, subscriber
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EventBus
EventBus is a lightweight, efficient, and easy-to-use publish/subscribe event bus system implemented in Go. It allows components within an application to communicate with each other using events without knowing the details of who is handling these events.
## Installation
To use EventBus in your Go projects, simply install it using `go get`:
```bash
go get github.com/ozgen/[email protected]
```## Usage
Here’s a simple example of how to use the EventBus:
```go
package mainimport (
"github.com/ozgen/eventbus"
"fmt"
)func main() {
bus := eventbus.New()bus.Subscribe("myEvent", func(e eventbus.Event) {
fmt.Printf("Event Received: %v\n", e.Payload)
})bus.Publish(eventbus.Event{Type: "myEvent", Payload: "Hello, World!"})
// Wait for all event handlers to complete before exiting
bus.Wait()
}
```This will output:
```
Event Received: Hello, World!
```## API Documentation
- `New() *EventBus`: Initializes and returns a new instance of EventBus.
- `Subscribe(eventType string, listener Listener)`: Registers a listener that gets called when an event of the specified type is published.
- `Publish(event Event)`: Publishes an event to all registered listeners of the event's type.
- `Wait()`: Blocks until all handlers have completed processing. This is useful for graceful shutdowns and ensuring all events are processed before an application exits.## Contributing
Contributions are welcome! Please feel free to submit pull requests, create issues, or provide feedback.
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details.