https://github.com/chk-n/gomemq
Lightweight, reliable and concurrent in-memory message queue written in go
https://github.com/chk-n/gomemq
golang in-memory lightweight message-queue reliable
Last synced: 6 months ago
JSON representation
Lightweight, reliable and concurrent in-memory message queue written in go
- Host: GitHub
- URL: https://github.com/chk-n/gomemq
- Owner: chk-n
- License: mit
- Created: 2023-12-04T19:15:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-30T15:37:31.000Z (over 2 years ago)
- Last Synced: 2023-12-30T16:23:57.870Z (over 2 years ago)
- Topics: golang, in-memory, lightweight, message-queue, reliable
- Language: Go
- Homepage:
- Size: 40 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Gomemq
Simple and concurrent in-memory message queue written in golang with zero third-party dependencies*
\*Excluding packages used for tests
## Features
* Zero third party dependencies
* Type safe
* No serialisation
* Batch publishing
* Receive ACK after message received by all subscribers
* Receive 'DONE' after all subscribers successfully processed message(s)
## Get
`go get github.com/chk-n/gomemq`
## Example
```go
// Set up message queue
cfg := gomemq.Config{
// retrier
}
mq := gomemq.New(cfg)
// Create topic
cfgTopic := gomemq.ConfigTopic{
// memory consumption
// concurrency control
// other topic configurations
}
t,_ := gomemq.NewTopic[CustomType](cfgTopic)
// Publish to topic
var msg CustomType
t.Publish(msg)
// equivalent to gomemq.Publish("topic", msg)
// Subscribe to topic
t.Subscribe(func(msg CustomType) error {
// handle message asychnronously
})
// Join existing topic
t,_ = gomemq.Join("topic")
// Batch publish with ACK and DONE acknowledgement
ctx := gomemq.PublishBatchDone[CustomType]("topic", []CustomType{msg, msg})
select {
case <-ctx.Ack():
// message was acknowledged
case <-ctx.WithAckTimeout(3 * time.Second):
// message was not acknowledged within 3 seconds of publishing
case <-ctx.WithDoneTimeout(2 * time.Minute):
// message was not successfully processed within 2 minutes of ACK
case <-ctx.Done():
// yay, message was successfully processed
}
```