Giter Club home page Giter Club logo

evently's Introduction

YohGo Evently

Build Status

YohGo Evently is a machinery based package that manages events asynchronously in an event-based architecture

Image of Yaktocat



Requirements

  • Go (1.5+)
  • Machinery (1+)

Features

  • Lightweight and fast
  • Native Go implementation
  • Supports redis and AMQP message brokers

Installation

Simply install the package to your $GOPATH with the go tool from shell:

$ go get github.com/RichardKnop/machinery/v1
$ go get github.com/yohgo/evently

Make sure Git is installed on your machine and in your system's PATH.


Usage

YohGo Evently is a package that manages events asynchronously in an event-based architecture. Evently is based on Machinery which is an asynchronous task queue/job queue based on distributed message passing.

Event Publishing

Example of using the evently package for event publishing:

import (
    "github.com/yohgo/evently"
)

// A string map containing the event publisher's settings
settings := map[string]string{
    "broker"           : "A url to a redis or AMQP broker",
    "downstream_queue" : "The default downstream event queue",
    "upstream_queues"  : "A colon-separated list of upstream event queues",
    "result_backend"   : "A url to the backend result storage",
            "amqp_exchange" : "An AMQP exchange", // (only when broker = AMQP)
            "amqp_exchange" : "An AMQP exchange type", // (only when broker = AMQP)
            "amqp_exchange" : "An AMQP binding key", // (only when broker = AMQP)
}

// Creating a new event publisher
publisher := evently.NewEventPublisher(settings)

// Attempting to publish a user.updated event
if !publisher.EventPublisher.Publish("user.updated", user).IsOK() {
    return errors.New("Unable to publish the user.updated event")
}

For more details regarding event publisher configuration check Machinery Documentation

Event Listening

Example of using the evently package for event listening:

import (
    "github.com/yohgo/evently"
)

// An event handler method (takes a json string)
func eventHandler(JSONData string) error {
    /* Event handling logic */
}

settings := map[string]string{
    "broker"           : "A url to a redis or AMQP broker",
    "downstream_queue" : "The default downstream event queue",
    "upstream_queues"  : "A colon-separated list of upstream event queues",
    "result_backend"   : "A url to the backend result storage",
            "amqp_exchange" : "An AMQP exchange", // (only when broker = AMQP)
            "amqp_exchange" : "An AMQP exchange type", // (only when broker = AMQP)
            "amqp_exchange" : "An AMQP binding key", // (only when broker = AMQP)
}

// A map of event/handler pairs
handlers := map[string]interface{}{
    "user.updated": eventHandler
}

// Creating a new event listener
listener := evently.NewEventListener("user.listener", settings, handlers)

// Attempting to start the user.updated event listener
if !listener.EventPublisher.Eavesdrop().IsOK() {
    return errors.New("Unable to start the event listener")
}

For more details regarding event listener configuration check Machinery Documentation

evently's People

Contributors

zorbasd avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.