diff --git a/pkg/rabbitmqamqp/amqp_connection.go b/pkg/rabbitmqamqp/amqp_connection.go index 8d65fcf..6583579 100644 --- a/pkg/rabbitmqamqp/amqp_connection.go +++ b/pkg/rabbitmqamqp/amqp_connection.go @@ -262,6 +262,10 @@ func (a *AmqpConnection) open(ctx context.Context, address string, connOptions * WriteTimeout: connOptions.WriteTimeout, } azureConnection, err = amqp.Dial(ctx, address, amqpLiteConnOptions) + if err != nil && (connOptions.TLSConfig != nil || uri.Scheme == AMQPS) { + Error("Failed to open TLS connection", fmt.Sprintf("%s://%s", uri.Scheme, uri.Host), err, "ID", connOptions.Id) + return fmt.Errorf("failed to open TLS connection: %w", err) + } if err != nil { Error("Failed to open connection", ExtractWithoutPassword(address), err, "ID", connOptions.Id) return fmt.Errorf("failed to open connection: %w", err) diff --git a/pkg/rabbitmqamqp/amqp_connection_test.go b/pkg/rabbitmqamqp/amqp_connection_test.go index 317ea71..73bce49 100644 --- a/pkg/rabbitmqamqp/amqp_connection_test.go +++ b/pkg/rabbitmqamqp/amqp_connection_test.go @@ -164,4 +164,16 @@ var _ = Describe("AMQP connection Test", func() { }() }) + Describe("AMQP TLS connection should fail with error.", func() { + tlsConfig := &tls.Config{} + + // Dial the AMQP server with TLS configuration + connection, err := Dial(context.Background(), "amqps://does_not_exist:5671", &AmqpConnOptions{ + TLSConfig: tlsConfig, + }) + Expect(connection).To(BeNil()) + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(ContainSubstring("failed to open TLS connection")) + }) + }) diff --git a/pkg/rabbitmqamqp/common.go b/pkg/rabbitmqamqp/common.go index f20d0ae..2f29e81 100644 --- a/pkg/rabbitmqamqp/common.go +++ b/pkg/rabbitmqamqp/common.go @@ -10,6 +10,7 @@ import ( // public consts +const AMQPS = "amqps" const StreamFilterValue = "x-stream-filter-value" const (