Reputation: 1298
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
}
}
}
}
Upvotes: 0
Views: 798
Reputation: 1371
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:
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:
I have published the above function into the azure portal.
Make sure to add service bus connection string in the appsettings of function app and check my configuration ln the below:
when i will send messages from the service bus topic got triggered in the portal like below:
Output:
Upvotes: 0