|
| 1 | +--- |
| 2 | +title: Enable stateful mode for stateless built-in connectors |
| 3 | +description: Enable stateless built-in connectors to run in stateful mode for Standard workflows in Azure Logic Apps. |
| 4 | +services: logic-apps |
| 5 | +ms.suite: integration |
| 6 | +ms.reviewer: estfan, edwardhe, azla |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 06/13/2023 |
| 9 | +--- |
| 10 | + |
| 11 | +# Enable stateful mode for stateless built-in connectors in Azure Logic Apps |
| 12 | + |
| 13 | +[!INCLUDE [logic-apps-sku-standard](../../includes/logic-apps-sku-standard.md)] |
| 14 | + |
| 15 | +In Standard logic app workflows, the following built-in, service provider-based connectors are stateless, by default: |
| 16 | + |
| 17 | +- Azure Service Bus |
| 18 | +- SAP |
| 19 | + |
| 20 | +To run these connector operations in stateful mode, you must enable this capability. This how-to guide shows how to enable stateful mode for these connectors. |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +- An Azure account and subscription. If you don't have a subscription, [sign up for a free Azure account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 25 | + |
| 26 | +- The Standard logic app resource where you plan to create the workflow that uses the stateful mode-enabled connector operations. If you don't have this resource, [create your Standard logic app resource now](../logic-apps/create-single-tenant-workflows-azure-portal.md). |
| 27 | + |
| 28 | +- An Azure virtual network with a subnet to integrate with your logic app. If you don't have these items, see the following documentation: |
| 29 | + |
| 30 | + - [Quickstart: Create a virtual network with the Azure portal](../virtual-network/quick-create-portal.md) |
| 31 | + - [Add, change, or delete a virtual network subnet](../virtual-network/virtual-network-manage-subnet.md?tabs=azure-portal) |
| 32 | + |
| 33 | +## Enable stateful mode in the Azure portal |
| 34 | + |
| 35 | +1. In the [Azure portal](https://portal.azure.com), open the Standard logic app resource where you want to enable stateful mode for these connector operations. |
| 36 | + |
| 37 | +1. Enable virtual network integration for your logic app and add your logic app to the previously created subnet: |
| 38 | + |
| 39 | + 1. On your logic app menu resource, under **Settings**, select **Networking**. |
| 40 | + |
| 41 | + 1. In the **Outbound Traffic** section, select **VNET integration** > **Add VNet**. |
| 42 | + |
| 43 | + 1. On the **Add VNet Integration** pane that opens, select your Azure subscription and your virtual network. |
| 44 | + |
| 45 | + 1. Under **Subnet**, select **Select existing**. From the **Subnet** list, select the subnet where you want to add your logic app. |
| 46 | + |
| 47 | + 1. When you're done, select **OK**. |
| 48 | + |
| 49 | + On the **Networking** page, the **VNet integration** option now appears set to **On**, for example: |
| 50 | + |
| 51 | + :::image type="content" source="media/enable-stateful-affinity-built-in-connectors/enable-virtual-network-integration.png" alt-text="Screenshot shows Azure portal, Standard logic app resource, Networking page, VNet integration set to On."::: |
| 52 | + |
| 53 | + For general information about enabling virtual network integration with your app, see [Enable virtual network integration in Azure App Service](../app-service/configure-vnet-integration-enable.md). |
| 54 | + |
| 55 | +1. Next, update your logic app's underlying website configuration (**<*logic-app-name*>.azurewebsites.net**) by using either of the following tools: |
| 56 | + |
| 57 | +## Update website configuration for logic app |
| 58 | + |
| 59 | +After you enable virtual network integration for your logic app, you must update your logic app's underlying website configuration (**<*logic-app-name*>.azurewebsites.net**) by using one the following methods: |
| 60 | + |
| 61 | +- [Azure Resource Management API](#azure-resource-management-api) (bearer token required) |
| 62 | +- [Azure PowerShell](#azure-powershell) (bearer token *not* required) |
| 63 | + |
| 64 | +### Azure Resource Management API |
| 65 | + |
| 66 | +To complete this task with the [Azure Resource Management API - Update By Id](/rest/api/resources/resources/update-by-id), review the following requirements, syntax, and parameter values. |
| 67 | + |
| 68 | +#### Requirements |
| 69 | + |
| 70 | +OAuth authorization and the bearer token are required. To get the bearer token, follow these steps |
| 71 | + |
| 72 | +1. While you're signed in to the Azure portal, open your web browser's developer tools (F12). |
| 73 | + |
| 74 | +1. Get the token by sending any management request, for example, by saving a workflow in your Standard logic app. |
| 75 | + |
| 76 | +#### Syntax |
| 77 | + |
| 78 | +Updates a resource by using the specified resource ID: |
| 79 | + |
| 80 | +`PATCH https://management.azure.com/{resourceId}?api-version=2021-04-01` |
| 81 | + |
| 82 | +#### Parameter values |
| 83 | + |
| 84 | +| Element | Value | Description | |
| 85 | +|---------|--------|-------------| |
| 86 | +| HTTP request method | **PATCH** | |
| 87 | +| <*resourceId*> | **subscriptions/{yourSubscriptionID}/resourcegroups/{yourResourceGroup}/providers/Microsoft.Web/sites/{websiteName}/config/web** | |
| 88 | +| <*yourSubscriptionId*> | The ID for your Azure subscription | |
| 89 | +| <*yourResourceGroup*> | The resource group that contains your logic app resource | |
| 90 | +| <*websiteName*> | The name for your logic app resource, which is **mystandardlogicapp** in this example | |
| 91 | +| HTTP request body | **{"properties": {"vnetPrivatePortsCount": "2"}}** | |
| 92 | + |
| 93 | +#### Example |
| 94 | + |
| 95 | +`https://management.azure.com/subscriptions/XXxXxxXX-xXXx-XxxX-xXXX-XXXXxXxXxxXX/resourcegroups/My-Standard-RG/providers/Microsoft.Web/sites/mystandardlogicapp/config/web?api-version=2021-02-01` |
| 96 | + |
| 97 | +### Azure PowerShell |
| 98 | + |
| 99 | +To complete this task with Azure PowerShell, review the following requirements, syntax, and values. This method doesn't require that you manually get the bearer token. |
| 100 | + |
| 101 | +#### Syntax |
| 102 | + |
| 103 | +```powershell |
| 104 | +Set-AzContext -Subscription {yourSubscriptionID} |
| 105 | +$webConfig = Get-AzResource -ResourceId {resourceId} |
| 106 | +$webConfig.Properties.vnetPrivatePortsCount = 2 |
| 107 | +$webConfig | Set-AzResource -ResourceId {resourceId} |
| 108 | +``` |
| 109 | + |
| 110 | +For more information, see the following documentation: |
| 111 | + |
| 112 | +- [Set-AzContext](/powershell/module/az.accounts/set-azcontext) |
| 113 | +- [Get-AzResource](/powershell/module/az.resources/get-azresource) |
| 114 | +- [Set-AzResource](/powershell/module/az.resources/set-azresource) |
| 115 | + |
| 116 | +#### Parameter values |
| 117 | + |
| 118 | +| Element | Value | |
| 119 | +|---------|--------| |
| 120 | +| <*yourSubscriptionID*> | The ID for your Azure subscription | |
| 121 | +| <*resourceId*> | **subscriptions/{yourSubscriptionID}/resourcegroups/{yourResourceGroup}/providers/Microsoft.Web/sites/{websiteName}/config/web** | |
| 122 | +| <*yourResourceGroup*> | The resource group that contains your logic app resource | |
| 123 | +| <*websiteName*> | The name for your logic app resource, which is **mystandardlogicapp** in this example | |
| 124 | + |
| 125 | +#### Example |
| 126 | + |
| 127 | +`https://management.azure.com/subscriptions/XXxXxxXX-xXXx-XxxX-xXXX-XXXXxXxXxxXX/resourcegroups/My-Standard-RG/providers/Microsoft.Web/sites/mystandardlogicapp/config/web?api-version=2021-02-01` |
| 128 | + |
| 129 | +#### Troubleshoot errors |
| 130 | + |
| 131 | +##### Error: Reserved instance count is invalid |
| 132 | + |
| 133 | +If you get an error that says **Reserved instance count is invalid**, use the following workaround: |
| 134 | + |
| 135 | +```powershell |
| 136 | +$webConfig.Properties.preWarmedInstanceCount = $webConfig.Properties.reservedInstanceCount |
| 137 | +$webConfig.Properties.reservedInstanceCount = $null |
| 138 | +$webConfig | Set-AzResource -ResourceId {resourceId} |
| 139 | +``` |
| 140 | + |
| 141 | +Error example: |
| 142 | + |
| 143 | +```powershell |
| 144 | +Set-AzResource : |
| 145 | +{ |
| 146 | + "Code":"BadRequest", |
| 147 | + "Message":"siteConfig.ReservedInstanceCount is invalid. Please use the new property siteConfig.PreWarmedInstanceCount.", |
| 148 | + "Target": null, |
| 149 | + "Details": |
| 150 | + [ |
| 151 | + { |
| 152 | + "Message":"siteConfig.ReservedInstanceCount is invalid. Please use the new property siteConfig.PreWarmedInstanceCount." |
| 153 | + }, |
| 154 | + { |
| 155 | + "Code":"BadRequest" |
| 156 | + }, |
| 157 | + { |
| 158 | + "ErrorEntity": |
| 159 | + { |
| 160 | + "ExtendedCode":"51021", |
| 161 | + "MessageTemplate":"{0} is invalid. {1}", |
| 162 | + "Parameters": |
| 163 | + [ |
| 164 | + "siteConfig.ReservedInstanceCount", "Please use the new property siteConfig.PreWarmedInstanceCount." |
| 165 | + ], |
| 166 | + "Code":"BadRequest", |
| 167 | + "Message":"siteConfig.ReservedInstanceCount is invalid. Please use the new property siteConfig.PreWarmedInstanceCount." |
| 168 | + } |
| 169 | + } |
| 170 | + ], |
| 171 | + "Innererror": null |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +## Prevent context loss during resource scale-in events |
| 176 | + |
| 177 | +Resource scale-in events might cause the loss of context for built-in connectors with stateful mode enabled. To prevent this potential loss before such events can happen, fix the number of instances available for your logic app resource. This way, no scale-in events can happen to cause this potential context loss. |
| 178 | + |
| 179 | +1. On your logic app resource menu, under **Settings**, select **Scale out**. |
| 180 | + |
| 181 | +1. Under **App Scale Out**, set **Enforce Scale Out Limit** to **Yes**, which shows the **Maximum Scale Out Limit**. |
| 182 | + |
| 183 | +1. On the **Scale out** page, under **App Scale out**, set the number for **Always Ready Instances** to the same number as **Maximum Scale Out Limit** and **Maximum Burst**, which appears under **Plan Scale Out**, for example: |
| 184 | + |
| 185 | + :::image type="content" source="media/enable-stateful-affinity-built-in-connectors/scale-in-settings.png" alt-text="Screenshot shows Azure portal, Standard logic app resource, Scale out page, and Always Ready Instances number set to match Maximum Scale Out Limit and Maximum Burst."::: |
| 186 | + |
| 187 | +1. When you're done, on the **Scale out** toolbar, select **Save**. |
| 188 | + |
| 189 | +## Next steps |
| 190 | + |
| 191 | +- [Connect to Azure Service Bus](connectors-create-api-servicebus.md) |
| 192 | +- [Connect to SAP](../logic-apps/logic-apps-using-sap-connector.md) |
0 commit comments