Skip to content

Commit 438a235

Browse files
authored
refactor (#54)
Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent bf5e04a commit 438a235

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

pkg/rabbitmqamqp/amqp_binding.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ type AMQPBindingInfo struct {
1010
}
1111

1212
type AMQPBinding struct {
13-
sourceName string
14-
destinationName string
15-
toQueue bool
16-
bindingKey string
17-
management *AmqpManagement
18-
additionalArguments map[string]any
13+
sourceName string
14+
destinationName string
15+
toQueue bool
16+
bindingKey string
17+
management *AmqpManagement
18+
arguments map[string]any
1919
}
2020

2121
func newAMQPBinding(management *AmqpManagement) *AMQPBinding {
@@ -38,8 +38,8 @@ func (b *AMQPBinding) Destination(name string, isQueue bool) {
3838
b.toQueue = isQueue
3939
}
4040

41-
func (b *AMQPBinding) AdditionalArguments(args map[string]any) {
42-
b.additionalArguments = args
41+
func (b *AMQPBinding) Arguments(arguments map[string]any) {
42+
b.arguments = arguments
4343
}
4444

4545
// Bind creates a binding between an exchange and a queue or exchange
@@ -61,8 +61,8 @@ func (b *AMQPBinding) Bind(ctx context.Context) (string, error) {
6161
kv["binding_key"] = b.bindingKey
6262
kv["source"] = b.sourceName
6363
kv[destination] = b.destinationName
64-
if b.additionalArguments != nil {
65-
kv["arguments"] = b.additionalArguments
64+
if b.arguments != nil {
65+
kv["arguments"] = b.arguments
6666
} else {
6767
kv["arguments"] = make(map[string]any)
6868
}

pkg/rabbitmqamqp/amqp_binding_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ var _ = Describe("AMQP Bindings test ", func() {
6969
bindingPath, err := management.Bind(context.TODO(), &ExchangeToExchangeBindingSpecification{
7070
SourceExchange: exchangeName,
7171
DestinationExchange: exchangeName2,
72+
Arguments: map[string]any{},
7273
})
7374

7475
Expect(err).To(BeNil())
@@ -82,27 +83,31 @@ var _ = Describe("AMQP Bindings test ", func() {
8283
_, err := management.Bind(context.TODO(), &ExchangeToExchangeBindingSpecification{
8384
SourceExchange: "",
8485
DestinationExchange: "destination",
86+
Arguments: map[string]any{},
8587
})
8688
Expect(err).NotTo(BeNil())
8789
Expect(err.Error()).To(ContainSubstring("source and destination names are required"))
8890

8991
_, err = management.Bind(context.TODO(), &ExchangeToExchangeBindingSpecification{
9092
SourceExchange: "source",
9193
DestinationExchange: "",
94+
Arguments: map[string]any{},
9295
})
9396
Expect(err).NotTo(BeNil())
9497
Expect(err.Error()).To(ContainSubstring("source and destination names are required"))
9598

9699
_, err = management.Bind(context.TODO(), &ExchangeToQueueBindingSpecification{
97100
SourceExchange: "",
98101
DestinationQueue: "destination",
102+
Arguments: map[string]any{},
99103
})
100104
Expect(err).NotTo(BeNil())
101105
Expect(err.Error()).To(ContainSubstring("source and destination names are required"))
102106

103107
_, err = management.Bind(context.TODO(), &ExchangeToQueueBindingSpecification{
104108
SourceExchange: "source",
105109
DestinationQueue: "",
110+
Arguments: map[string]any{"binding_key": "key"},
106111
})
107112
Expect(err).NotTo(BeNil())
108113
Expect(err.Error()).To(ContainSubstring("source and destination names are required"))

pkg/rabbitmqamqp/amqp_management.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (a *AmqpManagement) DeclareQueue(ctx context.Context, specification IQueueS
182182
amqpQueue.AutoDelete(specification.isAutoDelete())
183183
amqpQueue.Exclusive(specification.isExclusive())
184184
amqpQueue.QueueType(specification.queueType())
185-
amqpQueue.SetArguments(specification.buildArguments())
185+
amqpQueue.Arguments(specification.buildArguments())
186186

187187
return amqpQueue.Declare(ctx)
188188
}
@@ -217,7 +217,7 @@ func (a *AmqpManagement) Bind(ctx context.Context, bindingSpecification IBinding
217217
bind.SourceExchange(bindingSpecification.sourceExchange())
218218
bind.Destination(bindingSpecification.destination(), bindingSpecification.isDestinationQueue())
219219
bind.BindingKey(bindingSpecification.bindingKey())
220-
bind.AdditionalArguments(bindingSpecification.arguments())
220+
bind.Arguments(bindingSpecification.arguments())
221221
return bind.Bind(ctx)
222222

223223
}

pkg/rabbitmqamqp/amqp_queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type AmqpQueue struct {
8888
name string
8989
}
9090

91-
func (a *AmqpQueue) SetArguments(arguments map[string]any) {
91+
func (a *AmqpQueue) Arguments(arguments map[string]any) {
9292
a.arguments = arguments
9393
}
9494

0 commit comments

Comments
 (0)