Skip to content

Commit 05b2c39

Browse files
Merge pull request #95482 from ecfan/patch-3
Updates per PM feedback + UX updates
2 parents f7f28a0 + 29919b5 commit 05b2c39

16 files changed

+37
-30
lines changed
15.3 KB
Loading

articles/logic-apps/logic-apps-azure-functions.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Before you can create an Azure function starting from inside your logic app by u
109109

110110
* Between existing steps in your logic app's workflow, move your mouse over the arrow, select the plus (+) sign, and then select **Add an action**.
111111

112-
1. In the search box, enter "azure functions" as your filter. From the actions list, select this action: **Choose an Azure function**
112+
1. In the search box, enter "azure functions" as your filter. From the actions list, select the **Choose an Azure function** action, for example:
113113

114114
![Find "Azure functions"](./media/logic-apps-azure-functions/find-azure-functions-action.png)
115115

@@ -121,26 +121,26 @@ Before you can create an Azure function starting from inside your logic app by u
121121

122122
1. In the **Function name** box, provide a name for your function.
123123

124-
1. In the **Code** box, add your code to the function template, including the response and payload that you want returned to your logic app after your function finishes running.
124+
1. In the **Code** box, add your code to the function template, including the response and payload that you want returned to your logic app after your function finishes running. When you're done, select **Create**.
125125

126-
![Define your function](./media/logic-apps-azure-functions/function-definition.png)
126+
For example:
127127

128-
In the template's code, the *`context` object* refers to the message that your logic app sends through the **Request Body** field in a later step. To access the `context` object's properties from inside your function, use this syntax:
128+
![Define your function](./media/logic-apps-azure-functions/add-code-function-definition.png)
129129

130-
`context.body.<property-name>`
130+
In the template's code, the *`context` object* refers to the message that your logic app sends through the **Request Body** field in a later step. To access the `context` object's properties from inside your function, use this syntax:
131131

132-
For example, to reference the `content` property inside the `context` object, use this syntax:
132+
`context.body.<property-name>`
133133

134-
`context.body.content`
134+
For example, to reference the `content` property inside the `context` object, use this syntax:
135135

136-
The template code also includes an `input` variable, which stores the value from the `data` parameter so your function can perform operations on that value. Inside JavaScript functions, the `data` variable is also a shortcut for `context.body`.
136+
`context.body.content`
137137

138-
> [!NOTE]
139-
> The `body` property here applies to the `context` object and
140-
> isn't the same as the **Body** token from an action's output,
141-
> which you might also pass to your function.
138+
The template code also includes an `input` variable, which stores the value from the `data` parameter so your function can perform operations on that value. Inside JavaScript functions, the `data` variable is also a shortcut for `context.body`.
142139

143-
1. When you're done, select **Create**.
140+
> [!NOTE]
141+
> The `body` property here applies to the `context` object and
142+
> isn't the same as the **Body** token from an action's output,
143+
> which you might also pass to your function.
144144
145145
1. In the **Request Body** box, provide your function's input, which must be formatted as a JavaScript Object Notation (JSON) object.
146146

@@ -164,7 +164,7 @@ To call existing Azure functions from your logic apps, you can add Azure functio
164164

165165
1. Under the step where you want to add the function, select **New step**.
166166

167-
1. Under **Choose an action**, in the search box, enter "azure functions" as your filter. From the actions list, select this action: **Choose an Azure function**
167+
1. Under **Choose an action**, in the search box, enter "azure functions" as your filter. From the actions list, select the **Choose an Azure function** action.
168168

169169
![Find "Azure functions"](./media/logic-apps-azure-functions/find-azure-functions-action.png)
170170

articles/logic-apps/logic-apps-scenario-function-sb-trigger.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: ecfan
88
ms.author: estfan
99
ms.reviewer: jehollan, klam, LADocs
1010
ms.topic: article
11-
ms.date: 06/04/2019
11+
ms.date: 11/08/2019
1212
---
1313

1414
# Call or trigger logic apps by using Azure Functions and Azure Service Bus
@@ -27,13 +27,13 @@ You can use [Azure Functions](../azure-functions/functions-overview.md) to trigg
2727

2828
## Create logic app
2929

30-
For this scenario, you have a function running each logic app that you want to trigger. First, create a logic app that starts with an HTTP request trigger. The function calls that endpoint whenever a queue message is received.
30+
For this scenario, you have a function running each logic app that you want to trigger. First, create a logic app that starts with an HTTP request trigger. The function calls that endpoint whenever a queue message is received.
3131

3232
1. Sign in to the [Azure portal](https://portal.azure.com), and create blank logic app.
3333

3434
If you're new to logic apps, review [Quickstart: Create your first logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md).
3535

36-
1. In the search box, enter "http request". From the triggers list, select this trigger: **When a HTTP request is received**
36+
1. In the search box, enter `http request`. From the triggers list, select the **When a HTTP request is received** trigger.
3737

3838
![Select trigger](./media/logic-apps-scenario-function-sb-trigger/when-http-request-received-trigger.png)
3939

@@ -45,9 +45,9 @@ For this scenario, you have a function running each logic app that you want to t
4545

4646
If you don't have a schema, but you have a sample payload in JSON format, you can generate a schema from that payload.
4747

48-
1. In the Request trigger, choose **Use sample payload to generate schema**.
48+
1. In the Request trigger, select **Use sample payload to generate schema**.
4949

50-
1. Under **Enter or paste a sample JSON payload**, enter your sample payload, and then choose **Done**.
50+
1. Under **Enter or paste a sample JSON payload**, enter your sample payload, and then select **Done**.
5151

5252
![Enter sample payload](./media/logic-apps-scenario-function-sb-trigger/enter-sample-payload.png)
5353

@@ -97,9 +97,9 @@ Next, create the function that acts as the trigger and listens to the queue.
9797

9898
1. In the Azure portal, open and expand your function app, if not already open.
9999

100-
1. Under your function app name, expand **Functions**. On the **Functions** pane, choose **New function**.
100+
1. Under your function app name, expand **Functions**. On the **Functions** pane, select **New function**.
101101

102-
![Expand "Functions" and choose "New function"](./media/logic-apps-scenario-function-sb-trigger/create-new-function.png)
102+
![Expand "Functions" and select "New function"](./media/logic-apps-scenario-function-sb-trigger/add-new-function-to-function-app.png)
103103

104104
1. Select this template based on whether you created a new function app where you selected .NET as the runtime stack, or you're using an existing function app.
105105

@@ -111,27 +111,34 @@ Next, create the function that acts as the trigger and listens to the queue.
111111

112112
![Select template for existing function app](./media/logic-apps-scenario-function-sb-trigger/legacy-add-queue-trigger-template.png)
113113

114-
1. On the **Azure Service Bus Queue trigger** pane, provide a name for your trigger, and set up the **Service Bus connection** for the queue, which uses the Azure Service Bus SDK `OnMessageReceive()` listener, and choose **Create**.
114+
1. On the **Azure Service Bus Queue trigger** pane, provide a name for your trigger, and set up the **Service Bus connection** for the queue, which uses the Azure Service Bus SDK `OnMessageReceive()` listener, and select **Create**.
115115

116-
1. Write a basic function to call the previously created logic app endpoint by using the queue message as a trigger. This example uses the `application/json` message content type, but you can change this type as necessary. If possible, reuse the instance of HTTP clients. For more information, see [Manage connections in Azure Functions](../azure-functions/manage-connections.md).
116+
1. Write a basic function to call the previously created logic app endpoint by using the queue message as a trigger. Before you write your function, review these considerations:
117+
118+
* This example uses the `application/json` message content type, but you can change this type as necessary.
119+
120+
* Due to possible concurrently running functions, high volumes, or heavy loads, avoid instantiating the [HTTPClient class](https://docs.microsoft.com/dotnet/api/system.net.http.httpclient) with the `using` statement and directly creating HTTPClient instances per request. For more information, see [Use HttpClientFactory to implement resilient HTTP requests](https://docs.microsoft.com/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net-core).
121+
122+
* If possible, reuse the instance of HTTP clients. For more information, see [Manage connections in Azure Functions](../azure-functions/manage-connections.md).
123+
124+
This example uses the [`Task.Run` method](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task.run) in [asynchronous](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/async) mode. For more information, see [Asynchronous programming with async and await](https://docs.microsoft.com/dotnet/csharp/programming-guide/concepts/async/).
117125

118126
```CSharp
119127
using System;
120128
using System.Threading.Tasks;
121129
using System.Net.Http;
122130
using System.Text;
123131

124-
// Callback URL for previously created Request trigger
132+
// Can also fetch from App Settings or environment variable
125133
private static string logicAppUri = @"https://prod-05.westus.logic.azure.com:443/workflows/<remaining-callback-URL>";
126134

127-
// Reuse the instance of HTTP clients if possible
135+
// Reuse the instance of HTTP clients if possible: https://docs.microsoft.com/azure/azure-functions/manage-connections
128136
private static HttpClient httpClient = new HttpClient();
129137

130-
public static void Run(string myQueueItem, ILogger log)
138+
public static async Task Run(string myQueueItem, TraceWriter log)
131139
{
132-
log.LogInformation($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
133-
134-
var response = httpClient.PostAsync(logicAppUri, new StringContent(myQueueItem, Encoding.UTF8, "application/json")).Result;
140+
log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
141+
var response = await httpClient.PostAsync(logicAppUri, new StringContent(myQueueItem, Encoding.UTF8, "application/json"));
135142
}
136143
```
137144

@@ -141,4 +148,4 @@ Next, create the function that acts as the trigger and listens to the queue.
141148

142149
## Next steps
143150

144-
[Call, trigger, or nest workflows by using HTTP endpoints](../logic-apps/logic-apps-http-endpoint.md)
151+
* [Call, trigger, or nest workflows by using HTTP endpoints](../logic-apps/logic-apps-http-endpoint.md)
20.6 KB
Loading
11.9 KB
Loading
Binary file not shown.
3.31 KB
Loading
8.2 KB
Loading
11 KB
Loading
1.15 KB
Loading

0 commit comments

Comments
 (0)