forked from adjust/rmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (28 loc) · 835 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"log"
"time"
"github.com/adjust/rmq"
)
const unackedLimit = 1000
func main() {
connection := rmq.OpenConnection("consumer", "tcp", "localhost:6379", 2)
queue := connection.OpenQueue("things")
queue.StartConsuming(unackedLimit, 500*time.Millisecond)
queue.AddBatchConsumer("things", 111, NewBatchConsumer("things"))
queue = connection.OpenQueue("balls")
queue.StartConsuming(unackedLimit, 500*time.Millisecond)
queue.AddBatchConsumer("balls", 111, NewBatchConsumer("balls"))
select {}
}
type BatchConsumer struct {
tag string
}
func NewBatchConsumer(tag string) *BatchConsumer {
return &BatchConsumer{tag: tag}
}
func (consumer *BatchConsumer) Consume(batch rmq.Deliveries) {
time.Sleep(time.Millisecond)
log.Printf("%s consumed %d: %s", consumer.tag, len(batch), batch[0])
batch.Ack()
}