Stefan
Stefan

Reputation: 337

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
}

Upvotes: 2

Views: 2619

Answers (3)

Sean Feldman
Sean Feldman

Reputation: 25994

Azure Functions environment does not have the TCP ports blocks and therefore does not require WebSockets. Sending/receiving from/to Azure Functions using Service Bus queues/topics/subscriptions is not impacted by the constrains of other environments you're using. The messages will be flowing to your functions and sent out without a problem when the rest of the system (on premises for example) is using web sockets to connect to the namespace.

Upvotes: 0

Lee D
Lee D

Reputation: 12951

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.

Upvotes: 0

Stefan
Stefan

Reputation: 337

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.

Upvotes: 2

Related Questions