Informationen zu den unterstützten Connectors für Application Integration.
Daten einer Aufgabe des Typs „Für alle parallel” in BigQuery einfügen
In dieser Anleitung erstellen Sie eine Anwendungsintegration und eine Subintegration, um eine Reihe von Datensätzen zu verarbeiten. Für jeden Datensatz ruft die Hauptintegration die Subintegration asynchron auf. Dabei werden die Daten für jeden Datensatz als Zeile in eine Tabelle in einem BigQuery-Dataset eingefügt.
In dieser Anleitung führen Sie die folgenden Aufgaben aus:
- BigQuery-Verbindung einrichten
- Subintegration einrichten
- Hauptintegration einrichten
- Integration testen
Hinweise
- Prüfen Sie, ob Sie Zugriff auf Application Integration haben.
-
Führen Sie in Ihrem Google Cloud-Projekt folgende Schritte aus:
- Weisen Sie dem Dienstkonto, das Sie zum Erstellen der Verbindung verwenden möchten, die folgenden Rollen zu:
roles/bigquery.dataEditor
roles/bigquery.readSessionUser
roles/secretmanager.viewer
roles/secretmanager.secretAccessor
- Aktivieren Sie die folgenden Dienste:
secretmanager.googleapis.com
(Secret Manager API)connectors.googleapis.com
(Connectors API)
Wenn diese Dienste für Ihr Projekt noch nicht aktiviert wurden, werden Sie beim Erstellen der Verbindung auf der Seite „Verbindung erstellen“ dazu aufgefordert.
- Weisen Sie dem Dienstkonto, das Sie zum Erstellen der Verbindung verwenden möchten, die folgenden Rollen zu:
BigQuery-Verbindung einrichten
Erstellen Sie zuerst das BigQuery-Dataset und die Tabelle für die Verwendung in dieser Anleitung. Nachdem Sie das Dataset und die Tabelle erstellt haben, erstellen Sie eine BigQuery-Verbindung. Sie verwenden diese Verbindung später in dieser Anleitung in einer Integration.
BigQuery-Dataset und -Tabelle einrichten
Führen Sie die folgenden Schritte aus, um das BigQuery-Dataset und die BigQuery-Tabelle einzurichten:
- Wählen Sie auf der Seite Cloud Console Ihr Google Cloud -Projekt aus.
- Klicken Sie zum Starten einer Cloud Shell-Sitzung in der Cloud Console auf das Symbol
Cloud Shell aktivieren. Dadurch wird im unteren Bereich der Google Cloud Console eine Sitzung gestartet.
-
Geben Sie die folgenden Befehle in Ihr Cloud Shell-Terminal ein, um BigQuery APIs zu aktivieren:
Ersetzen Sie in diesem Befehl Folgendes:export PROJECT_ID=project_id export REGION=region gcloud services enable --project "${PROJECT_ID}" \ bigquery.googleapis.com \ bigquerystorage.googleapis.com
project_id
durch die Projekt-ID Ihres Google Cloud Projekts.region
durch die Region, die Sie zum Erstellen Ihres BigQuery-Datasets verwenden möchten.
- Geben Sie den folgenden Befehl in Ihrem Cloud Shell-Terminal ein, um ein BigQuery-Dataset mit dem Namen
bq_tutorial
zu erstellen:bq --project_id ${PROJECT_ID} --location ${REGION} mk bq_tutorial
- Geben Sie den folgenden Befehl in Ihr Cloud Shell-Terminal ein, um eine BigQuery-Tabelle mit dem Namen
tutorial
zu erstellen:bq --project_id ${PROJECT_ID} \ query \ --nouse_legacy_sql \ 'create table bq_tutorial.tutorial ( unique_key STRING NOT NULL, created_date STRING, closed_date STRING, agency STRING, agency_name STRING, complaint_type STRING, descriptor STRING, location_type STRING, incident_zip STRING, incident_address STRING, street_name STRING, cross_street_1 STRING, cross_street_2 STRING, intersection_street_1 STRING, intersection_street_2 STRING, address_type STRING, city STRING, landmark STRING, facility_type STRING, status STRING, due_date STRING, resolution_action_updated_date STRING, community_board STRING, borough STRING, x_coordinate_state_plane STRING, y_coordinate_state_plane STRING, park_facility_name STRING, park_borough STRING, school_name STRING, school_number STRING, school_region STRING, school_code STRING, school_phone_number STRING, school_address STRING, school_city STRING, school_state STRING, school_zip STRING, school_not_found STRING, school_or_citywide_complaint STRING, vehicle_type STRING, taxi_company_borough STRING, taxi_pick_up_location STRING, bridge_highway_name STRING, bridge_highway_direction STRING, bridge_highway_segment STRING, road_ramp STRING, garage_lot_name STRING, ferry_direction STRING, ferry_terminal_name STRING, latitude STRING, longitude STRING, location STRING ) '
-
Verify that your BigQuery table is created.
- In the Cloud console page, click the Navigation menu.
- In the Analytics section, click BigQuery.
-
Expand your project and confirm that the
bq_tutorial
dataset is listed. -
Expand the bq_tutorial dataset and confirm that the
tutorial
table is listed. - Click the documents table to view the schema.
Create a BigQuery connection
Next, you'll create a BigQuery connection. A BigQuery connection lets you insert, read, update and delete rows in a BigQuery table and use the resulting output in an integration. After creating the BigQuery connection, you'll use this connection in an integration later in this tutorial to add rows to the BigQuery table.
To create a BigQuery connection, complete the following steps:
- In the Cloud console page, select your Google Cloud project.
- Open the connections page.
- Click + CREATE NEW to open the Create Connection page.
- Configure the connection:
- In the Create Connection section, complete the following:
- Connector: Select BigQuery from the drop down list of available Connectors.
- Connector version: Select the latest Connector version from the drop down list of available versions.
- In the Connection Name field, enter a name for the Connection instance. For this tutorial, enter connector-bq-tutorial.
- Optionally, add a Description of the connection instance.
- Service Account: Select a service account that has the required roles.
- Project ID: Enter the ID of the Google Cloud project where the BigQuery data resides.
- Dataset ID: Enter the ID of the BigQuery dataset that you want to use. For this tutorial, enter bq_tutorial.
- Optionally, click + ADD LABEL to add a label in the form of a key/value pair.
- Click Next.
- Location: Select a region from where the connection will run. Supported
regions for connectors include:
- Click Next.
For the list of all the supported regions, see Locations.
- Authentication: The BigQuery connection does not require authentication configuration. Click Next.
- Review: Review your connection's configuration details. In this section, the connection and authentication details of the new connection are displayed for your review.
- In the Create Connection section, complete the following:
- Click Create.
Set up a sub-integration
In this tutorial, the sub-integration takes each record sent to it by the main integration and inserts it as a row in the tutorial
table in the bq_tutorial
dataset.
Create a sub-integration
To create the sub-integration, complete the following steps:
- In the Google Cloud console, go to the Application Integration page.
- In the navigation menu, click Integrations. The Integrations page appears.
- Click Create integration.
- In the Create Integration dialog, do the following:
- Enter a name, for example, enter Process-each-record
- Optionally, enter a description. For example, enter API Trigger to process each record (sub-integration)
- Select the region where you want to create your integration.
- Click Create to open the integration editor.
Add an API Trigger
To add an API Trigger to the integration, do the following:
- In the integration editor, select Add a task/trigger > Triggers to display a list of available triggers.
- Drag the API Trigger element to the integration editor.
Add a Data Mapping task
To add a Data Mapping task in the integration, complete the following steps:
- Select +Add a task/trigger > Tasks in the integration editor to display the list of available tasks.
- Drag the Data Mapping element to the integration editor.
Configure the BigQuery connection
Now you are ready to use the BigQuery connection that you created earlier in the sub-integration. To configure the BigQuery connection in this integration, complete the following steps:
- Select +Add a task/trigger > Tasks in the integration editor to display the list of available tasks.
- Drag the Connectors element to the integration editor.
- Click the Connectors task element on the designer to view the task configuration pane.
- Click the edit icon on the right panel and update the Label to Insert row to BigQuery.
- Click Configure task.
The Configure connector task dialog appears.
- In the Configure connector task dialog, do the following:
- Select the connection region where you created your BigQuery connection.
- Select the BigQuery connection that you want to use. For this tutorial, select connector-bq-tutorial.
- Once a connection is chosen, the Type column appears. Select Entities and then tutorial from the list of available entities.
- Once a type is chosen, the Operation column appears. Select Create.
- Click Done to complete the connection configuration and close the dialog.
Connect the integration elements
Next, add edge connections to connect the API Trigger to the Data Mapping task and the Data Mapping task to the Connectors task. An edge connection is a connection between any two elements in an integration. For more information on edges and edge conditions, see Edges.
To add the edge connections, complete the following steps:
- Click the Fork control point at the bottom of the API Trigger element. Drag and drop the edge connection at the Join control point at the top of the Data Mapping element.
- Click the Fork control point at the bottom of the Data Mapping element. Drag and drop the edge connection at the Join control point at the top of the Connectors element.
Configure the Data Mapping task
To configure the Data Mapping task, complete the following steps:
- In the integration editor, click the Data Mapping task to view the task configuration pane.
- Click Open Data Mapping Editor.
- In the Data Mapping Editor, click Add to add a new variable.
- In the Create Variable dialog, enter the following information:
- Name: Enter record.
- Data Type: Select JSON.
-
Schema: Select Infer from a sample JSON payload. Enter the following sample JSON payload:
{ "unique_key":"304271", "created_date":"02/06/2007 12:00:00 AM", "closed_date":"03/01/2007 12:00:00 AM", "agency":"TLC", "agency_name":"Taxi and Limousine Commission", "complaint_type":"Taxi Complaint", "descriptor":"Driver Complaint", "location_type":"Street", "incident_zip":"10001", "incident_address":"", "street_name":"", "cross_street_1":"", "cross_street_2":"", "intersection_street_1":"WEST 29 STREET", "intersection_street_2":"7 AVENUE", "address_type":"INTERSECTION", "city":"NEW YORK", "landmark":"", "facility_type":"N/A", "status":"Closed", "due_date":"02/28/2007 12:00:00 AM", "resolution_action_updated_date":"03/01/2007 12:00:00 AM", "community_board":"05 MANHATTAN", "borough":"MANHATTAN", "x_coordinate_state_plane":"986215", "y_coordinate_state_plane":"211740", "park_facility_name":"", "park_borough":"MANHATTAN", "school_name":"", "school_number":"", "school_region":"", "school_code":"", "school_phone_number":"", "school_address":"", "school_city":"", "school_state":"", "school_zip":"", "school_not_found":"", "school_or_citywide_complaint":"", "vehicle_type":"", "taxi_company_borough":"", "taxi_pick_up_location":"Other", "bridge_highway_name":"", "bridge_highway_direction":"", "road_ramp":"", "bridge_highway_segment":"", "garage_lot_name":"", "ferry_direction":"", "ferry_terminal_name":"", "latitude":"40.74785373937869", "longitude":"-73.99290823133913", "location":"(40.74785373937869, -73.99290823133913)" }
- Klicken Sie auf Erstellen.
- Führen Sie nach der Erstellung der Variable im Data Mapping Editor die folgenden Schritte aus:
- Ziehen Sie die neue Variable Datensatz in die Spalte Input.
- Ziehen Sie die Variable connectorInputPayload in die Spalte Ausgabe.
- Schließen Sie den Datenabgleichseditor, um zum Integrationseditor zurückzukehren.
Subintegration veröffentlichen
Um die Subintegration zu veröffentlichen, klicken Sie im Integrationseditor auf Veröffentlichen.
Hauptintegration einrichten
In diesem Abschnitt richten Sie die Hauptintegration ein, die die Aufgabe Für alle parallel verwendet, um jeden Datensatz zu verarbeiten. Diese Hauptintegration ruft dann die Subintegration für jeden Eintrag einmal auf.
Hauptintegration erstellen
Führen Sie die folgenden Schritte aus, um die Hauptintegration zu erstellen:
- Rufen Sie in der Google Cloud Console die Seite Application Integration auf.
- Klicken Sie im Navigationsmenü auf Integrationen. Die Seite Integrationen wird angezeigt.
- Klicken Sie auf Integration erstellen.
- Führen Sie im Dialogfeld Integration erstellen die folgenden Aufgaben aus:
- Geben Sie einen Namen ein, z. B. Process-each-record.
- Geben Sie optional unter Beschreibung eine Beschreibung ein. Geben Sie beispielsweise API Trigger zum Verarbeiten von Einträgen (Hauptintegration) ein.
- Wählen Sie die Region aus, in der Sie die Integration erstellen möchten.
- Klicken Sie auf Erstellen, um den Integrationseditor zu öffnen.
API-Trigger hinzufügen
So fügen Sie der Integration einen API-Trigger hinzu:
- Wählen Sie im Integrationseditor Aufgabe/Trigger hinzufügen > Trigger aus, um eine Liste der verfügbaren Trigger aufzurufen.
- Ziehen Sie das Element API-Trigger in den Integrationseditor.
Aufgabe „Für alle parallel“ hinzufügen
So fügen Sie der Integration die Aufgabe „Für jede Parallele“ hinzu:
- Wählen Sie im Integrationseditor Aufgabe/Trigger hinzufügen > Aufgaben aus, um die Liste der verfügbaren Aufgaben aufzurufen.
- Ziehen Sie das Element Für alle parallel in den Integrationseditor.
Integrationselemente verbinden
Fügen Sie als Nächstes eine Edge-Verbindung hinzu, um den API-Trigger mit der Aufgabe „Für jede parallele“ zu verbinden.
Klicken Sie unten im API-Trigger-Element auf den Steuerungspunkt Fork, um die Edge-Verbindung hinzuzufügen. Ziehen Sie die Edge-Verbindung per Drag-and-drop am Steuerpunkt Join oben im Element „Für jede parallele Aufgabe“.
Aufgabe „Für alle parallel” konfigurieren
Führen Sie die folgenden Schritte aus, um die Aufgabe „Für jede parallele“ zu konfigurieren:
- Klicken Sie im Integrationseditor auf die Aufgabe Für jede parallele, um den Aufgabenkonfigurationsbereich anzuzeigen.
- Klicken Sie unter Arrayauswahl > Liste für Iteration auf Neue Variable hinzufügen, um eine neue Variable hinzuzufügen.
- Geben Sie im Dialogfeld Variable erstellen die folgenden Informationen ein:
- Name: Geben Sie
records
ein. - Datentyp: Wählen Sie JSON aus.
-
Schema: Wählen Sie Aus einer JSON-Beispielnutzlast ableiten aus. Geben Sie die folgende Beispiel-JSON-Nutzlast ein:
[{ "unique_key":"304271", "created_date":"02/06/2007 12:00:00 AM", "closed_date":"03/01/2007 12:00:00 AM", "agency":"TLC", "agency_name":"Taxi and Limousine Commission", "complaint_type":"Taxi Complaint", "descriptor":"Driver Complaint", "location_type":"Street", "incident_zip":"10001", "incident_address":"", "street_name":"", "cross_street_1":"", "cross_street_2":"", "intersection_street_1":"WEST 29 STREET", "intersection_street_2":"7 AVENUE", "address_type":"INTERSECTION", "city":"NEW YORK", "landmark":"", "facility_type":"N/A", "status":"Closed", "due_date":"02/28/2007 12:00:00 AM", "resolution_action_updated_date":"03/01/2007 12:00:00 AM", "community_board":"05 MANHATTAN", "borough":"MANHATTAN", "x_coordinate_state_plane":"986215", "y_coordinate_state_plane":"211740", "park_facility_name":"", "park_borough":"MANHATTAN", "school_name":"", "school_number":"", "school_region":"", "school_code":"", "school_phone_number":"", "school_address":"", "school_city":"", "school_state":"", "school_zip":"", "school_not_found":"", "school_or_citywide_complaint":"", "vehicle_type":"", "taxi_company_borough":"", "taxi_pick_up_location":"Other", "bridge_highway_name":"", "bridge_highway_direction":"", "road_ramp":"", "bridge_highway_segment":"", "garage_lot_name":"", "ferry_direction":"", "ferry_terminal_name":"", "latitude":"40.74785373937869", "longitude":"-73.99290823133913", "location":"(40.74785373937869, -73.99290823133913)" }]
- Name: Geben Sie
- Klicken Sie auf Erstellen.
- Geben Sie im Abschnitt Details zur Teilintegration die folgenden Informationen ein:
- API Trigger-ID: Wählen Sie das API-Trigger-Element in der Sub-Integration aus. Wählen Sie beispielsweise Process-each-record_API_1 aus.
- Ausführungsstrategie: Wählen Sie ASYNC.
- Wählen Sie Einzelne Einbindung ausführen.
- Geben Sie im Abschnitt Bei jeder Ausführung für Wo einzelne Arrayelemente zuzuordnen sind den Namen der Variablen in der Datenzuordnungsaufgabe in die Subintegration ein. Geben Sie in diesem Fall record ein. Die Variablen der Subintegration werden nur für veröffentlichte Integrationen aufgeführt. Sind die Variablen nicht aufgeführt, aktualisieren Sie die Seite, da es einige Zeit dauert, bis die Variablen nach der Veröffentlichung der Subintegration sichtbar werden.
Hauptintegration veröffentlichen
Um die Hauptintegration zu veröffentlichen, klicken Sie im Integrationseditor auf Veröffentlichen.
Integration testen
Mit den folgenden Schritten testen Sie Ihre Integration:
- Laden Sie Beispieldaten in Cloud Shell herunter:
- Klicken Sie zum Starten einer Cloud Shell-Sitzung in der Cloud Console auf das Symbol
Cloud Shell aktivieren. Dadurch wird im unteren Bereich der Google Cloud Console eine Sitzung gestartet.
- Geben Sie den folgenden Befehl in Ihr Cloud Shell-Terminal ein:
wget https://raw.githubusercontent.com/GoogleCloudPlatform/application-integration-samples/main/assets/bq-sample-dataset.json
- Geben Sie den folgenden Befehl in Ihrem Cloud Shell-Terminal ein, um zu prüfen, ob die Beispieldaten heruntergeladen wurden:
Die heruntergeladene Datei wird im Cloud Shell-Terminal aufgelistet.ls -la bq-sample-dataset.json
- Klicken Sie zum Starten einer Cloud Shell-Sitzung in der Cloud Console auf das Symbol
- Wenn Sie drei zufällige Einträge aus dem Beispiel-Dataset auswählen und so speichern möchten, dass sie an die Integration übergeben werden können, geben Sie die folgenden Befehle in Ihr Cloud Shell-Terminal ein:
AUTH=$(gcloud auth print-access-token) export SAMPLE_DOCS=$(jq $(r=$((RANDOM % 1000)) ; echo ".[$r:$((r + 3))]") < bq-sample-dataset.json | jq -Rs '.') generate_post_data() { cat <<EOF { "triggerId": "api_trigger/process-records_API_1", "inputParameters": { "records": { "jsonValue": $SAMPLE_DOCS } } } EOF }
- Geben Sie den folgenden Befehl in Ihr Cloud Shell-Terminal ein, um den Test zu starten:
Ersetzen Sie in diesem Befehl Folgendes:curl -X POST \ https://integrations.googleapis.com/v1/projects/project_id/locations/region/integrations/process-records:execute \ -H "Authorization: Bearer $AUTH" \ -H "Content-Type: application/json" \ -d "$(generate_post_data)"
project_id
durch die Projekt-ID Ihres Projekts. Google Cloudregion
durch die Region, in der Sie die Integration erstellt haben.
- Um zu prüfen, ob Ihre BigQuery-Tabelle jetzt diese Einträge enthält, führen Sie die folgenden Schritte aus:
- Klicken Sie auf der Seite der Cloud Console auf das Navigationsmenü .
- Klicken Sie im Abschnitt Analytics auf BigQuery.
-
Maximieren Sie Ihr Projekt und klicken Sie auf das Dataset
bq_tutorial
. -
Maximieren Sie das Dataset bq_tutorial und klicken Sie auf die Tabelle
tutorial
. - Klicken Sie auf den Tab Tabellen-Explorer, um die eingefügten Datensätze anzusehen.
Nächste Schritte
Integrationen mit anderen Connectors erstellen. Eine Liste aller unterstützten Connectors finden Sie in der Connector-Referenz.