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
# Azure Database for MySQL trigger for Functions (Preview)
19
19
20
20
> [!NOTE]
21
-
> While input and output bindings will be supported on all plans, the MySQL Trigger binding will be available only on [dedicated and premium plans](functions-scale.md) during the public preview. Support for Consumption plans in the MySQL Trigger binding will be introduced at general availability.
21
+
> While input and output bindings are supported on all plans, the MySQL Trigger binding will be available only on [dedicated and premium plans](functions-scale.md) during the public preview. Support for Consumption plans in the MySQL Trigger binding will be introduced at general availability.
22
22
>
23
23
24
24
The Azure Database for MySQL Trigger bindings monitor the user table for changes (inserts, updates) and invokes the function with updated row data.
25
25
26
-
Azure MySQL Trigger bindings use "az_func_updated_at" and column's data, to monitor the user table for changes. As such, it is necessary to alter the table structure to allow change tracking on the MySQL table before using the trigger support. The change tracking can be enabled on a table through following query. For example, enable on ‘Products’ table:
26
+
Azure MySQL Trigger bindings use "az_func_updated_at" and column's data, to monitor the user table for changes. As such, it's necessary to alter the table structure to allow change tracking on the MySQL table before using the trigger support. The change tracking can be enabled on a table through following query. For example, enable on ‘Products’ table:
27
27
28
28
```sql
29
29
ALTERTABLE Products
30
30
ADD az_func_updated_at TIMESTAMP DEFAULT
31
31
CURRENT_TIMESTAMPONUPDATECURRENT_TIMESTAMP;
32
32
```
33
33
34
-
The leases table contains all columns corresponding to the primary key from the user table and three additional columns _az_func_AttemptCount, _az_func_LeaseExpirationTime, _az_func_SyncCompletedTime. So, if any of the primary key columns happen to have the same name, that will result in an error message listing any conflicts. In this case, the listed primary key columns must be renamed for the trigger to work.
34
+
The leases table contains all columns corresponding to the primary key from the user table and three more columns _az_func_AttemptCount, _az_func_LeaseExpirationTime, _az_func_SyncCompletedTime. So, if any of the primary key columns happen to have the same name that will result in an error message listing any conflicts. In this case, the listed primary key columns must be renamed for the trigger to work.
35
35
36
36
37
37
## Functionality Overview
38
38
39
-
When the trigger function starts, it will initiate two separate loops (Change Polling Loop and Lease Renewal Loop) that will run continuously until the function is stopped.
39
+
When the trigger function starts, it initiates two separate loops (Change Polling Loop and Lease Renewal Loop) that will run continuously until the function is stopped.
40
40
41
41
The Azure Database for MySQL trigger binding uses a polling loop to check for changes, triggering the user function when changes are detected. At a high level, the loop looks like this:
42
42
@@ -49,11 +49,11 @@ while (true) {
49
49
```
50
50
51
51
Changes are processed in the order that they were made, with the oldest changes being processed first. A couple notes about change processing:
52
-
1. If changes to multiple row are made once then the exact order they are sent to the function is based on, the ascending order of “az_func_updated_at” column and primary key columns.
52
+
1. If changes to multiple row are made once then the exact order they're sent to the function is based on, the ascending order of “az_func_updated_at” column and primary key columns.
53
53
2. Changes are "batched" together for a row. If multiple changes are made to a row between each iteration of the loop, then only the latest change entry exists for that row will be considered.
54
54
55
55
> [!NOTE]
56
-
>Currently, we are not supporting Managed Identity for connections between Functions and Azure Database for MySQL.
56
+
>Currently, we aren't supporting Managed Identity for connections between Functions and Azure Database for MySQL.
57
57
>
58
58
59
59
@@ -116,7 +116,7 @@ ON UPDATE CURRENT_TIMESTAMP;
116
116
117
117
The MySQL trigger binds to a `IReadOnlyList<MySqlChange<T>>`, a list of `MySqlChange` objects each with two properties:
118
118
- **Item:** the item that was changed. The type of the item should follow the table schema as seen in the `ToDoItem` class.
119
-
- **Operation:** a value from `MySqlChangeOperation` enum. The possible values is `Update` for both insert and update.
119
+
- **Operation:** a value from `MySqlChangeOperation` enum. The possible value is `Update` for both insert and update.
120
120
121
121
The following example shows a [C# function](functions-dotnet-class-library.md) that is invoked when there are changes to the `Product` table:
122
122
@@ -313,7 +313,7 @@ CREATE TABLE Products (
313
313
```
314
314
315
315
316
-
Change tracking is enabled on the database by adding the below column to the table:
316
+
Change tracking is enabled on the database by adding the following column to the table:
317
317
318
318
```sql
319
319
ALTER TABLE <table name>
@@ -324,7 +324,7 @@ ON UPDATE CURRENT_TIMESTAMP;
324
324
325
325
The MySQL trigger binds to a `MySqlChangeProduct[]`, an array of `MySqlChangeProduct` objects each with two properties:
326
326
- **item:** the item that was changed. The type of the item should follow the table schema as seen in the `Product` class.
327
-
- **operation:** a value from `MySqlChangeOperation` enum. The possible values is `Update` for both insert and update.
327
+
- **operation:** a value from `MySqlChangeOperation` enum. The possible value is `Update` for both insert and update.
328
328
329
329
330
330
The following example shows a Java function that is invoked when there are changes to the `Product` table:
@@ -394,8 +394,8 @@ ON UPDATE CURRENT_TIMESTAMP;
394
394
```
395
395
396
396
The MySQL trigger binds to `Product`, a list of objects each with two properties:
397
-
- **item:** the item that was changed. The structure of the item will follow the table schema.
398
-
- **operation:** The possible values is `Update` for both insert and update.
397
+
- **item:** the item that was changed. The structure of the item follows the table schema.
398
+
- **operation:** The possible value is `Update` for both insert and update.
399
399
400
400
401
401
The following example shows a PowerShell function that is invoked when there are changes to the `Product` table.
@@ -463,8 +463,8 @@ ON UPDATE CURRENT_TIMESTAMP;
463
463
```
464
464
465
465
The MySQL trigger binds `Changes`, an array of objects each with two properties:
466
-
-**item:** the item that was changed. The structure of the item will follow the table schema.
467
-
-**operation:** The possible values is `Update` for both insert and update.
466
+
-**item:** the item that was changed. The structure of the item follows the table schema.
467
+
-**operation:** The possible value is `Update` for both insert and update.
468
468
469
469
470
470
The following example shows a JavaScript function that is invoked when there are changes to the `Product` table.
@@ -530,13 +530,13 @@ ON UPDATE CURRENT_TIMESTAMP;
530
530
```
531
531
532
532
> [!NOTE]
533
-
> Please note that Azure Functions version 1.22.0b4 must be used for Python.
533
+
> Please note that Azure Functions version 1.22.0b4 must be used for Python.
534
534
>
535
535
536
536
537
537
The MySQL trigger binds to a variable `Product`, a list of objects each with two properties:
538
-
-**item:** the item that was changed. The structure of the item will follow the table schema.
539
-
-**operation:** The possible values is `Update` for both insert and update.
538
+
-**item:** the item that was changed. The structure of the item follows the table schema.
539
+
-**operation:** The possible value is `Update` for both insert and update.
540
540
541
541
542
542
The following example shows a Python function that is invoked when there are changes to the `Product` table.
@@ -612,7 +612,7 @@ def main(changes):
612
612
|---------|---------|
613
613
|**TableName**| Required. The name of the table monitored by the trigger. |
614
614
|**ConnectionStringSetting**| Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) to the Azure Database for MySQL.|
615
-
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name will be Leases_{FunctionId}_{TableId}.
615
+
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name is Leases_{FunctionId}_{TableId}.
616
616
617
617
618
618
::: zone-end
@@ -629,7 +629,7 @@ In the [Java functions runtime library](/java/api/overview/azure/functions/runti
629
629
|**name**| Required. The name of the parameter that the trigger binds to. |
630
630
|**tableName**| Required. The name of the table monitored by the trigger. |
631
631
|**connectionStringSetting**| Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) to the Azure Database for MySQL.|
632
-
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name will be Leases_{FunctionId}_{TableId}.
632
+
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name is Leases_{FunctionId}_{TableId}.
633
633
634
634
::: zone-end
635
635
@@ -646,7 +646,7 @@ The following table explains the binding configuration properties that you set i
646
646
|**direction**| Required. Must be set to `in`. |
647
647
|**tableName**| Required. The name of the table monitored by the trigger. |
648
648
|**connectionStringSetting**| Required. The name of an app setting that contains the connection string for the database containing the table monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](https://dev.mysql.com/doc/connector-net/en/connector-net-connections-string.html) to the Azure Database for MySQL.|
649
-
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name will be Leases_{FunctionId}_{TableId}.
649
+
| **LeasesTableName** | Optional. Name of the table used to store leases. If not specified, the leases table name is Leases_{FunctionId}_{TableId}.
650
650
651
651
::: zone-end
652
652
@@ -661,12 +661,12 @@ The following optional settings can be configured for the MySQL trigger for loca
661
661
| Setting | Default| Description|
662
662
|---------|---------|---------|
663
663
|**MaxBatchSize**| 100 |The maximum number of changes processed with each iteration of the trigger loop before being sent to the triggered function.|
664
-
|**PollingIntervalMs**| 1000 | The delay in milliseconds between processing each batch of changes. (1000 ms is 1 second)|
664
+
|**PollingIntervalMs**| 1000 | The delay in milliseconds between processing each batch of changes. (1,000 ms is 1 second)|
665
665
|**MaxChangesPerWorker**| 1000 | The upper limit on the number of pending changes in the user table that are allowed per application-worker. If the count of changes exceeds this limit, it might result in a scale-out. The setting only applies for Azure Function Apps with [runtime driven scaling enabled](#enable-runtime-driven-scaling).|
666
666
667
667
#### Example host.json file
668
668
669
-
Here is an example host.json file with the optional settings:
669
+
Here's an example host.json file with the optional settings:
670
670
671
671
```JSON
672
672
{
@@ -702,12 +702,12 @@ The local.settings.json file stores app settings and settings used by local deve
702
702
| Setting | Default| Description|
703
703
|---------|---------|---------|
704
704
|**MySql_Trigger_BatchSize**| 100 |The maximum number of changes processed with each iteration of the trigger loop before being sent to the triggered function.|
705
-
|**MySql_Trigger_PollingIntervalMs**| 1000 | The delay in milliseconds between processing each batch of changes. (1000 ms is 1 second)|
705
+
|**MySql_Trigger_PollingIntervalMs**| 1000 | The delay in milliseconds between processing each batch of changes. (1,000 ms is 1 second)|
706
706
|**MySql_Trigger_MaxChangesPerWorker**| 1000 | The upper limit on the number of pending changes in the user table that are allowed per application-worker. If the count of changes exceeds this limit, it might result in a scale-out. The setting only applies for Azure Function Apps with [runtime driven scaling enabled](#enable-runtime-driven-scaling).|
707
707
708
708
#### Example local.settings.json file
709
709
710
-
Here is an example local.settings.json file with the optional settings:
710
+
Here's an example local.settings.json file with the optional settings:
711
711
712
712
```JSON
713
713
{
@@ -727,7 +727,7 @@ Here is an example local.settings.json file with the optional settings:
727
727
728
728
Setting up change tracking for use with the Azure Database for MySQL trigger requires to add a column in table using a function. These steps can be completed from any MySQL tool that supports running queries, including [Visual Studio Code](/sql/tools/visual-studio-code/mssql-extensions) or [Azure Data Studio](/azure-data-studio/download-azure-data-studio).
729
729
730
-
Azure Database for MySQL Trigger ndings use "az_func_updated_at" and column's data, to monitor the user table for changes. As such, it is necessary to alter the table structure to allow change tracking on the MySQL table before using the trigger support.
730
+
Azure Database for MySQL Trigger bindings use "az_func_updated_at" and column's data, to monitor the user table for changes. As such, it's necessary to alter the table structure to allow change tracking on the MySQL table before using the trigger support.
731
731
732
732
The change tracking can be enabled on a table through following query. For example, enable on ‘Products’ table:
The leases table contains all columns corresponding to the primary key from the user table and two additional columns _az_func_AttemptCount and _az_func_LeaseExpirationTime. So, if any of the primary key columns happen to have the same name, that will result in an error message listing any conflicts. In this case, the listed primary key columns must be renamed for the trigger to work.
741
+
The leases table contains all columns corresponding to the primary key from the user table and two more columns _az_func_AttemptCount and _az_func_LeaseExpirationTime. So, if any of the primary key columns happen to have the same name, that will result in an error message listing any conflicts. In this case, the listed primary key columns must be renamed for the trigger to work.
742
742
743
743
744
744
## Enable runtime-driven scaling
@@ -753,9 +753,9 @@ Optionally, your functions can scale automatically based on the number of change
753
753
If an exception occurs during startup then the host runtime automatically attempts to restart the trigger listener with an exponential backoff strategy. These retries continue until either the listener is successfully started or the startup is canceled.
754
754
755
755
### Function exception retries
756
-
If an exception occurs in the user function when processing changes then the batch of rows currently being processed are retried again in 60 seconds. Other changes are processed as normal during this time, but the rows in the batch that caused the exception are ignored until the timeout period has elapsed.
756
+
If an exception occurs in the user function when processing changes then the batch of rows currently being processed are retried again in 60 seconds. Other changes are processed as normal during this time, but the rows in the batch that caused the exception are ignored until the time-out period has elapsed.
757
757
758
-
If the function execution fails five times in a row for a given row then that row is completely ignored for all future changes. Because the rows in a batch are not deterministic, rows in a failed batch might end up in different batches in subsequent invocations. This means that not all rows in the failed batch will necessarily be ignored. If other rows in the batch were the ones causing the exception, the "good" rows might end up in a different batch that doesn't fail in future invocations.
758
+
If the function execution fails five times in a row for a given row then that row is completely ignored for all future changes. Because the rows in a batch aren't deterministic, rows in a failed batch might end up in different batches in subsequent invocations. This means that not all rows in the failed batch will necessarily be ignored. If other rows in the batch were the ones causing the exception, the "good" rows might end up in a different batch that doesn't fail in future invocations.
0 commit comments