Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Trigger di Remote Config Firebase
Le funzioni Cloud Run possono essere attivate in risposta alle modifiche in Firebase Remote Config nello stesso progetto Google Cloud della funzione. In questo modo, puoi modificare il comportamento e l'aspetto della tua app senza dover pubblicare un aggiornamento.
Tipi di evento
Firebase Remote Config può attivare funzioni in risposta all'eventoremoteconfig.update.
Tipo di evento
Trigger
remoteconfig.update
Si attiva quando il modello di configurazione remota viene aggiornato.
/** * Background Function triggered by a change to a Firebase Remote Config value. * * @param {object} event The Cloud Functions event. */exports.helloRemoteConfig=event=>{console.log(`Update type: ${event.updateType}`);console.log(`Origin: ${event.updateOrigin}`);console.log(`Version: ${event.versionNumber}`);};
Python
defhello_remote_config(data,context):"""Triggered by a change to a Firebase Remote Config value. Args: data (dict): The event payload. context (google.cloud.functions.Context): Metadata for the event. """print(f'Update type: {data["updateType"]}')print(f'Origin: {data["updateOrigin"]}')print(f'Version: {data["versionNumber"]}')
Vai
// Package helloworld provides a set of Cloud Functions samples.packagehelloworldimport("context""log")// A RemoteConfigEvent is an event triggered by Firebase Remote Config.typeRemoteConfigEventstruct{UpdateOriginstring`json:"updateOrigin"`UpdateTypestring`json:"updateType"`UpdateUserstruct{Emailstring`json:"email"`ImageURLstring`json:"imageUrl"`Namestring`json:"name"`}`json:"updateUser"`VersionNumberstring`json:"versionNumber"`}// HelloRemoteConfig handles Firebase Remote Config events.funcHelloRemoteConfig(ctxcontext.Context,eRemoteConfigEvent)error{log.Printf("Update type: %v",e.UpdateType)log.Printf("Origin: %v",e.UpdateOrigin)log.Printf("Version: %v",e.VersionNumber)returnnil}
Java
importcom.google.cloud.functions.Context;importcom.google.cloud.functions.RawBackgroundFunction;importcom.google.gson.Gson;importcom.google.gson.JsonObject;importjava.util.logging.Logger;publicclassFirebaseRemoteConfigimplementsRawBackgroundFunction{privatestaticfinalLoggerlogger=Logger.getLogger(FirebaseRemoteConfig.class.getName());// Use GSON (https://github.com/google/gson) to parse JSON content.privatestaticfinalGsongson=newGson();@Overridepublicvoidaccept(Stringjson,Contextcontext){JsonObjectbody=gson.fromJson(json,JsonObject.class);if(body!=null){if(body.has("updateType")){logger.info("Update type: "+body.get("updateType").getAsString());}if(body.has("updateOrigin")){logger.info("Origin: "+body.get("updateOrigin").getAsString());}if(body.has("versionNumber")){logger.info("Version: "+body.get("versionNumber").getAsString());}}}}
C#
usingCloudNative.CloudEvents;usingGoogle.Cloud.Functions.Framework;usingGoogle.Events.Protobuf.Firebase.RemoteConfig.V1;usingMicrosoft.Extensions.Logging;usingSystem.Threading;usingSystem.Threading.Tasks;namespaceFirebaseRemoteConfig;publicclassFunction:ICloudEventFunction<RemoteConfigEventData>{privatereadonlyILogger_logger;publicFunction(ILogger<Function>logger)=>
_logger=logger;publicTaskHandleAsync(CloudEventcloudEvent,RemoteConfigEventDatadata,CancellationTokencancellationToken){_logger.LogInformation("Update type: {origin}",data.UpdateType);_logger.LogInformation("Update origin: {origin}",data.UpdateOrigin);_logger.LogInformation("Version number: {version}",data.VersionNumber);// In this example, we don't need to perform any asynchronous operations, so the// method doesn't need to be declared async.returnTask.CompletedTask;}}
Ruby
require"functions_framework"# Triggered by a change to a Firebase Remote Config valueFunctionsFramework.cloud_event"hello_remote_config"do|event|# Event-triggered Ruby functions receive a CloudEvents::Event::V1 object.# See https://cloudevents.github.io/sdk-ruby/latest/CloudEvents/Event/V1.html# The Firebase event payload can be obtained from the event data.payload=event.datalogger.info"Update type: #{payload['updateType']}"logger.info"Origin: #{payload['updateOrigin']}"logger.info"Version: #{payload['versionNumber']}"end
Il nome registrato della funzione Cloud Run di cui stai eseguendo il deployment.
Può essere il nome di una funzione nel
codice sorgente o una stringa arbitraria. Se FUNCTION_NAME è una
stringa arbitraria, devi includere il
flag --entry-point.
--entry-point ENTRY_POINT
Il nome di una funzione o di una classe nel codice sorgente. Facoltativo, a meno che
non abbia utilizzato FUNCTION_NAME
per specificare la
funzione nel codice sorgente da eseguire durante il deployment. In questo
caso, devi utilizzare --entry-point per fornire il nome della
funzione eseguibile.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-04-03 UTC."],[[["Firebase Remote Config triggers allow Cloud Run functions to respond to changes in Firebase Remote Config, enabling dynamic app behavior and appearance updates without app store releases."],["The `remoteconfig.update` event type triggers functions whenever the Remote Config template is updated, providing real-time adaptability."],["Event data for Remote Config updates includes `updateType`, `updateOrigin`, and `versionNumber`, offering detailed information about the configuration change."],["Beta triggers for Remote Config may have evolving formats for CloudEvents, particularly in the `Source`, `Subject`, and data payload, so adaptations may be needed."],["Deploying functions with Firebase Remote Config triggers requires specifying `google.firebase.remoteconfig.update` as the trigger event, alongside the function name, entry point, and runtime environment."]]],[]]