is it possible to have from QueueTrigger function response as controller? When I call a get method from controller response body could be something like
{
"error": {
"message": "The resource does not exist",
...
Is there a way to do similar response from the function? I found only output binding where it can return string to another queue, but this is not what I am looking for:
[FunctionName("QueueOutput")]
[return: Queue("myqueue-items")]
public static string Run([HttpTrigger] dynamic input, ILogger log)
{
...
}
If I do this:
[FunctionName("QueueOutput")]
public static Task<string> Run([HttpTrigger] dynamic input, ILogger log)
{
...
return "...";
}
I have following error:
The 'CleanDataFunction' function is in error:
Microsoft.Azure.WebJobs.Host: Error indexing method 'CleanDataFunction'.
Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type
String&. Make sure the parameter Type is supported by the binding. If
you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers,
etc.) make sure you've called the registration method for the extension(s)
in your startup code (e.g. builder.AddAzureStorage(),
builder.AddServiceBus(), builder.AddTimers(), etc.).
Probably it is not possible. Found answer here:
Azure Function doesn't work with QueueTrigger and non-void return value?
You could simply create the json you need, either manually as a string or using JSON.NET, and return it serialized.
Related
Currently i have scenario where i need to unit test a Service Bus Trigger Function. Fa code as below
public async Task Run([ServiceBusTrigger("sample", Connection = "sample", IsSessionsEnabled = false)] Message message, IMessageReceiver messageReceiver, ILogger _log)
{
//Some code
}
I was primarily using MessageReceiver, but it's hard to unit test as it's not much flexible to Mock,so i switched to IMessageReceiver. Getting below Error
Microsoft.Azure.WebJobs.Host: Can't bind parameter 'messageReceiver' to type 'Microsoft.Azure.ServiceBus.Core.IMessageReceiver'.
NB:- It have a Weird issue that the variable name should be messageReceiver, while using MessageReceiver .
Is there anything that i need to follow for IMessageReceiver as well?
As of today, IMessageReceiver is not supported via dependency injection. You can only get MessageReceiver. You can upvote the request to add the support here.
Meanwhile, there's a workaround that you could use, showed here. The workaround is to have an additional, internal method, accepting IMessageReceiver and Function call that is injected MessageReceiver to pass the parameter to the internal method.
I have a problem with passing class object as an input parameter to azure function, what is the proper way of doing it? I have function like posted below.
public async Task<IActionResult> GetClinics(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "clinics")] HttpRequest req, ILogger log, PersonDocument thePerson)
{
//do something
}
Error that i got:
The 'GetClinics' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'GetClinics'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'thePerson' to type PersonDocument. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
what is the simplest way to solve it? Do i have to prepare my own custom binding? PersonDocument is just a class with some properties that i would like to extract from body. The only information that i found show how to add custom binding with custom attribute, but I am curious if it is really required to add them to solve such an easy problem?
Method signatures developed by the azure function C # class library can only include these:
ILogger or TraceWriter for logging (v1 version only)
A CancellationToken parameter for graceful shutdown
Mark input and output bindings by using attribute decoration
Binding expressions parameters to get trigger metadata
For your question, what you need seems a input binding, so have a look of this doc:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#supported-bindings
You can see that only a few input bindings is support by azure function by default. So I think if you want to achieve what you want, custom binding is needed.
I'm trying to bind to MessageReceiver in an Azure Service Bus Triggered Function.
My goal is to handle dead letter queue messages and complete them.
public static class Function1
{
[FunctionName("Function1")]
public static async Task Run(
[ServiceBusTrigger(
"<topicName>",
"<subscriptionName>/$DeadLetterQueue",
Connection = "connectionstring")]
Message message,
ILogger logger,
MessageReceiver messageReceiver)
{
// TODO: Perform some actions
await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
}
The problem is that it fails to bind to the MessageReceiver class.
Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'receiver' to type MessageReceiver. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
Any ideas why the binding fails?
I figured out what was wrong. I was using 'receiver' as parameter name for MessageReceiver. It turned out that the parameter name has to be 'messageReceiver'. The example I was looking at first used 'receiver', so is this maybe something that has changed?
I am trying to use the new Durable Functions extension in Azure Functions I installed this Nuget package on my Function project:
Microsoft.Azure.WebJobs.Extensions.DurableTask
And then used the DurableOrchestrationContext in my function like that:
[FunctionName("StopVM")]
public static void StopVM([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, ILogger log, ExecutionContext context, DurableOrchestrationContext orchestrationContext)
{
....
}
but when i run the function this error shown:
Error indexing method 'FuncApp.StopVM' [20/11/2018
17:09:01] Microsoft.Azure.WebJobs.Host: Error indexing method
'FuncApp.StopVM'. Microsoft.Azure.WebJobs.Host: Cannot
bind parameter 'orchestrationContext' to type
DurableOrchestrationContext. Make sure the parameter Type is supported
by the binding. If you're using binding extensions (e.g. Azure
Storage, ServiceBus, Timers, etc.) make sure you've called the
registration method for the extension(s) in your startup code (e.g.
builder.AddAzureStorage(), builder.AddServiceBus(),
builder.AddTimers(), etc.).
Do i missing some steps like adding any middle-ware to startup class or etc. cause the documentation not shown clearly how to use it?
I got it. You should wrap your parameter of type DurableOrchestrationClient with this attribute[OrchestrationClient] if you want it to start the Orchestration itself or wrap the parameter of type DurableOrchestrationContext with this attribute [OrchestrationTrigger] to use the context and here there are more details (link)
I've made a bot using BotFramework, and I want to have an azure function triggered every 5 minutes (for example). And when it's triggered my bot must be notified.
But I have no idea how to do this, I read this https://docs.botframework.com/en-us/azure-bot-service/templates/proactive/ but the thing is he didn't use a Timmer Trigger Azure Function but a Queue Trigger.
I tryed to do something like that :
using System;
using System.Net;
using System.Net.Http;
using Microsoft.Azure.WebJobs.Host;
public class BotMessage
{
public string Source { get; set; }
public string Message { get; set; }
}
public static HttpResponseMessage Run(TimerInfo myTimer,out BotMessage message ,TraceWriter log)
{
message = new BotMessage()
{
Source = "AzureFunction",
Message = "Testing"
};
return new HttpResponseMessage(HttpStatusCode.OK);
}
but i have this error :
2017-03-02T14:49:40.460 Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.TimerTriggerCSharp1'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'message' to type BotMessage&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
Plus, to indicate which bot has to be notified where the event is triggered is added a output with the direct line key :
but as u can see there is the same error than above ...
Does someone have some docs or example for that.
Thank you for reading me.
Your binding configuration is set to use the return value of your function (also, in this case, that doesn't match any of the types supported by the binding)
You have a couple of options:
Uncheck the box to use the return value of of your function and name the parameter message
Or
Change the return type of your function to BotMessage return the message instance from your Run method and remove the out BotMessage message parameter.
Either option should fix this problem.