1
0
mirror of https://github.com/eventials/goevents.git synced 2025-04-24 13:48:53 +08:00
Eddy Santos 82c88a052a (feat): implement PriorityConsume function
The `PriorityConsume` function consumes messages based on the priority of consumers. The function registers and logs the handlers of each consumer. It then starts consuming messages in a loop, prioritizing the consumers accordingly. The consumption stops if a stop signal is received from a consumer. The function also checks and handles the scenario when all consumers are stopped.
The `checkPriorityMessages` function is also introduced which determines if a consumer is eligible to consume a message, considering the messages in higher priority consumers.
The code has been refactored for improved readability, and detailed comments have been added for better understanding.
2023-06-02 16:12:26 -03:00
2020-10-21 21:38:41 -03:00
2019-05-14 12:31:43 -03:00
2021-10-18 14:47:04 -03:00
2016-12-01 10:52:22 -02:00
2016-12-01 16:19:05 -02:00
2020-10-21 19:41:11 -03:00
2020-10-21 19:41:11 -03:00
2020-10-21 19:41:11 -03:00
2020-10-21 19:41:11 -03:00
2016-11-25 16:25:27 -02:00

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.

Description
No description provided
Readme MIT 2 MiB
Languages
Go 99.1%
Dockerfile 0.9%