Membuat AppProfile
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Buat AppProfile.
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code samples in C++ and PHP for creating an AppProfile in Google Cloud Bigtable.\u003c/p\u003e\n"],["\u003cp\u003eThe C++ code demonstrates creating an AppProfile with multi-cluster routing, while the PHP code showcases how to create an AppProfile with single-cluster routing, including setting its cluster ID and specifying whether transactional writes are allowed.\u003c/p\u003e\n"],["\u003cp\u003eBoth code samples require users to set up Application Default Credentials for authentication and refer to the Bigtable client libraries for installation instructions.\u003c/p\u003e\n"],["\u003cp\u003eThe PHP example also includes error handling for cases where an AppProfile with the given ID already exists.\u003c/p\u003e\n"],["\u003cp\u003eA link to the Google Cloud sample browser is provided for users to search for code samples for other products.\u003c/p\u003e\n"]]],[],null,["Create an AppProfile.\n\nCode sample \n\nC++\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n namespace cbt = ::google::cloud::bigtable;\n namespace cbta = ::google::cloud::bigtable_admin;\n using ::google::cloud::StatusOr;\n [](cbta::BigtableInstanceAdminClient instance_admin,\n std::string const& project_id, std::string const& instance_id,\n std::string const& profile_id) {\n std::string instance_name = cbt::InstanceName(project_id, instance_id);\n\n google::bigtable::admin::v2::AppProfile ap;\n ap.mutable_multi_cluster_routing_use_any()-\u003eClear();\n\n StatusOr\u003cgoogle::bigtable::admin::v2::AppProfile\u003e profile =\n instance_admin.CreateAppProfile(instance_name, profile_id,\n std::move(ap));\n if (!profile) throw std::move(profile).status();\n std::cout \u003c\u003c \"New profile created with name=\" \u003c\u003c profile-\u003ename() \u003c\u003c \"\\n\";\n }\n\nPHP\n\n\nTo learn how to install and use the client library for Bigtable, see\n[Bigtable client libraries](/bigtable/docs/reference/libraries).\n\n\nTo authenticate to Bigtable, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\ApiCore\\ApiException;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\AppProfile;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\AppProfile\\SingleClusterRouting;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\Client\\BigtableInstanceAdminClient;\n use Google\\Cloud\\Bigtable\\Admin\\V2\\CreateAppProfileRequest;\n\n /**\n * Create an App Profile\n *\n * @param string $projectId The Google Cloud project ID\n * @param string $instanceId The ID of the Bigtable instance\n * @param string $clusterId The ID of the cluster where the new App Profile will route it's requests(in case of single cluster routing)\n * @param string $appProfileId The ID of the App Profile to create\n */\n function create_app_profile(\n string $projectId,\n string $instanceId,\n string $clusterId,\n string $appProfileId\n ): void {\n $instanceAdminClient = new BigtableInstanceAdminClient();\n $instanceName = $instanceAdminClient-\u003einstanceName($projectId, $instanceId);\n\n $appProfile = new AppProfile([\n 'name' =\u003e $appProfileId,\n 'description' =\u003e 'Description for this newly created AppProfile'\n ]);\n\n // create a new routing policy\n // allow_transactional_writes refers to Single-Row-Transactions(https://cloud.google.com/bigtable/docs/app-profiles#single-row-transactions)\n $routingPolicy = new SingleClusterRouting([\n 'cluster_id' =\u003e $clusterId,\n 'allow_transactional_writes' =\u003e false\n ]);\n\n // set the newly created routing policy to our app profile\n $appProfile-\u003esetSingleClusterRouting($routingPolicy);\n\n // we could also create a multi cluster routing policy like so:\n // $routingPolicy = new \\Google\\Cloud\\Bigtable\\Admin\\V2\\AppProfile\\MultiClusterRoutingUseAny();\n // $appProfile-\u003esetMultiClusterRoutingUseAny($routingPolicy);\n\n printf('Creating a new AppProfile %s' . PHP_EOL, $appProfileId);\n\n try {\n $createAppProfileRequest = (new CreateAppProfileRequest())\n -\u003esetParent($instanceName)\n -\u003esetAppProfileId($appProfileId)\n -\u003esetAppProfile($appProfile);\n $newAppProfile = $instanceAdminClient-\u003ecreateAppProfile($createAppProfileRequest);\n } catch (ApiException $e) {\n if ($e-\u003egetStatus() === 'ALREADY_EXISTS') {\n printf('AppProfile %s already exists.', $appProfileId);\n return;\n }\n throw $e;\n }\n\n printf('AppProfile created: %s', $newAppProfile-\u003egetName());\n }\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=bigtable)."]]