Skip to content

Commit b5c747b

Browse files
committed
API consistency with .NET client
* Prefer using `IQueueSpecification` and `IExchangeSpecification` instead of `string`
1 parent 189408c commit b5c747b

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

examples/getting_started/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func main() {
4848
}
4949
fmt.Printf("Exchange %s created.\n", exchangeInfo.GetName())
5050

51-
bindingSpec := management.Binding().SourceExchange(exchangeInfo.GetName()).DestinationQueue(queueInfo.GetName()).Key("routing-key")
51+
bindingSpec := management.Binding().SourceExchange(exchangeSpec).DestinationQueue(queueSpec).Key("routing-key")
5252

5353
err = bindingSpec.Bind(context.Background())
5454
if err != nil {

rabbitmq_amqp/amqp_binding.go

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

1111
type AMQPBinding struct {
12-
sourceExchangeName string
13-
destinationQueue string
14-
bindingKey string
15-
management *AmqpManagement
12+
sourceExchange IExchangeSpecification
13+
destinationQueue IQueueSpecification
14+
bindingKey string
15+
management *AmqpManagement
1616
}
1717

1818
func newAMQPBinding(management *AmqpManagement) *AMQPBinding {
@@ -24,13 +24,13 @@ func (b *AMQPBinding) Key(bindingKey string) IBindingSpecification {
2424
return b
2525
}
2626

27-
func (b *AMQPBinding) SourceExchange(exchangeName string) IBindingSpecification {
28-
b.sourceExchangeName = exchangeName
27+
func (b *AMQPBinding) SourceExchange(exchangeSpec IExchangeSpecification) IBindingSpecification {
28+
b.sourceExchange = exchangeSpec
2929
return b
3030
}
3131

32-
func (b *AMQPBinding) DestinationQueue(queueName string) IBindingSpecification {
33-
b.destinationQueue = queueName
32+
func (b *AMQPBinding) DestinationQueue(queueSpec IQueueSpecification) IBindingSpecification {
33+
b.destinationQueue = queueSpec
3434
return b
3535
}
3636

@@ -39,16 +39,16 @@ func (b *AMQPBinding) Bind(ctx context.Context) error {
3939
path := bindingPath()
4040
kv := make(map[string]any)
4141
kv["binding_key"] = b.bindingKey
42-
kv["source"] = b.sourceExchangeName
43-
kv["destination_queue"] = b.destinationQueue
42+
kv["source"] = b.sourceExchange.GetName()
43+
kv["destination_queue"] = b.destinationQueue.GetName()
4444
kv["arguments"] = make(map[string]any)
4545
_, err := b.management.Request(ctx, kv, path, commandPost, []int{responseCode204})
4646
return err
4747

4848
}
4949

5050
func (b *AMQPBinding) Unbind(ctx context.Context) error {
51-
bindingPathWithExchangeQueueKey := bindingPathWithExchangeQueueKey(b.sourceExchangeName, b.destinationQueue, b.bindingKey)
51+
bindingPathWithExchangeQueueKey := bindingPathWithExchangeQueueKey(b.sourceExchange, b.destinationQueue, b.bindingKey)
5252
_, err := b.management.Request(ctx, amqp.Null{}, bindingPathWithExchangeQueueKey, commandDelete, []int{responseCode204})
5353
return err
5454
}

rabbitmq_amqp/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ func bindingPath() string {
8686
return "/" + Bindings
8787
}
8888

89-
func bindingPathWithExchangeQueueKey(exchangeName, queueName, key string) string {
89+
func bindingPathWithExchangeQueueKey(exchangeSpec IExchangeSpecification, queueSpec IQueueSpecification, key string) string {
9090
//string path =
9191
//$"/{Consts.Bindings}/src={Utils.EncodePathSegment(_sourceName)};{($"{destinationCharacter}={Utils.EncodePathSegment(_destinationName)};key={Utils.EncodePathSegment(_routingKey)};args=")}";
9292

93-
return fmt.Sprintf("/%s/src=%s;dstq=%s;key=%s;args=", Bindings, encodePathSegments(exchangeName), encodePathSegments(queueName), encodePathSegments(key))
93+
return fmt.Sprintf("/%s/src=%s;dstq=%s;key=%s;args=", Bindings, encodePathSegments(exchangeSpec.GetName()), encodePathSegments(queueSpec.GetName()), encodePathSegments(key))
9494

9595
}
9696

rabbitmq_amqp/entities.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ type IExchangeSpecification interface {
8686
}
8787

8888
type IBindingSpecification interface {
89-
SourceExchange(exchangeName string) IBindingSpecification
90-
DestinationQueue(queueName string) IBindingSpecification
89+
SourceExchange(exchangeSpec IExchangeSpecification) IBindingSpecification
90+
DestinationQueue(queueSpec IQueueSpecification) IBindingSpecification
9191
Key(bindingKey string) IBindingSpecification
9292
Bind(ctx context.Context) error
9393
Unbind(ctx context.Context) error

0 commit comments

Comments
 (0)