https://github.com/welllog/omq
message
https://github.com/welllog/omq
Last synced: about 2 months ago
JSON representation
message
- Host: GitHub
- URL: https://github.com/welllog/omq
- Owner: welllog
- Created: 2022-04-30T07:53:14.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-05T02:58:57.000Z (almost 2 years ago)
- Last Synced: 2025-03-11T17:47:54.077Z (over 1 year ago)
- Language: Go
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# omq
message
###### Currently only redis-based message queues are implemented
#### USAGE
```go
queue := redisq.NewQueue(redisClient, "queue_name", rediq.WithPartitionNum(4))
queue.Produce(&omq.Message{
Topic: "topic_name",
Payload: NewPayloadJsonEncoder(map[string]string{"name": "test"}),
DelayAt: time.Now().Add(time.Second)
})
queue.Produce(&omq.Message{
Topic: "topic_name",
Payload: ByteEncoder("words"),
})
ctx, cancel := context.WithCancel(context.Background())
fetcher, _ := queue.Fetcher(ctx, 0)
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-quit
cancel()
}()
for msg := range fetcher.Messages() {
// TODO
fetcher.Commit(ctx, msg)
}
```
#### FEATURE
Program crashes usually result in lost messages, to avoid this, the library supports retry, When this property is set, the task being processed will be cached.
Once the cached task exceeds the commitTimeout, it will re-enter the queue
```go
queue := redisq.NewQueue(redisClient, "queue_name",
redisq.WithMaxRetry(3), // Retry up to 3 times
redisq.WithCommitTimeout(10), // When the number of retries is set greater than 0, re-enter the queue and retry if it is not submitted for more than 10 seconds
)
```