events

package module
Version: v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 0 Imported by: 0

README

goevents Build Status GoDoc Go Report Card

Go messaging library

About

goevents allows to dispatch events between applications.

An application produces events based on actions. Another application consume these events and maybe create new events.

Scenario: If an application produces an event "payment.received", another application may want to delivery the product to the buyer.

Supported Transport

  • AMQP

How to use

The consumer

conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/")

if err != nil {
    panic(err)
}

defer conn.Close()

c, err := NewConsumer(conn, false, "events-exchange", "events-queue")

if err != nil {
    panic(err)
}

defer c.Close()

c.Subscribe("object.*", func(body []byte) bool {
    fmt.Println(body)
    return true
})

go c.Consume()

select{}

The producer

conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/")

if err != nil {
    panic(err)
}

defer conn.Close()

p, err := NewProducer(conn, "events-exchange", "events-queue")

if err != nil {
    panic(err)
}

defer p.Close()

err = p.Publish("object.my_action", []byte("message"))

if err != nil {
    panic(err)
}

Important

When using producer, always close all your producers (things who call the producer.Publish) before closing the producer itself (producer.Close). In this way, you have more garanties that your messages is delivered to RabbitMQ.

Documentation

Overview

Package events implements a messaging library

About

goevents allows to dispatch events between applications.

An application produces events based on actions. Another application consume these events and maybe create new events.

Supported Transport

AMQP

How to use

The consumer

conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/", "events-queue", "events-exchange")

if err != nil {
    panic(err)
}

c, err := NewConsumer(conn, false)

if err != nil {
    panic(err)
}

c.Subscribe("my_action", func(body []byte) bool {
    fmt.Println(body)
    return true
})

The producer

conn, err := NewConnection("amqp://guest:guest@127.0.0.1:5672/", "events-queue", "events-exchange")

if err != nil {
    panic(err)
}

p, err := NewProducer(conn)

if err != nil {
    panic(err)
}

err = p.Publish("my_action", []byte("message"))

if err != nil {
    panic(err)
}

Source Files

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL