-
Notifications
You must be signed in to change notification settings - Fork 1
/
consumer.go
68 lines (57 loc) · 1.52 KB
/
consumer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package rabbitmq
import (
"context"
amqp "github.com/rabbitmq/amqp091-go"
)
// An IConsumer handles an amqp message (delivery - in terms of github.com/rabbitmq/amqp091-go library).
//
// Underlying implementations are responsible for either `Acknowledge` or `Reject` of the message.
//
// HINT: one can consume messages the same way as http request handling via http.Handler
// i.e. building chain of middlewares for: panic-handling, logging, tracing and error-handling ...etc.
type IConsumer interface {
Consume(ctx context.Context, msg amqp.Delivery)
}
type ConsumerFunc func(ctx context.Context, msg amqp.Delivery)
func (f ConsumerFunc) Consume(ctx context.Context, msg amqp.Delivery) {
f(ctx, msg)
}
// AMQPConsumer collects all parameters required for creating a queue and consuming messages
type AMQPConsumer struct {
ExchangeParams
QueueParams
QueueBindParams
ConsumerParams
IConsumer
}
// ExchangeParams and all other underlying structs created for compacting amqp091-go `function` parameters
type ExchangeParams struct {
Name string
Type string
Durable bool
AutoDelete bool
Internal bool
Nowait bool
Args amqp.Table
}
type QueueParams struct {
Name string
Durable bool
AutoDelete bool
Exclusive bool
Nowait bool
Args amqp.Table
}
type QueueBindParams struct {
Nowait bool
Args amqp.Table
}
type ConsumerParams struct {
RoutingKeys []string
ConsumerID string
AutoAck bool
Exclusive bool
NoLocal bool
Nowait bool
Args amqp.Table
}