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
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
11
5
ms.service: logic-apps
12
-
ms.devlang: multiple
6
+
ms.suite: integration
7
+
author: ecfan
8
+
ms.reviewer: jehollan, klam, LADocs
13
9
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
19
12
---
20
-
# Scenario: Trigger a logic app with Azure Functions and Azure Service Bus
21
13
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
+
<ahref="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).
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.
23
63
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**.
26
66
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**.
![The callback URL appears on the trigger card][1]
72
+
This sample payload generates this schema that appears in the trigger:
34
73
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
+

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.
37
117
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#**
39
121
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.
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).
0 commit comments