@@ -10,12 +10,18 @@ import (
10
10
// Option for queue system
11
11
type Option func (* options )
12
12
13
+ // AMQP 0-9-1 Model Explained
14
+ // ref: https://www.rabbitmq.com/tutorials/amqp-concepts.html
13
15
type options struct {
14
16
runFunc func (context.Context , core.QueuedMessage ) error
15
17
logger queue.Logger
16
18
addr string
17
19
subj string
18
20
tag string
21
+ // Durable AMQP exchange name
22
+ exchangeName string
23
+ // Exchange Types: Direct, Fanout, Topic and Headers
24
+ exchangeType string
19
25
}
20
26
21
27
// WithAddr setup the URI
@@ -25,6 +31,28 @@ func WithAddr(addr string) Option {
25
31
}
26
32
}
27
33
34
+ // WithExchangeName setup the Exchange name
35
+ // Exchanges are AMQP 0-9-1 entities where messages are sent to.
36
+ // Exchanges take a message and route it into zero or more queues.
37
+ func WithExchangeName (val string ) Option {
38
+ return func (w * options ) {
39
+ w .exchangeName = val
40
+ }
41
+ }
42
+
43
+ // WithExchangeType setup the Exchange type
44
+ // The routing algorithm used depends on the exchange type and rules called bindings.
45
+ // AMQP 0-9-1 brokers provide four exchange types:
46
+ // Direct exchange (Empty string) and amq.direct
47
+ // Fanout exchange amq.fanout
48
+ // Topic exchange amq.topic
49
+ // Headers exchange amq.match (and amq.headers in RabbitMQ)
50
+ func WithExchangeType (val string ) Option {
51
+ return func (w * options ) {
52
+ w .exchangeType = val
53
+ }
54
+ }
55
+
28
56
// WithAddr setup the tag
29
57
func WithTag (tag string ) Option {
30
58
return func (w * options ) {
@@ -55,10 +83,12 @@ func WithLogger(l queue.Logger) Option {
55
83
56
84
func newOptions (opts ... Option ) options {
57
85
defaultOpts := options {
58
- addr : "amqp://guest:guest@localhost:5672/" ,
59
- subj : "queue" ,
60
- tag : "golang-queue" ,
61
- logger : queue .NewLogger (),
86
+ addr : "amqp://guest:guest@localhost:5672/" ,
87
+ subj : "golang-queue" ,
88
+ tag : "golang-queue" ,
89
+ exchangeName : "test-exchange" ,
90
+ exchangeType : "direct" ,
91
+ logger : queue .NewLogger (),
62
92
runFunc : func (context.Context , core.QueuedMessage ) error {
63
93
return nil
64
94
},
0 commit comments