revealit / laravel-azure-sdk
A PHP Laravel wrapper for the Microsoft Azure REST API
Requires
- php: ^8.1
- sammyjo20/saloon: ^1.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- spatie/laravel-ray: ^1.26
README
This package aims to wrap the Azure REST API.
At the moment, the following is supported:
Service Bus
- Push messages into a queue
Installation
You can install the package via composer:
composer require revealit/laravel-azure-sdk
You can publish the config file with:
php artisan vendor:publish
and then entering the number of the ServiceProvider
This is the contents of the published config file:
return [ /* * The Application (client) ID */ "client_id" => "", /* * Directory (tenant) ID */ "tenant_id" => "", /* * The apps secret value. This value is only visible immediately after creation, * so be sure to note it down. */ "client_secret_value" => "" /* * The default service bus to use. */ "default_service_bus_namespace" => "" ];
Usage
Edit azure-sdk.php
in the Laravel config
folder, and enter your Apps keys and secret.
use Revealit\AzureSdk\Facades\AzureSdk; // Define an array $message = [ "title" => "Hello World!" ]; // Send a message to a queue return AzureSdk::pushToQueue("test_queue", $message)->status();
This will generate a token and send a message to the queue specified in the first parameter.
You can also send a message to a different service bus:
use Revealit\AzureSdk\Facades\AzureSdk; // Send a message to a queue in a different service bus return AzureSdk::pushToQueue("test_queue", ["msg" => "Hello World!"], "different_service_bus")->status();
If you want to send multiple messages, you can generate a token first and pass it in as an optional forth parameter:
use Revealit\AzureSdk\Facades\AzureSdk; $token = AzureSdk::getAPIToken(); $serviceBus = config("azure-sdk.default_service_bus_namespace"); $message1 = ["url" => "https:www.github.com"]; // Send messages to different queues using the same token AzureSdk::pushToQueue("test_queue", $message1, $serviceBus, $token)->status(); AzureSdk::pushToQueue("test_queue_2", ["title" => "Azure SDK"], $serviceBus, $token)->status();
Credits
License
The MIT License (MIT). Please see License File for more information.