Skip to content

Gerfey/messenger

Repository files navigation

Messenger

CI Security codecov Go Report Card Go Reference License

⚠️ v0.7.0 is a pre-release version — feel free to test and report issues!

📚 Full documentation available in the GitHub Wiki

🇷🇺 Русская версия

✨ Features

  • Multiple Transports: AMQP (RabbitMQ), In-Memory (sync)
  • Middleware Chain: Extensible middleware system for message processing
  • Event-Driven: Built-in event dispatcher for lifecycle hooks
  • Retry Mechanism: Configurable retry strategies with exponential backoff
  • Message Routing: Flexible routing system for message distribution
  • Stamps System: Metadata attachment for message tracking
  • YAML Configuration: Easy configuration management with %env(...)% support

📦 Installation

Requires Go 1.24+

go get github.com/gerfey/messenger@v0.7.0

🚀 Quick Start

Define Your Message

package main

type HelloMessage struct {
    Text string
}

Create a Handler

package main

type HelloHandler struct{}

func (h *HelloHandler) Handle(ctx context.Context, msg *HelloMessage) error {
    fmt.Println("Hello:", msg.Text)
    return nil
}

Create config file messenger.yaml:

default_bus: default

buses:
  default: ~

💡 If no transport is configured for a message, it will be executed synchronously by default (inline handler execution).

Initialize messenger:

cfg, errConfig := config.LoadConfig("messenger.yaml")
if errConfig != nil {
    fmt.Println("ERROR load config", "error", errConfig)
    return
}

b := builder.NewBuilder(cfg, slog.Default())
b.RegisterHandler(&HelloHandler{})
m, _ := b.Build()

ctx := context.Background()
go m.Run(ctx)

bus, _ := m.GetDefaultBus()
_, _ = bus.Dispatch(ctx, &HelloMessage{Text: "World"})

🔍 More Examples

  • ✅ Commands with void return
  • ✅ Queries with return value access
  • ✅ Retry and Dead Letter Queue
  • ✅ Custom Middleware and Transports
  • ✅ Event Listeners and Lifecycle Hooks

See Usage Scenarios for commands, queries, return values and advanced use-cases.

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

⚖️ License

This project is licensed under the MIT License - see the LICENSE file for details.

⭐️ Support

If you find this project useful, please consider starring ⭐️ it and sharing with others!

🙏 Acknowledgments

About

A message bus system for Go that helps applications send and handle messages through synch/asynch channels.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages