-
Notifications
You must be signed in to change notification settings - Fork 205
/
deliveries.go
46 lines (37 loc) · 1.15 KB
/
deliveries.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
39
40
41
42
43
44
45
46
package rmq
type Deliveries []Delivery
func (deliveries Deliveries) Payloads() []string {
payloads := make([]string, len(deliveries))
for i, delivery := range deliveries {
payloads[i] = delivery.Payload()
}
return payloads
}
// NOTE: The returned error map maps delivery indexes to errors. So if the
// error map is non empty you can use the indexes in the map to look up which
// of the deliveries ran into the corresponding error. See
// example/batch_consumer.
// functions with retry, see comments in delivery.go (recommended)
func (deliveries Deliveries) Ack() (errMap map[int]error) {
return deliveries.each(Delivery.Ack)
}
func (deliveries Deliveries) Reject() (errMap map[int]error) {
return deliveries.each(Delivery.Reject)
}
func (deliveries Deliveries) Push() (errMap map[int]error) {
return deliveries.each(Delivery.Push)
}
// helper functions
func (deliveries Deliveries) each(
f func(Delivery) error,
) (errMap map[int]error) {
for i, delivery := range deliveries {
if err := f(delivery); err != nil {
if errMap == nil { // create error map lazily on demand
errMap = map[int]error{}
}
errMap[i] = err
}
}
return errMap
}