I am using session queue on Azure and when I push some data on queue,I write one Azure function to trigger.
Please note that I have created statefull/session based queue.
The problem is when I push data to queue at that moment I got error like
The listener for function 'xxx' was unable to start.
Microsoft.ServiceBus: It is not possible for an entity that requires
sessions to create a non-sessionful message receiver
So my question is am I not able to use function with queue/topic with session?
Update 2020:
Set isSessionsEnabled property in your function.json.
This is a common ask, but currently Web Jobs SDK, and thus Azure Functions, don't support Service Bus sessions. See WebJobs SDK issue; unfortunately there's no progress 3 years after it was created. Add a +1 in Azure Functions issue.
I think its actually possible now, using the beta package Microsoft.Azure.WebJobs.Extensions.ServiceBus/3.1.0-beta2.
public static void Run([ServiceBusTrigger("core-test-queue1-sessions",
Connection = "AzureWebJobsServiceBus",
IsSessionsEnabled = true)]string myQueueItem,
IMessageSession messageSession,
ILogger log)
Also you can specify new SessionHandlerOptions section in host.json:
{
"version": "2.0",
"extensions": {
"serviceBus": {
"SessionHandlerOptions":
{
"MaxAutoRenewDuration": "00:01:00",
"MessageWaitTimeout": "00:05:00",
"MaxConcurrentSessions": 16,
"AutoComplete": true,
}
}
}
}
https://github.com/azure/azure-webjobs-sdk/issues/529#issuecomment-491113458
You need to specify in function.json of consumer AF a property "IsSessionsEnabled": true
Related
I have a queue in a service bus. After putting a message into a queue an azure logic app and an azure functions should betriggered and process the content.
My Azure logic app is triggered but my azure funcction is not triggered. My code for azure function:
[FunctionName("ReadMEssageFromQueue")]
public static void Run([ServiceBusTrigger("messagequeue", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}
host json:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobsStorage": "******" // connection string of my service bus
}
}
should I set something in service bus queue to send message to both ressources?
Azure Service Bus Queue messages are picked up by only one processor. So I think in your case, the logic app is picking up and consuming the message first and the message is not available for the function to process. You can try temporarily disabling the logic app and letting function pick the message to confirm this.
Ref: azure-service-bus-queue-with-multiple-listeners
You can trigger the Azure function from your logic app (not sure if it'll help your use case), or you can use Azure Service Bus topics as topics support the model where multiple consumers can subscribe to a topic.
The former option might be a better approach for you from cost perspective, as you'd need to use Standard tier of service bus in order to use topics feature, which means additional cost for you over your current setup.
Also, you might want to use some other name for service bus connection string as AzureWebJobsStorage is used for storage account connection string
I am trying to get the Azure function to trigger when a blob file is uploaded. The function was deployed from an azure DevOps release.
Azure deploy steps (shows most relevant information):
Storage account:
- has a folder [blob folder] where I upload files to.
Azure function code:
public async static Task Run([BlobTrigger("[blob folder]/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, ILogger log)
{
// any breakpoint here is never hit.
}
function.json:
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.24",
"configurationSource": "attributes",
"bindings": [
{
"type": "blobTrigger",
"connection": "AzureWebJobsStorage",
"path": "[blob folder]/{name}",
"name": "myBlob"
}
],
"disabled": false,
"scriptFile": "../bin/[dllname].dll",
"entryPoint": "[namespace].[function].[command]"
}
The storage and function are part of the same resource group. The Function app settings contains the values AzureWebJobsDashboard and AzureWebJobsStorage. I read these should be available in the function settings in this post. I also turned off the Function setting "Always On" for the function, and made sure the function is running.
Running and debugging the function locally (with the Azure storage emulator and storage explorer) works fine. The function is triggered after I upload a file to the blob folder.
In Azure, it seems like nothing happens. I'm not super familiar with the Azure environment, so any help is appreciated.
The issue was caused by the FUNCTIONS_EXTENSION_VERSION setting in the application settings. I needed to update this setting to the correct version.
I managed to get the debugging running using Jason Robert's blog post and debug the trigger event of my function.
I have an Azure Service Bus with Service Bus Topic trigger. My function looks something like this
[FunctionName("SbListener")]
public static async Task Run(
[ServiceBusTrigger("test-topic", "test-sub-1", Connection = "ServiceBus")]string message,
[Inject("Microsoft.EventStore.Functions", true)] IWebNotificationManagerFactory webNotificationManagerFactory,
[Inject("Microsoft.EventStore.Functions", true)] ILogger logger)
{ ... }
The configuration for my Service Bus is in the local.settings.json file.
"ConnectionStrings": {
"ServiceBus": "Endpoint=sb://<my-sb>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<my-key>"
}
What I am looking for is that I want to refer the topic names from the configuration file as well, rather than hard-coding them in the ServiceBusTrigger. The problem is that in case I change the subscription name then I would have to re-deploy Function code (I want to avoid this at all cost).
Put topic and subscription in Values in local.settings.json(Application settings in portal) and reference them using app setting binding expressions--wrap the app setting name with %, check the doc.
[ServiceBusTrigger("%Topic%", "%Subscription%", Connection = "ServiceBus")]string message
Besides, I would suggest you put ServiceBus connection string in Values as well, ConnectionStrings is used by frameworks that typically get connection strings from the ConnectionStrings section of a configuration file, such as Entity Framework. See the doc.
If I have another Azure Function creating documents, based on some other event (e.g. API call).
Is there support (or will there be) to have an Azure Function run based on a new document being created?
using System;
public static void Run(object doc, TraceWriter log)
{
log.Info($"doc based trigger? ... {doc}");
}
Binding I tried to use, i tried it with and wihout the "id" property, and type documentDB and documentDBTrigger :
"bindings": [
{
"type": "documentDB",
"name": "doc",
"databaseName": "MyDb",
"collectionName": "MyCollection",
"connection": "mydb_DOCUMENTDB",
"direction": "in"
}
No, we don't currently have a DocumentDB trigger binding. Only input and output bindings.
The underlying DocumentDB support for Azure Functions lives in the azure-webjobs-sdk-extensions repo. Feel free to leave an issue in that repo for this feature request :)
I think you're searching for this: https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-documentdb/
Another option: you can create a DocumentDB trigger that will put a message into a service bus Queue, and then, use a Service Bus binding for your Azure Function:
https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-service-bus/
The new azure function preview contains a few templates for C#. But there is no service bus queue template for C#. There is a trigger template for node with service bus. But on close inspection, it only supported Notification Hubs and not service bus queue. Is it even possible to write an azure function that can only be triggered when an item appears in azure service bus queue? If it is not possible now, will there be such a template in the near future?
Thanks.
Raghu/..
Update: The below steps and information still hold, however we now have a "ServiceBusQueueTrigger - C#" template live in the portal, so the workaround steps are no longer necessary :)
ServiceBus IS supported already for C#, we just need to add a template for it (we'll add very soon). In general, templates are just starting points - you can always modify templates by adding additional bindings, or start from the empty template and build up your own Function.
Until we get the template uploaded, you can get this working yourself by starting from the C# Empty template. For example, you can enter binding info like the following in the Advanced Editor on the Integrate tab:
{
"bindings": [
{
"type": "serviceBusTrigger",
"name": "message",
"direction": "in",
"queueName": "samples-input",
"connection": "myServiceBus"
}
]
}
Make sure your Function App has an AppSetting matching the name of the connection property, containing your ServiceBus connection string. It looks like we currently have some issues with the connection string picker for ServiceBus (which will also be fixed very soon), but you can use "Function app settings"/"Go to App Service Settings"/"Application Settings" to add this app setting. Then you can use the corresponding Function code:
using System;
using Microsoft.Azure.WebJobs.Host;
public static void Run(string message, TraceWriter log)
{
log.Verbose($"C# ServiceBus Queue function processed message: {message}");
}
This function will then be invoked whenever new messages are added to ServiceBus queue samples-input.
Per https://azure.microsoft.com/en-us/documentation/articles/functions-reference/, there is no binding with the SB.
The best way to do that instead of doing something that is (at least by some chance) being in work in product group is to submit your idea on the UserVoice - https://feedback.azure.com/forums/355860-azure-functions .