Un pipeline connecte un bus à une destination cible et achemine les messages d'événement vers cette destination. Vous pouvez configurer un pipeline pour qu'il attende des données d'événement dans un format spécifique. Vous pouvez également convertir les données d'événement d'un format compatible à un autre avant de les distribuer à une destination. Par exemple, vous devrez peut-être acheminer des événements vers un point de terminaison qui n'accepte que les données Avro.
Formats compatibles
Les conversions entre les formats suivants sont possibles :
Avro vers JSON
Avro vers Protobuf
JSON vers Avro
JSON vers Protobuf
Protobuf vers Avro
Protobuf vers JSON
Veuillez noter les points suivants :
Lorsque vous convertissez le format des événements, seule la charge utile de l'événement est convertie, et non l'ensemble du message d'événement.
Si un format de données entrantes est spécifié pour un pipeline, tous les événements doivent correspondre à ce format. Tous les événements qui ne correspondent pas au format attendu sont traités comme des erreurs persistantes.
Si aucun format de données entrantes n'est spécifié pour un pipeline, aucun format de données sortantes ne peut être défini.
Avant qu'un format d'événement ne soit converti pour une destination spécifique, toute transformation de données configurée est appliquée en premier.
Les schémas JSON sont détectés de manière dynamique. Pour les définitions de schéma Protobuf, vous ne pouvez définir qu'un seul type de premier niveau. Les instructions d'importation qui font référence à d'autres types ne sont pas acceptées. Les définitions de schéma sans identifiant syntax sont définies par défaut sur proto2. Notez qu'il existe une limite de taille pour le schéma.
Configurer un pipeline pour mettre en forme les événements
Vous pouvez configurer un pipeline pour qu'il attende des données d'événement dans un format spécifique ou pour qu'il convertisse les données d'événement d'un format à un autre dans la console Google Cloud ou à l'aide de la gcloud CLI.
Console
Dans la console Google Cloud , accédez à la page Eventarc>Pipelines.
Vous pouvez créer un pipeline ou, si vous mettez à jour un pipeline, cliquez sur son nom.
Sur la page Détails du pipeline, cliquez sur
editModifier.
Dans le volet Médiation d'événements, procédez comme suit :
Cochez la case Appliquer une transformation.
Dans la liste Format d'entrée, sélectionnez le format applicable.
Notez que si un format de données entrantes est spécifié pour un pipeline, tous les événements doivent correspondre à ce format. Tous les événements qui ne correspondent pas au format attendu sont traités comme des erreurs persistantes.
Pour les formats Avro ou Protobuf, vous devez spécifier un schéma d'entrée.
(Vous pouvez également importer un schéma d'entrée au lieu de le spécifier directement.)
Dans le champ Expression CEL, écrivez une expression de transformation en CEL.
Cliquez sur Continuer.
Dans le volet Destination, procédez comme suit :
Le cas échéant, sélectionnez un format dans la liste Format de sortie.
Notez que si un format de données entrantes n'est pas spécifié pour un pipeline, un format sortant ne peut pas être défini.
Facultatif : Appliquez une liaison de message. Pour en savoir plus, consultez Liaison de messages.
Cliquez sur Enregistrer.
La mise à jour d'un pipeline peut prendre quelques minutes.
Vous pouvez également définir la propriété d'emplacement de gcloud CLI :
gcloudconfigseteventarc/locationREGION
INPUT_PAYLOAD_FLAG : indicateur de format de données d'entrée, qui peut être l'un des suivants :
--input-payload-format-avro-schema-definition
--input-payload-format-json
--input-payload-format-protobuf-schema-definition
Notez que si un format de données d'entrée est spécifié pour un pipeline, tous les événements doivent correspondre à ce format. Tous les événements qui ne correspondent pas au format attendu sont traités comme des erreurs persistantes.
OUTPUT_PAYLOAD_KEY : clé de format de données de sortie, qui peut être l'une des suivantes :
output_payload_format_avro_schema_definition
output_payload_format_json
output_payload_format_protobuf_schema_definition
Notez que si vous définissez une clé de format de données de sortie, vous devez également spécifier un indicateur de format de données d'entrée.
La mise à jour d'un pipeline peut prendre quelques minutes.
Exemples :
L'exemple suivant utilise un indicateur --input-payload-format-protobuf-schema-definition pour spécifier que le pipeline doit s'attendre à des événements au format de données Protobuf avec un schéma spécifique :
L'exemple suivant utilise une clé output_payload_format_avro_schema_definition et un indicateur --input-payload-format-avro-schema-definition pour créer un pipeline qui attend des événements au format Avro et les génère dans le même format :
L'exemple suivant utilise une clé output_payload_format_protobuf_schema_definition et un indicateur --input-payload-format-avro-schema-definition pour mettre à jour un pipeline et convertir ses données d'événement d'Avro en Protobuf à l'aide de définitions de schéma :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/10 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/10 (UTC)."],[[["\u003cp\u003eEventarc Advanced, currently in pre-GA, allows you to configure pipelines to manage the format of event data, including converting between Avro, JSON, and Protobuf.\u003c/p\u003e\n"],["\u003cp\u003ePipelines can be set up to expect a specific inbound data format, and all incoming events must match this format, or they will be treated as persistent errors.\u003c/p\u003e\n"],["\u003cp\u003eWhen converting event formats, only the payload is transformed, not the entire event message, and inbound and outbound schema formats must be specified appropriately.\u003c/p\u003e\n"],["\u003cp\u003eYou can configure pipelines and manage event format conversion through the Google Cloud console or the gcloud CLI, noting that updating a pipeline may take over 10 minutes.\u003c/p\u003e\n"],["\u003cp\u003ePipelines can be set to use data transformations prior to the formatting of the data, and the formatted data can be sent with a CloudEvents format, unless a message binding is specified.\u003c/p\u003e\n"]]],[],null,["# Format received events\n\n[Advanced](/eventarc/advanced/docs/overview)\n\nA pipeline connects a bus to a target destination, and routes event messages to\nthat destination. You can configure a pipeline to expect event data in a\nspecific format or, before events are delivered to a destination, you can\nconvert event data from one supported format to another. For example, you might\nneed to route events to an endpoint that only accepts Avro data.\n\nSupported formats\n-----------------\n\nThe following format conversions are supported:\n\n- Avro to JSON\n- Avro to Protobuf\n- JSON to Avro\n- JSON to Protobuf\n- Protobuf to Avro\n- Protobuf to JSON\n\n#### Note the following:\n\n- When you convert the format of events, *only* the event payload is converted\n and not the entire event message.\n\n- If an inbound data format is specified for a pipeline, all events must match\n that format. Any events that don't match the expected format are treated as\n [persistent errors](/eventarc/advanced/docs/retry-events#persistent).\n\n- If an inbound data format is *not* specified for a pipeline, an outbound\n format *can't* be set.\n\n- Before an event format is converted for a specific destination, any\n [data transformation](/eventarc/advanced/docs/receive-events/transform-events)\n that is configured is applied first.\n\n- Events are always delivered in a\n [CloudEvents format using an HTTP request in binary content mode](/eventarc/docs/cloudevents)\n unless you specify a [message binding](/eventarc/advanced/docs/receive-events/transform-events#message-binding).\n\n- JSON schemas are detected dynamically. For Protobuf schema definitions, you\n can define only one top-level type and import statements that refer to other\n types are not supported. Schema definitions without a `syntax` identifier\n default to `proto2`. Note that there is a\n [schema size limit](/eventarc/docs/quotas#limits).\n\nConfigure a pipeline to format events\n-------------------------------------\n\nYou can configure a pipeline to expect event data in a specific format, or to\nconvert event data from one format to another, in the Google Cloud console or by\nusing the gcloud CLI. \n\n### Console\n\n1. In the Google Cloud console, go to the **Eventarc**\n \\\u003e **Pipelines** page.\n\n\n [Go to Pipelines](https://console.cloud.google.com/eventarc/pipelines)\n\n \u003cbr /\u003e\n\n2. You can [create a pipeline](/eventarc/advanced/docs/receive-events/create-enrollment#console)\n or, if you are updating a pipeline, click the name of the pipeline.\n\n3. In the **Pipeline details** page, click\n edit\n **Edit**.\n\n4. In the **Event mediation** pane, do the following:\n\n 1. Select the **Apply a transformation** checkbox.\n 2. In the **Inbound format** list, select the applicable format.\n\n Note that if an inbound data format is specified for a pipeline, all\n events must match that format. Any events that don't match the\n expected format are treated as\n [persistent errors](/eventarc/advanced/docs/retry-events#persistent).\n 3. For Avro or Protobuf formats, you must specify an inbound schema.\n (Optionally, instead of specifying it directly, you can upload an inbound\n schema.)\n\n 4. In the **CEL expression** field, write a transformation expression\n [using CEL](/eventarc/advanced/docs/receive-events/use-cel).\n\n 5. Click **Continue**.\n\n5. In the **Destination** pane, do the following:\n\n 1. If applicable, in the **Outbound format** list, select a format.\n\n Note that if an inbound data format is *not* specified for a pipeline,\n an outbound format *can't* be set.\n 2. Optional: Apply a **Message binding** . For more information, see\n [Message binding](/eventarc/advanced/docs/receive-events/transform-events#message-binding).\n\n6. Click **Save**.\n\n It can take a couple of minutes to update a pipeline.\n\n### gcloud\n\n1. Open a terminal.\n\n2. You can [create a pipeline](/eventarc/advanced/docs/receive-events/create-enrollment#gcloud)\n or you can update a pipeline using the\n [`gcloud eventarc pipelines update`](/sdk/gcloud/reference/eventarc/pipelines/update)\n command:\n\n ```bash\n gcloud eventarc pipelines update PIPELINE_NAME \\\n --location=REGION \\\n --INPUT_PAYLOAD_FLAG \\\n --destinations=OUTPUT_PAYLOAD_KEY\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePIPELINE_NAME\u003c/var\u003e: the ID of the pipeline or a fully qualified name\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: a\n [supported Eventarc Advanced location](/eventarc/docs/locations#advanced-regions)\n\n Alternatively, you can set the gcloud CLI location\n property: \n\n gcloud config set eventarc/location \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\n\n - \u003cvar translate=\"no\"\u003eINPUT_PAYLOAD_FLAG\u003c/var\u003e: an input data format\n flag that can be one of the following:\n\n - `--input-payload-format-avro-schema-definition`\n - `--input-payload-format-json`\n - `--input-payload-format-protobuf-schema-definition`\n\n Note that if an input data format is specified for a pipeline, all\n events must match that format. Any events that don't match the\n expected format are treated as\n [persistent errors](/eventarc/advanced/docs/retry-events#persistent).\n - \u003cvar translate=\"no\"\u003eOUTPUT_PAYLOAD_KEY\u003c/var\u003e: an output data format key\n that can be one of the following:\n\n - `output_payload_format_avro_schema_definition`\n - `output_payload_format_json`\n - `output_payload_format_protobuf_schema_definition`\n\n Note that if you set an output data format key, you must also\n specify an input data format flag.\n\n It can take a couple of minutes to update a pipeline.\n\n ### Examples:\n\n The following example use an\n `--input-payload-format-protobuf-schema-definition` flag to specify that\n the pipeline should expect events in a Protobuf data format with a\n specific schema: \n\n ```bash\n gcloud eventarc pipelines update my-pipeline \\\n --input-payload-format-protobuf-schema-definition \\\n '\n syntax = \"proto3\";\n message schema {\n string name = 1;\n string severity = 2;\n }\n '\n ```\n\n The following example uses an\n `output_payload_format_avro_schema_definition` key and an\n `--input-payload-format-avro-schema-definition` flag to create a\n pipeline that expects events in an Avro format and outputs them in the\n same format: \n\n ```bash\n gcloud eventarc pipelines create my-pipeline \\\n --location=us-central1 \\\n --destinations=http_endpoint_uri='https://example-endpoint.com',output_payload_format_avro_schema_definition='{\"type\": \"record\", \"name\": \"my_record\", \"fields\": [{\"name\": \"my_field\", \"type\": \"string\"}]}' \\\n --input-payload-format-avro-schema-definition='{\"type\": \"record\", \"name\": \"my_record\", \"fields\": [{\"name\": \"my_field\", \"type\": \"string\"}]}'\n ```\n\n The following example uses an\n `output_payload_format_protobuf_schema_definition` key and an\n `--input-payload-format-avro-schema-definition` flag to update a\n pipeline and convert its event data from Avro to Protobuf using schema\n definitions: \n\n ```bash\n gcloud eventarc pipelines update my-pipeline \\\n --location=us-central1 \\\n --destinations=output_payload_format_protobuf_schema_definition='message MessageProto {string prop1 = 1; string prop2 = 2;}' \\\n --input-payload-format-avro-schema-definition= \\\n '\n {\n \"type\": \"record\",\n \"name\": \"MessageProto\",\n \"fields\": [\n { \"name\" : \"prop1\", \"type\": \"string\" },\n { \"name\" : \"prop2\", \"type\": \"string\" },\n ]\n }\n '\n ```"]]