Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoMessenger

Build Status codecov

Simple implementation of a message bus to handle commands and queries easily but with the potential of middlewares.

You can go to the examples to see how it works: examples

Installation

go get github.com/isd4n/gomessenger

Usage

import (
    "github.com/isd4n/gomessenger/pkg/messenger"
    "github.com/isd4n/gomessenger/pkg/errors"
    "github.com/isd4n/gomessenger/pkg/middleware"
)

func main() {
    // We create a new bus
    commandBus := messenger.DefaultBus()

    // Adding a middleware to catch errors and send them to sentry (optional)
    commandBus.AddMiddleware(middleware.NewSentry("local", "dsn"))

    // Adding new message handler
    commandBus.AddHandler(MyHandler{})

    // Dispatching the first message without expecting any result
    myMessage := MyMessage{Id: "123abc"}
    env := commandBus.Dispatch(myMessage)
    if env.LastError != nil {
        // Error has occurried
    }

    if env.LastResult != nil {
        // Result received
    }
}

About

A simple messenger to handle commands and queries.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages