Skip to content

Commit 0b59c8a

Browse files
committed
Revisions
1 parent 31bd7f1 commit 0b59c8a

9 files changed

+66
-56
lines changed

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

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@ ms.custom: devx-track-csharp
1414

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

17-
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.
1818

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.
2020

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.
2222

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.
2527
2628
## Prerequisites
2729

2830
* 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).
2931

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)
3133

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.
3335

3436
* Basic knowledge about [how to create a Consumption logic app workflow](quickstart-create-first-logic-app-workflow.md).
3537

3638
## Create a logic app workflow
3739

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-
4040
1. In the [Azure portal](https://portal.azure.com), create a Consumption blank logic app by selecting the **Blank Logic App** template.
4141

4242
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
5959

6060
:::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.":::
6161

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+
}
8586
}
8687
}
8788
}
8889
}
89-
}
90-
```
90+
```
9191

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.
9393

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.
9595

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.
9797

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.
9999

100100
:::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.":::
101101

102102
## Create a function
103103

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.
105105

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.
107107

108108
1. On the function app navigation menu, select **Functions**. On the **Functions** pane, select **Create**.
109109

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.":::
111111

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:
113113

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. |
115119

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.":::
117121

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.
119129

120-
* The following example uses the `application/json` message content type, but you can change this type as necessary.
121-
122130
* 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).
123131

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

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.
127135

128136
```csharp
129137
using System;
130138
using System.Threading.Tasks;
131139
using System.Net.Http;
132140
using System.Text;
133141

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.
135143
private static string logicAppUri = @"https://prod-05.westus.logic.azure.com:443/workflows/<remaining-callback-URL>";
136144

137145
// 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.
146154

147155
## Test your logic app workflow
148156

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:
150158

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.
152160

153161
1. On the Service Bus namespace navigation menu, select **Queues**.
154162

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.":::
156164

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**.
158168

159-
1. On the queue navigation menu, select **Service Bus Explorer**, and then select **Send messages**.
160-
161169
:::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.":::
162170

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.
172+
173+
This message triggers your logic app workflow.
164174

165175
## Next steps
166176

3.86 KB
Loading
-3.26 KB
Loading
12.1 KB
Loading
-3.08 KB
Loading
5.18 KB
Loading
-1.95 KB
Loading
-38.1 KB
Loading

0 commit comments

Comments
 (0)