0

My Service bus trigger function reads messages from a service bus topic

[Function("Posting")]
public async Task Run(
        [ServiceBusTrigger("topicnName", "subscriptionName",Connection = "AppSettings:SERVICE_BUS_CONNSTRING")]
         ServiceBusReceivedMessage message,
         ServiceBusMessageActions messageActions)
{  

}

SERVICE_BUS_CONNSTRING is retrieved from Azure app configuration. And this function is working locally but not in Azure.

My application settings in Azure for worker runtime is set to dotnet-isolated

  {
    "name": "FUNCTIONS_WORKER_RUNTIME",
    "value": "dotnet-isolated",
    "slotSetting": false
  }

And my host.json is also configured as below:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensions": {
    "serviceBus": {
      "messageHandlerOptions": {
        "autoComplete": false,
        "maxConcurrentCalls": 1
      }
    }
  }
}
2
  • What versions of the Functions packages are you using? Commented Feb 15, 2024 at 22:41
  • what is the dotnet version you are using? Commented Feb 16, 2024 at 4:28

1 Answer 1

0

I have created Isolated service bus topic trigger function with runtime stack dotnet isolated. By using below code able to read the messages from the service bus topic like below:

enter image description here

function code:

using System;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace FunctionApp32323
{
    public class Function1
    {
        private readonly ILogger<Function1> _logger;

        public Function1(ILogger<Function1> logger)
        {
            _logger = logger;
        }

        [Function(nameof(Function1))]
        public async Task Run(
            [ServiceBusTrigger("firsttopic", "sample", Connection = "servicebusconnection")]
            ServiceBusReceivedMessage message,
            ServiceBusMessageActions messageActions)
        {
            _logger.LogInformation("Message ID: {id}", message.MessageId);
            _logger.LogInformation("Message Body: {body}", message.Body);
            _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);

             // Complete the message
            await messageActions.CompleteMessageAsync(message);
        }
    }
}

local.settings.josn:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "servicebusconnection": "your-servicebus-conn-string",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

host.json:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
        }
    }
}

The above function executed successfully. check below:

enter image description here

I have published the above function into the azure portal. enter image description here

enter image description here

Make sure to add service bus connection string in the appsettings of function app and check my configuration ln the below:

enter image description here

when i will send messages from the service bus topic got triggered in the portal like below:

Output:

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.