Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeromicro/go-queue
Kafka, Beanstalkd Pub/Sub framework.
https://github.com/zeromicro/go-queue
Last synced: 5 days ago
JSON representation
Kafka, Beanstalkd Pub/Sub framework.
- Host: GitHub
- URL: https://github.com/zeromicro/go-queue
- Owner: zeromicro
- License: mit
- Created: 2020-09-01T07:27:44.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-12T08:45:51.000Z (2 months ago)
- Last Synced: 2024-11-03T04:02:53.678Z (9 days ago)
- Language: Go
- Homepage:
- Size: 214 KB
- Stars: 713
- Watchers: 14
- Forks: 127
- Open Issues: 34
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome - zeromicro/go-queue - 09 star:0.7k fork:0.1k Kafka, Beanstalkd Pub/Sub framework. (Go)
README
# go-queue
## dq
High available beanstalkd.
### consumer example
```go
consumer := dq.NewConsumer(dq.DqConf{
Beanstalks: []dq.Beanstalk{
{
Endpoint: "localhost:11300",
Tube: "tube",
},
{
Endpoint: "localhost:11300",
Tube: "tube",
},
},
Redis: redis.RedisConf{
Host: "localhost:6379",
Type: redis.NodeType,
},
})
consumer.Consume(func(body []byte) {
fmt.Println(string(body))
})
```
### producer example
```go
producer := dq.NewProducer([]dq.Beanstalk{
{
Endpoint: "localhost:11300",
Tube: "tube",
},
{
Endpoint: "localhost:11300",
Tube: "tube",
},
})for i := 1000; i < 1005; i++ {
_, err := producer.Delay([]byte(strconv.Itoa(i)), time.Second*5)
if err != nil {
fmt.Println(err)
}
}
```## kq
Kafka Pub/Sub framework
### consumer example
config.yaml
```yaml
Name: kq
Brokers:
- 127.0.0.1:19092
- 127.0.0.1:19092
- 127.0.0.1:19092
Group: adhoc
Topic: kq
Offset: first
Consumers: 1
```example code
```go
var c kq.KqConf
conf.MustLoad("config.json", &c)q := kq.MustNewQueue(c, kq.WithHandle(func(k, v string) error {
fmt.Printf("=> %s\n", v)
return nil
}))
defer q.Stop()
q.Start()
```### producer example
```go
type message struct {
Key string `json:"key"`
Value string `json:"value"`
Payload string `json:"message"`
}pusher := kq.NewPusher([]string{
"127.0.0.1:19092",
"127.0.0.1:19092",
"127.0.0.1:19092",
}, "kq")ticker := time.NewTicker(time.Millisecond)
for round := 0; round < 3; round++ {
select {
case <-ticker.C:
count := rand.Intn(100)
m := message{
Key: strconv.FormatInt(time.Now().UnixNano(), 10),
Value: fmt.Sprintf("%d,%d", round, count),
Payload: fmt.Sprintf("%d,%d", round, count),
}
body, err := json.Marshal(m)
if err != nil {
log.Fatal(err)
}fmt.Println(string(body))
if err := pusher.Push(string(body)); err != nil {
log.Fatal(err)
}
}
}
cmdline.EnterToContinue()
```