2

I want to build an Azure Function that responds to HTTP POST requests coming from another Azure function i.e. MasterFunction calling NotificationsFunction.

Say, I have the following simple POCO object:

public class Car
{
   public string Make { get; set; }
   public string Model { get; set; }
   public int Year { get; set; }
   public int Mileage { get; set; }
}

Both functions will be sharing the same class library containing these POCO objects.

Am I right to assume that in the MasterFunction, I'll have to serialize my Car object to JSON, then make an HTTP call?

Could someone point me to some code samples on a similar scenario?

Janusz Nowak
  • 2,595
  • 1
  • 17
  • 36
Sam
  • 26,817
  • 58
  • 206
  • 383
  • 4
    Possible duplicate of [How to call another function with in an Azure function](https://stackoverflow.com/questions/46315734/how-to-call-another-function-with-in-an-azure-function) – Mikhail Shilkov Oct 01 '17 at 19:10

2 Answers2

3

If both of your functions are in the same azure function app (which I think that's the case), I'd say the best way of calling other functions is using Queues.

In the sense that you put your POCO into a queue and define your second function with a QueueTrigger. So once an object gets into the queue, the other function gets called automatically and the object get dequeued.

You can find samples and more details in here : https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue

akardon
  • 43,164
  • 4
  • 34
  • 42
  • why use Azure Queue when you could make a direct HTTP request to the other function public URL? – Artemious Feb 19 '18 at 22:01
  • 2
    cuz it's the recommended way of doing that by MS. And there is some build in fault tolerance mechanism for it. For instance what if the second function throws exceptions, then with the queue mechanism, it would retry automatically and after a few failures, puts them in a separate queue (called poison queue) so that you can retry later on. There is also another mechanism to load balance and parallelize the function execution per queue item. – akardon Feb 20 '18 at 06:02
  • Generally speaking, I'd say if you wanna call the other function in like a fire and forget manner, then queue is the best option, but if you need to wait for the function to get the result, it's not a good thing to do. – akardon Feb 20 '18 at 06:03
  • yes, I'm interested in the fire-and-forget scenario. ok, I understand that Queues have this fault tolerance mechanism. But what if I don't need to retry? Just log the exception and forget it. I would have to implement the poison-queue handling logic, right? – Artemious Feb 20 '18 at 12:45
  • And what do you mean by "another mechanism to load balance and parallelize the function execution per queue item"? Don't the http requests run in parallel? each request in its own thread. I don't get the point – Artemious Feb 20 '18 at 12:47
  • 1
    you can set the poison queue parameters (retry count,...) through the function.json settings, but the simplest way of avoiding auto retries is to not throw from the second function (swallowing the exception and just logging the error in the function) By other mechanisms, I mean the way that it deals with the Queue triggers. Once you got 1000 items in the queue it, picks up 16 items at a time and triggers the functions (this number could be set), so it's trying to balance the load on the second function, you can also set auto scale rules to scale out the app based on the queue length . – akardon Feb 21 '18 at 01:18
  • 1
    But if you don't need those stuff and the HttpTrigger suits you better go for it. – akardon Feb 21 '18 at 01:18
0

If I understand correctly you want service communication between services/endpoints. You can use Orchestration or choreography for service communication. orchestration in azure using 1. Durable function 2. Logic app Choreography in azure using 1. Storage queue 2. Service Bus.

Hope it will help

Pankaj Rawat
  • 4,037
  • 6
  • 41
  • 73