You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/logic-apps/logic-apps-scenario-function-sb-trigger.md
+29-27Lines changed: 29 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,46 +1,48 @@
1
1
---
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.
4
4
services: logic-apps
5
5
ms.suite: integration
6
6
ms.reviewer: estfan, azla
7
7
ms.topic: how-to
8
-
ms.date: 11/08/2019
8
+
ms.date: 10/31/2022
9
9
ms.custom: devx-track-csharp
10
10
#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.
11
11
---
12
12
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
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.
18
20
19
21
## Prerequisites
20
22
21
23
* 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).
22
24
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).
24
26
25
27
* 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.
26
28
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).
28
30
29
31
## Create a logic app workflow
30
32
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.
32
34
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.
34
36
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).
36
38
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.
38
40
39
41
:::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.":::
40
42
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.
42
44
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.
44
46
45
47
:::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.":::
46
48
@@ -52,7 +54,7 @@ For this scenario, you have a function running for each logic app that you want
52
54
53
55
:::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.":::
54
56
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:
56
58
57
59
```json
58
60
{
@@ -86,7 +88,7 @@ For this scenario, you have a function running for each logic app that you want
86
88
87
89
For example, you can send an email with the Office 365 Outlook connector.
88
90
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.
90
92
91
93
The callback URL appears in the **HTTP POST URL** property.
92
94
@@ -96,38 +98,38 @@ For this scenario, you have a function running for each logic app that you want
96
98
97
99
Next, create the function that acts as the trigger and listens to the queue.
98
100
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.
100
102
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**.
102
104
103
105
:::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.":::
104
106
105
107
1. Select the **Azure Service Bus Queue trigger** template.
106
108
107
109
:::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.":::
108
110
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**.
110
112
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:
112
114
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.
114
116
115
117
* 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).
116
118
117
119
* If possible, reuse the instance of HTTP clients. For more information, see [Manage connections in Azure Functions](../azure-functions/manage-connections.md).
118
120
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/).
120
122
121
123
```csharp
122
124
usingSystem;
123
125
usingSystem.Threading.Tasks;
124
126
usingSystem.Net.Http;
125
127
usingSystem.Text;
126
128
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.
@@ -139,7 +141,7 @@ Next, create the function that acts as the trigger and listens to the queue.
139
141
140
142
## Test your logic app workflow
141
143
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.
143
145
144
146
1. In the Azure portal, open your Service Bus namespace.
145
147
@@ -151,10 +153,10 @@ Next, create the function that acts as the trigger and listens to the queue.
151
153
152
154
1. On the queue navigation menu, select **Service Bus Explorer**, and then select **Send messages**.
153
155
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.":::
155
157
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.
157
159
158
160
## Next steps
159
161
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