forked from grafana/xk6-amqp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexchanges.go
100 lines (90 loc) · 1.93 KB
/
exchanges.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package amqp
import (
amqpDriver "github.com/streadway/amqp"
)
type Exchange struct {
Version string
Connection *amqpDriver.Connection
}
type ExchangeOptions struct {
ConnectionUrl string
}
type ExchangeDeclareOptions struct {
Name string
Kind string
Durable bool
AutoDelete bool
Internal bool
NoWait bool
Args amqpDriver.Table
}
type ExchangeBindOptions struct {
DestinationExchangeName string
SourceExchangeName string
RoutingKey string
NoWait bool
Args amqpDriver.Table
}
type ExchangeUnindOptions struct {
DestinationExchangeName string
SourceExchangeName string
RoutingKey string
NoWait bool
Args amqpDriver.Table
}
func (exchange *Exchange) Declare(options ExchangeDeclareOptions) error {
ch, err := exchange.Connection.Channel()
if err != nil {
return err
}
defer ch.Close()
return ch.ExchangeDeclare(
options.Name,
options.Kind,
options.Durable,
options.AutoDelete,
options.Internal,
options.NoWait,
options.Args,
)
}
func (exchange *Exchange) Delete(name string) error {
ch, err := exchange.Connection.Channel()
if err != nil {
return err
}
defer ch.Close()
return ch.ExchangeDelete(
name,
false, // ifUnused
false, // noWait
)
}
func (exchange *Exchange) Bind(options ExchangeBindOptions) error {
ch, err := exchange.Connection.Channel()
if err != nil {
return err
}
defer ch.Close()
return ch.ExchangeBind(
options.DestinationExchangeName,
options.RoutingKey,
options.SourceExchangeName,
options.NoWait,
options.Args,
)
}
func (exchange *Exchange) Unbind(options ExchangeUnindOptions) error {
ch, err := exchange.Connection.Channel()
if err != nil {
return err
}
defer ch.Close()
return ch.ExchangeUnbind(
options.DestinationExchangeName,
options.RoutingKey,
options.SourceExchangeName,
options.NoWait,
options.Args,
)
}