Home > Back-end >  Azure ServiceBusQueue function not firing locally
Azure ServiceBusQueue function not firing locally

Time:02-10

I just cannot seem to figure out why this function will not fire.

There is an active message in my service bus queue.

My local.settings.json file has the correct queue name and bus connection string which are referenced correctly in the main function class.

I've checked my code agaisn't the example in the MS docs and it looks correct.

When I run it in debug, the CLI picks up the correct function then logs host lock acquired, but does nothing else.

I have tried...

  • Adding ;TransportType=AmqpWebSockets to the connection string
  • Explicitly typing the queue name in the main function class instead of the json settings file
  • Sending a new message onto the queue
  • Refreshing the queue

But it just will not work and I'm wondering what else to try?

Running the following...

.NET core - 3.1

Azure core tools - 3.0

Function version - 3.3.1

Nugets...

Azure.Messaging.ServiceBus - 7.5.1

Microsoft.Azure.WebJobs.Extensions.ServiceBus - 5.2.0 (I'm using the new ServiceBusReceivedMessage type)

Microsoft.NET.Sdk.Functions - 3.0.13

I haven't reached the stage to publish yet, still just getting it running locally first.

Thanks

 public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task Run([ServiceBusTrigger("MessageQueueName", Connection = "ServiceBusConnectionString")] ServiceBusReceivedMessage message, ILogger logger)
        {
            var bus = new AzureBus(Environment.GetEnvironmentVariable("ServiceBusConnectionString", EnvironmentVariableTarget.Process)).SendOnly();
            var endpoint = new Endpoint(bus, logger);

            logger.LogInformation($"Message received from bus - {message}");

            await endpoint.Start();
            await bus.Handle(message);
        }
    }

CodePudding user response:

could you share your code snippet for the main class? It should look something like this:

  public static async System.Threading.Tasks.Task RunAsync([ServiceBusTrigger("myqueue", Connection = "ServiceBusConnection")]
    Message myQueueItem, string lockToken, Microsoft.Azure.ServiceBus.Core.MessageReceiver messageReceiver, ILogger log)

if using MessageReceiver you need to handle DeadLetter/Completing the message yourself

EDIT: make sure you have the storage emulator running aswell

CodePudding user response:

TransportType is not a valid token for the connection string and will be ignored by the Service Bus client library. To use the web socket transport, the easiest way is to specify it in your host.json:

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