Skip to content

Commit

Permalink
fix: add callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta committed Jan 3, 2024
1 parent 17e221c commit ad52a0f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/topic-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function printBanner(string $message, LoggerInterface $logger): void
$logger->info("Subscribing to topic: $TOPIC_NAME\n");
$callback = function ($message) use ($logger) {
$logger->info("Received message: " . json_encode($message));
file_put_contents('message_received.flag', '1');
};
$response = $topicClient->subscribe($CACHE_NAME, $TOPIC_NAME, $callback);
if ($response->asSuccess()) {
Expand All @@ -65,6 +66,11 @@ function printBanner(string $message, LoggerInterface $logger): void
exit(1);
}

// Wait for a message to be received and logged
while (!file_exists('message_received.flag')) {
sleep(1); // Sleep for 1 second before checking again
}


// Delete test cache
//$logger->info("Deleting cache $CACHE_NAME\n");
Expand Down

0 comments on commit ad52a0f

Please sign in to comment.