Skip to content

Commit 264e1eb

Browse files
committed
feat(PubSub): Add CreateTopicWithAwsMskIngestion sample
1 parent 4a9b7a7 commit 264e1eb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Google LLC.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* For instructions on how to run the full sample:
20+
*
21+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
22+
*/
23+
24+
namespace Google\Cloud\Samples\PubSub;
25+
26+
# [START pubsub_create_topic_with_aws_msk_ingestion]
27+
use Google\Cloud\PubSub\PubSubClient;
28+
29+
/**
30+
* Creates a Pub/Sub topic with AWS MSK ingestion.
31+
*
32+
* @param string $projectId The Google project ID.
33+
* @param string $topicName The Pub/Sub topic name.
34+
* @param string $clusterArn The Amazon Resource Name (ARN) that uniquely identifies the cluster.
35+
* @param string $mskTopic The name of the topic in the Amazon MSK cluster that Pub/Sub will import from.
36+
* @param string $awsRoleArn AWS role ARN to be used for Federated Identity authentication with Amazon MSK. Check the Pub/Sub docs for how to set up this role and the required permissions that need to be attached to it.
37+
* @param string $gcpServiceAccount The GCP service account to be used for Federated Identity authentication with Amazon MSK (via a AssumeRoleWithWebIdentity call for the provided role). The aws_role_arn must be set up with accounts.google.com:sub equals to this service account number.
38+
*/
39+
function create_topic_with_aws_msk_ingestion($projectId, $topicName, $clusterArn, $mskTopic, $awsRoleArn, $gcpServiceAccount)
40+
{
41+
$pubsub = new PubSubClient([
42+
'projectId' => $projectId,
43+
]);
44+
45+
$topic = $pubsub->createTopic($topicName, [
46+
'ingestionDataSourceSettings' => [
47+
'aws_msk' => [
48+
'cluster_arn' => $clusterArn,
49+
'topic' => $mskTopic,
50+
'aws_role_arn' => $awsRoleArn,
51+
'gcp_service_account' => $gcpServiceAccount
52+
]
53+
]
54+
]);
55+
56+
printf('Topic created: %s' . PHP_EOL, $topic->name());
57+
}
58+
# [END pubsub_create_topic_with_aws_msk_ingestion]
59+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
60+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)