Skip to content

Commit 4e81b86

Browse files
authored
Merge pull request #50176 from ecfan/metadata-1
Update metadata, SEO tweaks, and art updates
2 parents 8a0058b + eb0a7a7 commit 4e81b86

15 files changed

+218
-113
lines changed

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

Lines changed: 130 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,133 @@
11
---
22
title: Scenario - Trigger logic apps with Azure Functions and Azure Service Bus | Microsoft Docs
3-
description: Create a function to trigger a logic app by using Azure Functions and Azure Service Bus
4-
services: logic-apps,functions
5-
documentationcenter: .net,nodejs,java
6-
author: jeffhollan
7-
manager: jeconnoc
8-
editor: ''
9-
10-
ms.assetid: 19cbd921-7071-4221-ab86-b44d0fc0ecef
3+
description: Create functions that trigger logic apps by using Azure Functions and Azure Service Bus
4+
services: logic-apps
115
ms.service: logic-apps
12-
ms.devlang: multiple
6+
ms.suite: integration
7+
author: ecfan
8+
ms.reviewer: jehollan, klam, LADocs
139
ms.topic: article
14-
ms.tgt_pltfrm: na
15-
ms.workload: integration
16-
ms.date: 05/23/2016
17-
ms.author: LADocs; jehollan
18-
10+
ms.assetid: 19cbd921-7071-4221-ab86-b44d0fc0ecef
11+
ms.date: 08/25/2018
1912
---
20-
# Scenario: Trigger a logic app with Azure Functions and Azure Service Bus
2113

22-
You can use Azure Functions to create a trigger for a logic app when you need to deploy a long-running listener or task. For example, you can create a function that listens in on a queue and then immediately fire a logic app as a push trigger.
14+
# Scenario: Trigger logic apps with Azure Functions and Azure Service Bus
15+
16+
You can use Azure Functions to create a trigger for a logic app
17+
when you need to deploy a long-running listener or task. For example,
18+
you can create a function that listens in on a queue and then
19+
immediately fire a logic app as a push trigger.
20+
21+
## Prerequisites
22+
23+
* An Azure subscription. If you don't have an Azure subscription,
24+
<a href="https://azure.microsoft.com/free/" target="_blank">sign up for a free Azure account</a>.
25+
26+
* Basic knowledge about [how to create logic apps](../logic-apps/quickstart-create-first-logic-app-workflow.md)
27+
28+
* Before you can create an Azure function,
29+
[create a function app](../azure-functions/functions-create-function-app-portal.md).
30+
31+
## Create logic app
32+
33+
In this example, you have a function running for
34+
each logic app that needs to be triggered.
35+
First, create a logic app that has an HTTP request trigger.
36+
The function calls that endpoint whenever a queue message is received.
37+
38+
1. Sign in to the [Azure portal](https://portal.azure.com),
39+
and create blank logic app.
40+
41+
If you're new to logic apps, review
42+
[Quickstart: Create your first logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md).
43+
44+
1. In the search box, enter "http request".
45+
Under the triggers list, select this trigger:
46+
**When a HTTP request is received**
47+
48+
![Select trigger](./media/logic-apps-scenario-function-sb-trigger/when-http-request-received-trigger.png)
49+
50+
1. For the **Request** trigger, you can optionally
51+
enter a JSON schema for use with the queue message.
52+
JSON schemas help the Logic App Designer understand
53+
the structure of the input data and makes outputs
54+
easier for you to select throughout the workflow.
55+
56+
To specify a schema, enter the schema in the
57+
**Request Body JSON Schema** box, for example:
58+
59+
![Specify JSON schema](./media/logic-apps-scenario-function-sb-trigger/when-http-request-received-trigger-schema.png)
60+
61+
If you don't have a schema, but you have a sample payload in JSON format,
62+
you can generate a schema from that payload.
2363

24-
## Build the logic app
25-
In this example, you have a function running for each logic app that needs to be triggered. First, create a logic app that has an HTTP request trigger. The function calls that endpoint whenever a queue message is received.
64+
1. In the Request trigger, choose
65+
**Use sample payload to generate schema**.
2666

27-
1. Create a logic app.
28-
2. Select the **Manual - When an HTTP Request is Received** trigger.
29-
Optionally, you can specify a JSON schema to use with the queue message by using a tool like [jsonschema.net](http://jsonschema.net). Paste the schema in the trigger. Schemas help the designer understand the shape of the data and flow properties more easily through the workflow.
30-
2. Add any additional steps that you want to occur after a queue message is received. For example, send an email via Office 365.
31-
3. Save the logic app to generate the callback URL for the trigger to this logic app. The URL appears on the trigger card.
67+
1. Under **Enter or paste a sample JSON payload**,
68+
enter your sample payload, and then choose **Done**.
69+
70+
![Enter sample payload](./media/logic-apps-scenario-function-sb-trigger/enter-sample-payload.png)
3271

33-
![The callback URL appears on the trigger card][1]
72+
This sample payload generates this schema that appears in the trigger:
3473

35-
## Build the function
36-
Next, you must create a function that acts as the trigger and listens to the queue.
74+
```json
75+
{
76+
"type": "object",
77+
"properties": {
78+
"address": {
79+
"type": "object",
80+
"properties": {
81+
"number": {
82+
"type": "integer"
83+
},
84+
"street": {
85+
"type": "string"
86+
},
87+
"city": {
88+
"type": "string"
89+
},
90+
"postalCode": {
91+
"type": "integer"
92+
},
93+
"country": {
94+
"type": "string"
95+
}
96+
}
97+
}
98+
}
99+
}
100+
```
101+
102+
1. Add any other actions you want to happen after receiving the queue message.
103+
104+
For example, you can send an email with the Office 365 Outlook connector.
105+
106+
1. Save your logic app, which generates the
107+
callback URL for the trigger in this logic app.
108+
This URL appears in the **HTTP POST URL** property.
109+
110+
![Generated callback URL for trigger](./media/logic-apps-scenario-function-sb-trigger/callback-URL-for-trigger.png)
111+
112+
## Create Azure function
113+
114+
Next, create the function that acts as the trigger and listens to the queue.
115+
116+
1. In the Azure portal, open and expand your function app, if not already open.
37117

38-
1. In the [Azure Functions portal](https://functions.azure.com/), select **New Function**, and then select the **ServiceBusQueueTrigger - C#** template.
118+
1. Under your function app name, expand **Functions**.
119+
On the **Functions** pane, choose **New function**.
120+
Select this template: **Service Bus Queue trigger - C#**
39121

40-
![Azure Functions portal][2]
41-
2. Configure the connection to the Service Bus queue, which uses the Azure Service Bus SDK `OnMessageReceive()` listener.
42-
3. Write a basic function to call the logic app endpoint (created earlier) by using the queue message as a trigger. Here's a full example of a function. The example uses an `application/json` message content type, but you can change this type as necessary.
122+
![Select Azure Functions portal](./media/logic-apps-scenario-function-sb-trigger/newqueuetriggerfunction.png)
123+
124+
1. Provide a name for your trigger, and then configure the
125+
connection to the Service Bus queue, which uses the Azure
126+
Service Bus SDK `OnMessageReceive()` listener.
127+
128+
1. Write a basic function to call the previously created logic app endpoint by using the queue message as a trigger, for example:
43129

44-
```
130+
```CSharp
45131
using System;
46132
using System.Threading.Tasks;
47133
using System.Net.Http;
@@ -51,17 +137,25 @@ Next, you must create a function that acts as the trigger and listens to the que
51137

52138
public static void Run(string myQueueItem, TraceWriter log)
53139
{
54-
55140
log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
141+
56142
using (var client = new HttpClient())
57143
{
58144
var response = client.PostAsync(logicAppUri, new StringContent(myQueueItem, Encoding.UTF8, "application/json")).Result;
59145
}
60146
}
61147
```
62148

63-
To test, add a queue message via a tool like [Service Bus Explorer](https://github.com/paolosalvatori/ServiceBusExplorer). See the logic app fire immediately after the function receives the message.
149+
This example uses the `application/json` message content type,
150+
but you can change this type as necessary.
151+
152+
1. To test the function, add a queue message by using a tool such as the [Service Bus Explorer](https://github.com/paolosalvatori/ServiceBusExplorer).
153+
154+
The logic app triggers immediately after the
155+
function receives the message.
156+
157+
## Get support
158+
159+
* For questions, visit the [Azure Logic Apps forum](https://social.msdn.microsoft.com/Forums/en-US/home?forum=azurelogicapps).
160+
* To submit or vote on feature ideas, visit the [Logic Apps user feedback site](http://aka.ms/logicapps-wish).
64161

65-
<!-- Image References -->
66-
[1]: ./media/logic-apps-scenario-function-sb-trigger/manualtrigger.png
67-
[2]: ./media/logic-apps-scenario-function-sb-trigger/newqueuetriggerfunction.png

0 commit comments

Comments
 (0)