Skip to content

Commit d21cd5a

Browse files
committed
Edit content
1 parent dac0d9e commit d21cd5a

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

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

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
---
2-
title: Call logic apps with Azure Functions
3-
description: Call or trigger logic apps by using Azure Functions and Azure Service Bus.
2+
title: Call logic app workflows with Azure Functions
3+
description: Trigger a logic app workflow whenever an Azure Service Bus message arrives in a queue by using Azure Functions to call an endpoint on the logic app workflow.
44
services: logic-apps
55
ms.suite: integration
66
ms.reviewer: estfan, azla
77
ms.topic: how-to
8-
ms.date: 11/08/2019
8+
ms.date: 10/31/2022
99
ms.custom: devx-track-csharp
1010
#Customer intent: As a logic apps developer, I want to use Azure Logic Apps to respond automatically and instantaneously to Azure Service Bus messages so that I don't have to monitor the messages manually.
1111
---
1212

13-
# Call or trigger logic apps by using Azure Functions and Azure Service Bus
13+
# Call or trigger logic app workflows by using Azure Functions and Azure Service Bus
1414

1515
[!INCLUDE [logic-apps-sku-consumption](../../includes/logic-apps-sku-consumption.md)]
1616

17-
You can use [Azure Functions](../azure-functions/functions-overview.md) to trigger a logic app workflow when you need to deploy a long-running listener or task. For example, you can create a function that listens in on an [Azure Service Bus](../service-bus-messaging/service-bus-messaging-overview.md) queue and immediately fires a logic app as a push trigger.
17+
You can use [Azure Functions](../azure-functions/functions-overview.md) to trigger a logic app workflow when you need to deploy a long-running listener or task. For example, you can create a function that listens to an [Azure Service Bus](../service-bus-messaging/service-bus-messaging-overview.md) queue and immediately fires a logic app workflow as a push trigger.
18+
19+
This how-to guide shows you how to create a logic app workflow that starts with an HTTP request trigger. You also see how to create a function that listens to a message queue and calls the logic app endpoint whenever a queue message arrives.
1820

1921
## Prerequisites
2022

2123
* An Azure account and subscription. If you don't have a subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
2224

23-
* An Azure Service Bus namespace. If you don't have a namespace, [create your namespace first](../service-bus-messaging/service-bus-create-namespace-portal.md).
25+
* A Service Bus namespace. If you don't have a namespace, [create your namespace first](../service-bus-messaging/service-bus-create-namespace-portal.md).
2426

2527
* A function app, which is a container for your functions. If you don't have a function app, [create your function app first](../azure-functions/functions-get-started.md), and make sure that you select .NET as the runtime stack.
2628

27-
* Basic knowledge about [how to create a Consumption logic app workflow](quickstart-create-first-logic-app-workflow.md) or [how to create a Standard logic app workflow](create-single-tenant-workflows-azure-portal.md).
29+
* Basic knowledge about [how to create a Consumption logic app workflow](quickstart-create-first-logic-app-workflow.md).
2830

2931
## Create a logic app workflow
3032

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

33-
1. Sign in to the [Azure portal](https://portal.azure.com), and create blank logic app.
35+
1. Sign in to the [Azure portal](https://portal.azure.com), and create a blank logic app workflow.
3436

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

37-
1. In the search box, enter `http request`. From the triggers list, select the **When a HTTP request is received** trigger.
39+
1. In the search box, enter **http request**. From the triggers list, select the **When a HTTP request is received** trigger.
3840

3941
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/when-http-request-received-trigger.png" alt-text="Screenshot of the designer in the portal. The search box contains 'http request.' Under 'Triggers,' 'When a HTTP request is received' is highlighted.":::
4042

41-
With the Request trigger, you can optionally enter a JSON schema to use with the queue message. JSON schemas help the Logic App Designer understand the structure for the input data, and make the outputs easier for you to use in your workflow.
43+
With the Request trigger, you can optionally enter a JSON schema to use with the queue message. JSON schemas help the designer understand the structure for the input data, and make the outputs easier for you to use in your workflow.
4244

43-
1. To specify a schema, enter the schema in the **Request Body JSON Schema** box, for example:
45+
1. To specify a schema, enter the schema in the **Request Body JSON Schema** box.
4446

4547
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/when-http-request-received-trigger-schema.png" alt-text="Screenshot of the details of an HTTP request trigger. Some JSON code is visible in the 'Request Body JSON Schema' box.":::
4648

@@ -52,7 +54,7 @@ For this scenario, you have a function running for each logic app that you want
5254

5355
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/enter-sample-payload.png" alt-text="Screenshot of the details of an HTTP request trigger. Under 'Enter or paste a sample JSON payload,' some payload data is visible.":::
5456

55-
This sample payload generates this schema that appears in the trigger:
57+
The sample payload that's pictured earlier generates the following schema, which appears in the trigger:
5658

5759
```json
5860
{
@@ -86,7 +88,7 @@ For this scenario, you have a function running for each logic app that you want
8688

8789
For example, you can send an email with the Office 365 Outlook connector.
8890

89-
1. Save your logic app, which generates the callback URL for the trigger in this logic app. Later, you use this callback URL in the code for the Azure Service Bus Queue trigger.
91+
1. Save your logic app workflow. This action generates the callback URL for the trigger in your logic app workflow. Later, you use this callback URL in the code for the Azure Service Bus Queue trigger.
9092

9193
The callback URL appears in the **HTTP POST URL** property.
9294

@@ -96,38 +98,38 @@ For this scenario, you have a function running for each logic app that you want
9698

9799
Next, create the function that acts as the trigger and listens to the queue.
98100

99-
1. In the Azure portal, open and expand your function app, if not already open.
101+
1. In the Azure portal, go to your function app.
100102

101-
1. Under your function app name, expand **Functions**. On the **Functions** pane, select **New function**.
103+
1. On the function app navigation menu, select **Functions**. On the **Functions** pane, select **Create**.
102104

103105
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/add-new-function-to-function-app.png" alt-text="Screenshot of the 'Functions' page of a function app in the portal, with 'Create' highlighted. On the navigation menu, 'Functions' is highlighted.":::
104106

105107
1. Select the **Azure Service Bus Queue trigger** template.
106108

107109
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/current-add-queue-trigger-template.png" alt-text="Screenshot of the 'Create function' page of a function app in the portal. Under 'Template,' 'Azure Service Bus Queue trigger' is highlighted.":::
108110

109-
1. Under **Template details**, enter a name for your function, and set up the **Service Bus connection** for the queue, which uses the Azure Service Bus SDK `OnMessageReceive()` listener. Next, enter the queue name, and then select **Create**.
111+
1. Under **Template details**, enter a name for your function, and set up the **Service Bus connection** for the queue, which uses the Service Bus SDK `OnMessageReceive()` listener. Next, enter the queue name, and then select **Create**.
110112

111-
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:
113+
1. Write a basic function to call the logic app endpoint that you created earlier. Use the queue message to trigger the function. Before you write your function, review the following considerations:
112114

113-
* This example uses the `application/json` message content type, but you can change this type as necessary.
115+
* The following example uses the `application/json` message content type, but you can change this type as necessary.
114116

115117
* Due to possible concurrently running functions, high volumes, or heavy loads, avoid instantiating the [HTTPClient class](/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](/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net-core).
116118

117119
* If possible, reuse the instance of HTTP clients. For more information, see [Manage connections in Azure Functions](../azure-functions/manage-connections.md).
118120

119-
This example uses the [`Task.Run` method](/dotnet/api/system.threading.tasks.task.run) in [asynchronous](/dotnet/csharp/language-reference/keywords/async) mode. For more information, see [Asynchronous programming with async and await](/dotnet/csharp/programming-guide/concepts/async/).
121+
The following example uses the [`Task.Run` method](/dotnet/api/system.threading.tasks.task.run) in [asynchronous](/dotnet/csharp/language-reference/keywords/async) mode. For more information, see [Asynchronous programming with async and await](/dotnet/csharp/programming-guide/concepts/async/).
120122

121123
```csharp
122124
using System;
123125
using System.Threading.Tasks;
124126
using System.Net.Http;
125127
using System.Text;
126128

127-
// Can also fetch from App Settings or environment variable
129+
// Set up the logic app workflow URI. You can also get it from App Settings or an environment variable.
128130
private static string logicAppUri = @"https://prod-05.westus.logic.azure.com:443/workflows/<remaining-callback-URL>";
129131

130-
// Reuse the instance of HTTP clients if possible: https://learn.microsoft.com/azure/azure-functions/manage-connections
132+
// Reuse the instance of HTTP clients if possible. For more information, see https://learn.microsoft.com/azure/azure-functions/manage-connections.
131133
private static HttpClient httpClient = new HttpClient();
132134

133135
public static async Task Run(string myQueueItem, TraceWriter log)
@@ -139,7 +141,7 @@ Next, create the function that acts as the trigger and listens to the queue.
139141

140142
## Test your logic app workflow
141143

142-
1. To test your logic app workflow, use a tool to add a message to your Service Bus queue.
144+
To test your logic app workflow, use a tool to add a message to your Service Bus queue.
143145

144146
1. In the Azure portal, open your Service Bus namespace.
145147

@@ -151,10 +153,10 @@ Next, create the function that acts as the trigger and listens to the queue.
151153

152154
1. On the queue navigation menu, select **Service Bus Explorer**, and then select **Send messages**.
153155

154-
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/select-service-bus-explorer.png" alt-text="Screenshot of a Service Bus queue page in the portal, with 'Send message' highlighted. On the navigation menu, 'Service Bus Explorer' is highlighted.":::
156+
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/select-service-bus-explorer.png" alt-text="Screenshot of a Service Bus queue page in the portal, with 'Send messages' highlighted. On the navigation menu, 'Service Bus Explorer' is highlighted.":::
155157

156-
1. Use the tool to send a message to your Service Bus queue. The message triggers your logic app.
158+
1. Use the tool to send a message to your Service Bus queue. The message triggers your logic app workflow.
157159

158160
## Next steps
159161

160-
* [Call, trigger, or nest workflows by using HTTP endpoints](../logic-apps/logic-apps-http-endpoint.md)
162+
* [Call, trigger, or nest workflows by using HTTP endpoints](logic-apps-http-endpoint.md)

0 commit comments

Comments
 (0)