gomessenger

module
v0.1.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2020 License: Apache-2.0

README

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
    }
}

Directories

Path Synopsis
examples
command_handler command
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL