EventsIO is a simple and flexible library designed to handle events within G3deon. Its main goal is to centralize event logic in the application, providing a unified interface for different messaging implementations.
- Simple Interface: Intuitive API for publishing and subscribing to events
- Multiple Implementations: Support for different messaging backends
- RabbitMQ (implemented)
- Kafka (coming soon)
- Memory (for testing)
- Flexibility: Allows advanced options when needed
- Thread-Safe: Concurrency-safe implementation
- JSON Serialization: Automatic event serialization/deserialization
go get github.com/g3deon/aventsioTo ensure code quality, the project includes a pre-commit hook that runs:
- Go code formatting (
go fmt) - Linting with
golangci-lint - Unit tests (
go test)
To set up the hook:
# Configure hooks directory
git config core.hooksPath githooks
# Give execution permissions to the script
git add githooks/pre-commit.sh
git update-index --chmod=+x githooks/pre-commit.shNow, every time you try to commit, these checks will run automatically.
import (
"github.com/g3deon/aventsio"
"github.com/g3deon/aventsio/adapters/memory"
)
// Create in-memory event bus
bus := memory.NewEventBus()
// Publish event
event := eventsio.NewEvent("event-id")
bus.Publish("users", event)
// Subscribe to events
bus.Subscribe("users", func(event eventsio.Event) {
fmt.Printf("Received event: %s\n", event.GetID())
})// Publish with automatic retry
bus.Publish("users", event, eventsio.WithRetry())// Retry count its increment every time the event its re-delivered
bus.Subscribe("users", func(event eventsio.Event) {
fmt.Printf(
"Received event: %s\n, with re-try: %d",
event.GetID(),
event.GetRetryCount(),
)
})More comming soon...
Each event contains:
- Unique ID
- Send timestamp
- Customizable headers
- Event-specific data
Contributions are welcome. Please ensure to:
- Follow existing code conventions
- Add tests for new functionality
- Update documentation as needed
MIT