'Sending Message to Azure Service Bus works locally, but not from service deployed on AWS

The following code works to send the message to an Azure Service Bus Queue when I run my service locally. The service is written with JAVA and with the Spring Boot Framework. The service is deployed on AWS, but needs to access the queue on Azure.

      // create a Service Bus Sender client for the queue
      ServiceBusSenderClient senderClient = new ServiceBusClientBuilder()
          .connectionString("myPrimaryConnectionStringForSending")
          // .transportType(AmqpTransportType.AMQP_WEB_SOCKETS)
          .sender()
          .queueName("myQueueName")
          .buildClient();
      // send one message to the queue
      senderClient.sendMessage(new ServiceBusMessage("Hello World!"));

This is the error message i get from the deployed service:

Caused by: com.azure.core.amqp.exception.AmqpException: Connection refused, errorContext[NAMESPACE: my-env-services-servicebus-namespace.servicebus.windows.net. ERROR CONTEXT: N/A]

When I try to send it with the .transportType(AmqpTransportType.AMQP_WEB_SOCKETS) line then I receive following error:

c.a.c.a.i.ReactorConnection              : onConnectionError connectionId[MF_074e33_164373...], hostName[proxy.private.emea.vwapps.io], message[Starting new reactor], error[protocol = my-env-services-servicebus-namespace.servicebus.windows.net host = null, TrackingId: d0b2ba5d-f5d9-4104-b5fa-..., at: 2022-02-01T17:29:51.299629Z[Etc/UTC], errorContext[NAMESPACE: my-env-services-servicebus-namespace.servicebus.windows.net. ERROR CONTEXT: N/A]]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source