From 189408c5bba3f63eb698d6001fa25fc85228cfe2 Mon Sep 17 00:00:00 2001 From: Gabriele Santomaggio Date: Mon, 16 Sep 2024 09:34:27 +0200 Subject: [PATCH] Restore the Azure Client (#11) The null value is fixed here https://github.com/Azure/go-amqp/pull/336 Signed-off-by: Gabriele Santomaggio --- examples/getting_started/main.go | 1 - go.mod | 4 +--- go.sum | 2 ++ rabbitmq_amqp/amqp_binding.go | 7 +++++-- rabbitmq_amqp/amqp_exchange.go | 7 +++++-- rabbitmq_amqp/amqp_managent.go | 6 ++++-- rabbitmq_amqp/amqp_queue.go | 3 ++- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/examples/getting_started/main.go b/examples/getting_started/main.go index 46a2dc6..0491115 100644 --- a/examples/getting_started/main.go +++ b/examples/getting_started/main.go @@ -11,7 +11,6 @@ import ( func main() { fmt.Printf("Getting started with AMQP Go AMQP 1.0 Client\n") - chStatusChanged := make(chan *mq.StatusChanged, 1) go func(ch chan *mq.StatusChanged) { diff --git a/go.mod b/go.mod index 135f6cf..12cb540 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/rabbitmq/rabbitmq-amqp-go-client go 1.22.0 require ( - github.com/Azure/go-amqp v0.0.0-00010101000000-000000000000 github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/gomega v1.34.2 ) require ( + github.com/Azure/go-amqp v1.1.1-0.20240913224415-f631e6909719 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/go-cmp v0.6.0 // indirect @@ -20,5 +20,3 @@ require ( golang.org/x/tools v0.24.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace github.com/Azure/go-amqp => github.com/Gsantomaggio/go-amqp v0.0.0-20240905094626-af192b497e48 diff --git a/go.sum b/go.sum index 803082e..260b0ed 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/Azure/go-amqp v1.1.1-0.20240913224415-f631e6909719 h1:rL7yrEV9yputQV7T+Y9eJVmTVkK4B0aHlBc8TUITC5A= +github.com/Azure/go-amqp v1.1.1-0.20240913224415-f631e6909719/go.mod h1:vZAogwdrkbyK3Mla8m/CxSc/aKdnTZ4IbPxl51Y5WZE= github.com/Gsantomaggio/go-amqp v0.0.0-20240905094626-af192b497e48 h1:etxEtd7qkhJD34gpQesPbZuMJrqkc+ZOXqR3diVfGWs= github.com/Gsantomaggio/go-amqp v0.0.0-20240905094626-af192b497e48/go.mod h1:vZAogwdrkbyK3Mla8m/CxSc/aKdnTZ4IbPxl51Y5WZE= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/rabbitmq_amqp/amqp_binding.go b/rabbitmq_amqp/amqp_binding.go index 353c419..7b5d99a 100644 --- a/rabbitmq_amqp/amqp_binding.go +++ b/rabbitmq_amqp/amqp_binding.go @@ -1,6 +1,9 @@ package rabbitmq_amqp -import "context" +import ( + "context" + "github.com/Azure/go-amqp" +) type AMQPBindingInfo struct { } @@ -46,6 +49,6 @@ func (b *AMQPBinding) Bind(ctx context.Context) error { func (b *AMQPBinding) Unbind(ctx context.Context) error { bindingPathWithExchangeQueueKey := bindingPathWithExchangeQueueKey(b.sourceExchangeName, b.destinationQueue, b.bindingKey) - _, err := b.management.Request(ctx, nil, bindingPathWithExchangeQueueKey, commandDelete, []int{responseCode204}) + _, err := b.management.Request(ctx, amqp.Null{}, bindingPathWithExchangeQueueKey, commandDelete, []int{responseCode204}) return err } diff --git a/rabbitmq_amqp/amqp_exchange.go b/rabbitmq_amqp/amqp_exchange.go index d652b2b..73d6041 100644 --- a/rabbitmq_amqp/amqp_exchange.go +++ b/rabbitmq_amqp/amqp_exchange.go @@ -1,6 +1,9 @@ package rabbitmq_amqp -import "context" +import ( + "context" + "github.com/Azure/go-amqp" +) type AmqpExchangeInfo struct { name string @@ -56,7 +59,7 @@ func (e *AmqpExchange) IsAutoDelete() bool { func (e *AmqpExchange) Delete(ctx context.Context) error { path := exchangePath(e.name) - _, err := e.management.Request(ctx, nil, path, commandDelete, []int{responseCode204}) + _, err := e.management.Request(ctx, amqp.Null{}, path, commandDelete, []int{responseCode204}) return err } diff --git a/rabbitmq_amqp/amqp_managent.go b/rabbitmq_amqp/amqp_managent.go index 67a4f85..30c1fc6 100644 --- a/rabbitmq_amqp/amqp_managent.go +++ b/rabbitmq_amqp/amqp_managent.go @@ -154,12 +154,14 @@ func (a *AmqpManagement) validateResponseCode(responseCode int, expectedResponse } } - return PreconditionFailed + return errors.New(fmt.Sprintf("expected response code %d got %d", expectedResponseCodes, responseCode)) } func (a *AmqpManagement) request(ctx context.Context, id string, body any, path string, method string, expectedResponseCodes []int) (map[string]any, error) { - amqpMessage := amqp.NewMessageWithValue(body) + amqpMessage := &amqp.Message{ + Value: body, + } s := commandReplyTo amqpMessage.Properties = &amqp.MessageProperties{ ReplyTo: &s, diff --git a/rabbitmq_amqp/amqp_queue.go b/rabbitmq_amqp/amqp_queue.go index 36b5ac7..ada9775 100644 --- a/rabbitmq_amqp/amqp_queue.go +++ b/rabbitmq_amqp/amqp_queue.go @@ -2,6 +2,7 @@ package rabbitmq_amqp import ( "context" + "github.com/Azure/go-amqp" ) type AmqpQueueInfo struct { @@ -161,7 +162,7 @@ func (a *AmqpQueue) Declare(ctx context.Context) (IQueueInfo, error) { func (a *AmqpQueue) Delete(ctx context.Context) error { path := queuePath(a.name) - _, err := a.management.Request(ctx, nil, path, commandDelete, []int{responseCode200}) + _, err := a.management.Request(ctx, amqp.Null{}, path, commandDelete, []int{responseCode200}) return err }