I have setup Azure Service bus to use RBAC and assigned myself a role of "Azure Service Bus Data Owner". I am able to send a message to a queue with:
ServiceBusClient client = new ServiceBusClient("mynamespace.servicebus.windows.net", new AzureCliCredential());
ServiceBusMessage serviceBusMessage = new ServiceBusMessage("my message");
await client.CreateSender("myqueue").SendMessageAsync(serviceBusMessage);
when the message is there, I am trying to run an Azure Function with Service Bus Trigger, like this:
[Function(nameof(MyTrigger))]
public async Task Run(
[ServiceBusTrigger("myqueue", Connection = "MyServiceBusNamespace")]
ServiceBusReceivedMessage message,
ServiceBusMessageActions messageActions)
{
_logger.LogInformation("Message Body: {body}", message.Body);
await messageActions.CompleteMessageAsync(message);
await Task.CompletedTask;
}
with settings like this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsSecretStorageType": "Files",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"MyServiceBusNamespace": "mynamespace.servicebus.windows.net"
}
}
Now I get the error upon running the funciton locally:
[2025-02-17T17:22:14.636Z] The listener for function 'Functions.MyTrigger' was unable to start.
[2025-02-17T17:22:14.636Z] The listener for function 'Functions.MyTrigger' was unable to start. Azure.Messaging.ServiceBus: The connection string could not be parsed; either it was malformed or contains no well-known tokens.
How do I use the service bus trigger with Azure Function (not the one with the SAS key but RBAC)?
"MyServiceBusNamespace": "mynamespace.servicebus.windows.net". For making it to work, you need to first deploy to azure func, later give rbac to managed idenity, then it works