I have a subscriber function in C#, that’s is listening to an Azure topic. It is working perfectly well when I run it from my Visual Studio. However, when I deployed it to Azure, it is not triggering automatically.
I have the following in my code:
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"SBConnectionString": "Endpoint=1234"
}
}
Subscriber function
public class Subscriber1
{
private readonly ILogger<Subscriber1> _logger;
public Subscriber1(ILogger<Subscriber1> logger)
{
_logger = logger;
}
[Function(nameof(Subscriber1))]
public async Task Run(
[ServiceBusTrigger("topic1", "Subscriber1", Connection = "SBConnectionString")]
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);
}
}
After going through some topics, I also created an appsettings.json file, like this:
{
"AzureWebJobs": {
"Storage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"extensions": {
"ServiceBus": {
"ConnectionStrings": {
"Primary": "Endpoint=sb:1234"
}
}
}
}
}
After deployment, the settings were not transferred. So I created a ConnectionString manually with the same name as local under ‘Environment variables, and put the path to the ServiceBus. it looks like this:
Had a look at this, which was pretty close to my scenario, but didn’t work for me.
Any suggestions?
1
- Local settings is only being used for local development and it will not copied to function app when you are deploying your function. So you need to add the connection string in App settings of function app.
- Here as you are using Service Bus trigger, so you need to add the Service Bus connection string in App settings post deployment.
My function triggered as expected.
1