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
When you need to deploy a long-running listener or task, you can trigger your logic app workflow using Azure Functions. For example, you can create a function that listens for messages that arrive in an Azure Service Bus queue and works as a push trigger to immediately run the workflow.
17
+
When you need to deploy a long-running listener or task, you can create a logic app workflow that uses the Request trigger and Azure Functions to call that trigger and run the workflow.
18
18
19
-
This how-to guide shows how to create a logic app workflow that starts with the Request trigger. You then create a function that listens to a message queue and calls the endpoint on the logic app workflow when a message arrives in the queue. Although you can implement this behavior for Consumption and Standard logic app workflows, this example continues by using a Consumption workflow as the example.
19
+
For example, you can create a function that listens for messages that arrive in an Azure Service Bus queue. When this event happens, the function calls the Request trigger, which works as a push trigger to automatically run your workflow.
20
20
21
-
For more information, see the following documentation:
21
+
This how-to guide shows how to create a logic app workflow that starts with the Request trigger. You then create a function that listens to a Service Bus queue. When a message arrives in the queue, the function calls the endpoint created by the Request trigger to run your workflow.
22
22
23
-
-[Introduction to Azure Functions](../azure-functions/functions-overview.md)
24
-
-[What is Azure Service Bus?](../service-bus-messaging/service-bus-messaging-overview.md)
23
+
> [!NOTE]
24
+
>
25
+
> Although you can implement this behavior using either a Consumption and Standard logic app workflow,
26
+
> this example continues with a Consumption workflow.
25
27
26
28
## Prerequisites
27
29
28
30
* 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).
29
31
30
-
* A Service Bus namespace. If you don't have a namespace, [create your namespace first](../service-bus-messaging/service-bus-create-namespace-portal.md).
32
+
* A Service Bus namespace. If you don't have a namespace, [create your namespace first](../service-bus-messaging/service-bus-create-namespace-portal.md). For more information, see [What is Azure Service Bus?](../service-bus-messaging/service-bus-messaging-overview.md)
31
33
32
-
* 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.
34
+
* 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 to and make sure that you select .NET for the **Runtime stack** property.
33
35
34
36
* Basic knowledge about [how to create a Consumption logic app workflow](quickstart-create-first-logic-app-workflow.md).
35
37
36
38
## Create a logic app workflow
37
39
38
-
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 a Request trigger. The function calls that endpoint whenever a queue message is received.
39
-
40
40
1. In the [Azure portal](https://portal.azure.com), create a Consumption blank logic app by selecting the **Blank Logic App** template.
41
41
42
42
1. After the designer opens, under the designer search box, select **Built-in**. In the search box, enter **request**.
@@ -59,79 +59,87 @@ For this scenario, you have a function running for each logic app workflow that
59
59
60
60
:::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.":::
61
61
62
-
The sample payload that's pictured earlier generates the following schema, which appears in the trigger:
63
-
64
-
```json
65
-
{
66
-
"type": "object",
67
-
"properties": {
68
-
"address": {
69
-
"type": "object",
70
-
"properties": {
71
-
"number": {
72
-
"type": "integer"
73
-
},
74
-
"street": {
75
-
"type": "string"
76
-
},
77
-
"city": {
78
-
"type": "string"
79
-
},
80
-
"postalCode": {
81
-
"type": "integer"
82
-
},
83
-
"country": {
84
-
"type": "string"
62
+
The sample payload that's pictured earlier generates the following schema, which appears in the trigger:
63
+
64
+
```json
65
+
{
66
+
"type": "object",
67
+
"properties": {
68
+
"address": {
69
+
"type": "object",
70
+
"properties": {
71
+
"number": {
72
+
"type": "integer"
73
+
},
74
+
"street": {
75
+
"type": "string"
76
+
},
77
+
"city": {
78
+
"type": "string"
79
+
},
80
+
"postalCode": {
81
+
"type": "integer"
82
+
},
83
+
"country": {
84
+
"type": "string"
85
+
}
85
86
}
86
87
}
87
88
}
88
89
}
89
-
}
90
-
```
90
+
```
91
91
92
-
1.Add any other actions that you want to run after receiving the queue message.
92
+
1. Under the trigger, add any other actions that you want use to process the received message.
93
93
94
-
For example, you can send an email with the Office 365 Outlook connector.
94
+
For example, you can add an action that sends email with the Office 365 Outlook connector.
95
95
96
-
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.
96
+
1. Save your logic app workflow.
97
97
98
-
The callback URL appears in the **HTTP POST URL** property.
98
+
This step generates the callback URL for the Request trigger in your workflow. Later, you use this callback URL in the code for the Azure Service Bus Queue trigger. The callback URL appears in the **HTTP POST URL** property.
99
99
100
100
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/callback-URL-for-trigger.png" alt-text="Screenshot of the details of an HTTP request trigger. Next to 'HTTP POST URL,' a URL is visible.":::
101
101
102
102
## Create a function
103
103
104
-
Next, create the function that acts as the trigger and listens to the queue.
104
+
Next, create the function that listens to the queue and calls the endpoint on the Request trigger when a message arrives.
105
105
106
-
1. In the Azure portal, go to your function app.
106
+
1. In the [Azure portal](https://portal.azure.com), open your function app.
107
107
108
108
1. On the function app navigation menu, select **Functions**. On the **Functions** pane, select **Create**.
109
109
110
-
:::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.":::
110
+
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/add-new-function-to-function-app.png" alt-text="Screenshot of the Azure portal with a function app open, and 'Functions' is highlighted on the function app menu. The 'Functions' page is opened, and 'Create' is highlighted.":::
111
111
112
-
1. Select the **Azure Service Bus Queue trigger**template.
112
+
1. Under **Select a template**, select the template named **Azure Service Bus Queue trigger**. After the **Template details** section appears, which shows different options based on your template selection, provide the following information:
113
113
114
-
:::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.":::
114
+
| Property | Value | Description |
115
+
|----------|-------|-------------|
116
+
| **New Function** | <*function-name*> | Enter a name for your function. |
117
+
| **Service Bus connection** | <*Service-Bus-connection*> | Select **New** to set up the connection for your Service Bus queue, which uses the Service Bus SDK `OnMessageReceive()` listener. |
118
+
| **Queue name** | <*queue-name*> | Enter the name for your queue. |
115
119
116
-
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**.
120
+
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/current-add-queue-trigger-template.png" alt-text="Screenshot of the 'Create function' pane with 'Azure Service Bus Queue trigger' highlighted, and template example details entered.":::
117
121
118
-
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:
122
+
1. When you're done, select **Create**.
123
+
124
+
The Azure portal now shows the **Overview** page for your new Azure Service Bus Queue trigger function.
125
+
126
+
1. Now, write a basic function to call the endpoint for the logic app workflow that you created earlier.Before you write your function, review the following considerations:
127
+
128
+
* Trigger the function by using the message from the queue message.
119
129
120
-
* The following example uses the `application/json` message content type, but you can change this type as necessary.
121
-
122
130
* 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).
123
131
124
132
* If possible, reuse the instance of HTTP clients. For more information, see [Manage connections in Azure Functions](../azure-functions/manage-connections.md).
125
133
126
-
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/).
134
+
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/). The example also uses the `application/json` message content type, but you can change this type as necessary.
127
135
128
136
```csharp
129
137
using System;
130
138
using System.Threading.Tasks;
131
139
using System.Net.Http;
132
140
using System.Text;
133
141
134
-
// Set up the logic app workflow URI. You can also get it from App Settings or an environment variable.
142
+
// Set up the URI for the logic app workflow. You can also get this value on the logic app's 'Overview' pane, under the trigger history or an environment variable.
// Reuse the instance of HTTP clients if possible. For more information, see https://learn.microsoft.com/azure/azure-functions/manage-connections.
@@ -146,21 +154,23 @@ Next, create the function that acts as the trigger and listens to the queue.
146
154
147
155
## Test your logic app workflow
148
156
149
-
To test your logic app workflow, use a tool to add a message to your Service Bus queue.
157
+
For testing, add a message to your Service Bus queue by using the following steps or other tool:
150
158
151
-
1. In the Azure portal, open your Service Bus namespace.
159
+
1. In the [Azure portal](https://portal.azure.com), open your Service Bus namespace.
152
160
153
161
1. On the Service Bus namespace navigation menu, select **Queues**.
154
162
155
-
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/service-bus-namespace-queues.png" alt-text="Screenshot of a Service Bus namespace in the Azure portal. On the navigation menu, 'Queues' is highlighted.":::
163
+
:::image type="content" source="./media/logic-apps-scenario-function-sb-trigger/service-bus-namespace-queues.png" alt-text="Screenshot of a Service Bus namespace. On the navigation menu, 'Queues' is highlighted.":::
156
164
157
-
1. Select the queue that you linked to your function through its Service Bus connection.
165
+
1. Select the Service Bus queue that you linked to your function earlier using a Service Bus connection.
166
+
167
+
1. On the queue navigation menu, select **Service Bus Explorer**, and then on the toolbar, select **Send messages**.
158
168
159
-
1. On the queue navigation menu, select **Service Bus Explorer**, and then select **Send messages**.
160
-
161
169
:::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.":::
162
170
163
-
1. Use the tool to send a message to your Service Bus queue. The message triggers your logic app workflow.
171
+
1. On the **Send messages** pane, specify the message to send to your Service Bus queue.
0 commit comments