IoTHubTrigger Azure Function does not trigger - azure

I have an Azure function with the following signature:
[FunctionName("MyFunction")]
[return: EventHub("eventhubname", Connection = "EVENTHUB_OUTPUT_CONNECTIONSTRING")]
public static string Run([IoTHubTrigger("messages/events", Connection = "IOTHUB_CONNECTIONSTRING", ConsumerGroup = "consumergroup")] EventData message, ILogger log)
I am running another Azure Functions with HTTP trigger. When i post to this function, it sends a device message to IoThub. I can see the message coming into the IoT Hub.
My routes have been setup as follows:
My routes have no special queries and i can see them hitting all the endpoints.
I have used the connectionstring from this page:
When i run in debug and when published to Azure, my function does not trigger when sending device messages. I have created 2 consumer groups and I am running 2 partitions.
Any idea what i could change to make this work?

Related

Azure function with Service Bus trigger calls the namespace with no reason

I have the following code:
[FunctionName("myFunc")]
public static void Run([ServiceBusTrigger("myQueue", Connection = "ConnectionString")]string myQueueItem, ILogger log)
{
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
}
It is published in an Azure Function App that has Managed Identity configured to a namespace. The app shows no executions (no messages have been sent to the queue/namespace):
Yet, at the same time the namespace shows it has received requests:
The namespace has no other queues and NOTHING else connects/accesses/requests the namespace and queue. Also, if the function app is stopped the requests stop, as well.
I'm trying to figure out why would the function app send requests to the namespace (and so many) when it wasn't even triggered.
At least one reason that I can think of is that it could be monitoring the queue length.
Azure Functions will auto-scale up/down based on the number of messages in the queue after all.

Way to consume bulk messages from Service Bus Queue instead of triggering it for each message

We have a Service Bus Queue; we are thinking to handle messages through Service Bus Queue Trigger in the Azure Function. But we want to consume bulk messages (in a loop) instead of re-triggering Function App for each message. What should be the way to achieve this and by using which handler. Should Azure Function be only used or we can host an App Service for consuming the same.
You should use batches. Simply declare the variable as an array.
public static class ProcessOrders
{
[FunctionName("ProcessOrders")]
public static void Run(
[ServiceBusTrigger("orders", Connection = "ServiceBusConnection")]
Message[] orders, // <-- array
ILogger log)
{
log.LogInformation($"Number of orders: {orders.Length}");
}
}
You can further configure batch size and such using the host.json file.

Not getting regular service bus messages when configuring to receive messages from deadletterqueue

this is how my azure function code looks like..
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("myqueue/$DeadLetterQueue", Connection = "ServiceBusConnection")]Message myQueueItem, ILogger log, int deliveryCount,
string messageId,
string deadLetterSource,
System.Collections.Generic.IDictionary<string, object> UserProperties
)
{}
I am able to get deadletter messages, but somehow not receiving regular messages from the service bus queue,
Is this expected behaviour?
if so how can i receive regular/deadletter messages in the same function.
I am using function 2.0 runtime.
Azure Function does not support receiving from more than a single source.
A queue and its dead-letter queue are considered two different queues.
You will need to have two Functions with some shared logic.

Azure Function Triggered by IoT Hub event - the messaging entity could not be found

When developing Azure Function thru Class Library approach (local development) I came across issue when using Even Hub compatible endpoint of IoTHub for triggering my function. This is set thru IoTHubTrigger attribute:
[FunctionName("IoTHubMessageProcessor")]
public static void Run([IoTHubTrigger("messages/events", Connection= "IoTHubReceiveEventsConnectionEndpoint")]EventData message, ILogger log)
When using provided connection string and messages/events endpoint I received error stating that "messaging entity could not be found".
Solution was to alter the connection string and include also Event Hub compatible name in connection string as an entity path so it looks like this:
Endpoint=sb://<Event hub-compatible endpoint>.servicebus.windows.net/;EntityPath=<Event Hub compatible name>;SharedAccessKeyName=<keyName>;SharedAccessKey=<key>"

How to specify a specific queue to a WebJob listener

This is one of those questions that I feel like I've solved in the past, but I don't seem to be able to atm. I have a WebJob, and I simply want to listen for a message in a queue:
public static void ProcessQueueMessage(
[QueueTrigger("myqueue")] string message,
TextWriter log)
Running it locally, it runs, but when I add a message to myqueue nothing happens. I'm pretty sure that the reason is that the queue trigger doesn't know where to look for my queue. I feel like there should be a connection string property of QueueTrigger, but there isn't.
I've tried using the connection string from the RootManageSharedAccessKey on the service bus as the AzureWebJobsStorage value (also tried dashboard), but it doesn't like either connection string. How can I point the web job at the right service bus?
QueueTrigger listens to a Storage Queue, not Service Bus queue. It's using AzureWebJobsStorage connection string by default.
If you need to process Service Bus messages, use ServiceBusTrigger attribute:
public static void ProcessQueueMessage(
[ServiceBusTrigger("myqueue")] string message,
TextWriter log)
The default connection string name is AzureWebJobsServiceBus. Otherwise you can set an alternative name of app setting for connection string via Connection property.
See docs for further explanation.

Resources