eventbus

package
v1.4.5-alpha1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MPL-2.0 Imports: 1 Imported by: 1

Documentation

Overview

Package eventbus is a default implementation of InterfaceEventBus declared in "github.com/ottemo/commerce/env" package.

Event bus is a service used for simplified communication between application code. Event provider emits an event message and event listeners makes special handling for an event.

Event name is "." delimited string. So, even listeners can listen for all messages of "top level" message (i.e. listener for "api" event will listen for "api.checkout.visitCheckout" automatically).

Event provides a data objects relative to. These objects could be changed during event handling, as well as new data could be added to a data map, during event processing.

To be more consistent and clear, event names should be declared as a package constants with description about providing event data map.

Example 1:
----------
    return env.ErrorNew(ConstErrorModule, ConstErrorLevel, "004e9f7b-bb97-4356-bbc2-5e084736983b", "unknown cmd '"+args[0]+"'")
    env.Event("api.checkout.visitCheckout", eventData)

Example 2:
----------
    salesHandler := func(event string, eventData map[string]interface{}) bool {
        env.LogMessage( fmt.Sprintf("%+v", eventData) )
    }
    env.EventRegisterListener("checkout.success", salesHandler)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultEventBus

type DefaultEventBus struct {
	// contains filtered or unexported fields
}

DefaultEventBus InterfaceEventBus implementer class

func (*DefaultEventBus) New

func (it *DefaultEventBus) New(event string, args map[string]interface{})

New generates new event, with following dispatching

func (*DefaultEventBus) RegisterListener

func (it *DefaultEventBus) RegisterListener(event string, listener env.FuncEventListener)

RegisterListener adds listener to event handling stack

  • event listening is patch based, "" - global listener on any event, "api.product" - will listen for app events starts with api.product.[...])

Jump to

Keyboard shortcuts

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