https://github.com/greyireland/amq
https://github.com/greyireland/amq
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/greyireland/amq
- Owner: greyireland
- Created: 2022-08-31T06:47:17.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-12T03:12:10.000Z (about 3 years ago)
- Last Synced: 2025-01-29T03:51:24.201Z (9 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# amq
simple async mq
## example
```go
package amqimport (
"fmt"
"github.com/go-redis/redis/v8"
"github.com/greyireland/log"
"testing"
"time"
)type Msg struct {
Tp string `json:"tp"`
Data string `json:"data"`
}func TestNewSender(t *testing.T) {
r := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
})
queue := "test"s := NewSender(r, queue)
go func() {
for i := 0; i < 100000; i++ {s.Send(Msg{
Tp: "1",
Data: fmt.Sprintf("hello %d", i),
})
}
}()
re := NewReceiver(r, queue)
go func() {
for {
var data Msg
err := re.Receive(&data)
if err != nil {
log.Warn("dequeue error", "err", err)
}
fmt.Println("data", data)
}
}()
time.Sleep(10 * time.Second)
}```