Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure.Messaging.ServiceBus unable to configure TransportType

I'm currently trying to make use of the Azure.Messaging.ServiceBus package following this Getting Started page. I ran into a problem where I would receive the following error:

Azure.Messaging.ServiceBus.ServiceBusException: 'An existing connection was forcibly closed by the remote host. ErrorCode: ConnectionReset (ServiceCommunicationProblem).

I understand this happens because the port is blocked. To get around this, I created the following:

var option = new ServiceBusClientOptions
{
    TransportType = ServiceBusTransportType.AmqpWebSockets
};

var client = new ServiceBusClient(connectionString, options);

As per this documentation.

This solves the problem for the Sender and Receiver code. My problem still occurs with an Azure Function setup to use ServiceBusQueues as its trigger. I saw on that documentation that I can append

TransportType=AmqpWebSockets;

to the connection string, and it would fix the problem. However that feature doesn't seem to be present in the newer Azure.Messaging.ServiceBus package, only the older Microsoft.Azure.ServiceBus package.

Is there a way to assign the TransportType for the Service Bus Queue connection string in the Azure Function without downgrading packages? It's currently grabbing the connection string from local.settings.json.

Code for the Azure Function:

[Function("ServiceBusQueueTrigger1")]
public static async void Run([ServiceBusTrigger("someQueueName", Connection = "somebus_SERVICEBUS")] string myQueueItem, FunctionContext context)
{
    // some function code
}
like image 515
Stefan Avatar asked Feb 01 '26 07:02

Stefan


2 Answers

It seems that appending TransportType=AmqpWebSockets; will work to resolve the issue for the Azure Function. It won't work for the Sender/Receiver code since those rely on the NuGet package. The Azure Function does not.

like image 180
Stefan Avatar answered Feb 02 '26 23:02

Stefan


If you are using Azure Functions with ServiceBusTrigger, you can add this to host.json to specify the use of AMQP web sockets:

"extensions": {
  "serviceBus": {
    "transportType": "amqpWebSockets"
  }
}

As other answers and comments have pointed out, appending TransportType=AmqpWebSockets to the connection string has no effect when using the newer package versions.

like image 35
Lee D Avatar answered Feb 02 '26 23:02

Lee D