-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
32 lines (30 loc) · 952 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\PubSub\PubSubClient;
/**
* Pulls all Pub/Sub messages for a subscription.
*
* @param string $projectId The Google project ID.
* @param string $subscriptionName The Pub/Sub subscription name.
*/
function pull_messages($projectId, $subscriptionName)
{
$pubsub = new PubSubClient([
'projectId' => $projectId,
]);
$subscription = $pubsub->subscription($subscriptionName);
foreach ($subscription->pull() as $message) {
printf('Message: %s' . PHP_EOL, $message->data());
echo "<br>";
// Acknowledge the Pub/Sub message has been received, so it will not be pulled multiple times.
$subscription->acknowledge($message);
}
}
for($i=0;$i<=10;$i++){
echo "<strong>PULL ".$i."</strong><br>";
pull_messages('incentro-spain-projects','poc-oscar-multiclient-sub');
echo "<br>";
flush();
ob_flush();
sleep(1);
}