PHP code example of alesima / laravel-azure-service-bus
1. Go to this page and download the library: Download alesima/laravel-azure-service-bus library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alesima / laravel-azure-service-bus example snippets
$app->bind(Illuminate\Queue\QueueManager::class, function ($app) {
return $app['queue'];
});
use App\Jobs\MyJob;
dispatch(new MyJob($data)); // Push to the default queue
dispatch((new MyJob($data))->delay(60)); // Delay by 60 seconds
$interval = new \DateInterval('PT10M'); // 10 minutes
dispatch((new MyJob($data))->delay($interval));
$releaseTime = new \DateTime('+1 hour');
dispatch((new MyJob($data))->delay($releaseTime));
public function handle()
{
// Your job logic here
}
use LaravelAzureServiceBus\Services\AzurePubSubService;
$pubSub = app(AzurePubSubService::class);
// Publish to a specific topic
$pubSub->publishMessage('topic1', [
'event' => 'user.created',
'data' => ['user_id' => 123],
]);
use LaravelAzureServiceBus\Services\AzurePubSubService;
$pubSub = app(AzurePubSubService::class);
// Subscribe to messages from 'topic1'
$messages = $pubSub->retrieveMessages('topic1', 'subscription1');
foreach ($messages as $message) {
echo $message; // Process the message
}
use LaravelAzureServiceBus\Services\AzurePubSubService;
$pubSub = app(AzurePubSubService::class);
// Retrieve messages from multiple topics
$topics = ['topic1', 'topic2', 'topic3'];
foreach ($topics as $topic) {
$messages = $pubSub->retrieveMessages($topic, 'subscription1');
foreach ($messages as $message) {
echo "From {$topic}: " . $message;
}
}