PHPackages                             marmanik/laravel-azure-service-bus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. marmanik/laravel-azure-service-bus

ActiveLibrary[Queues &amp; Workers](/categories/queues)

marmanik/laravel-azure-service-bus
==================================

A Laravel package to publish and consume messages from Azure Service Bus queues and topics via the REST API

1.15(1mo ago)07↑2900%MITPHPPHP ^8.2

Since Mar 28Pushed 1mo agoCompare

[ Source](https://github.com/marmanik/laravel-azure-service-bus)[ Packagist](https://packagist.org/packages/marmanik/laravel-azure-service-bus)[ Docs](https://github.com/nmarmaridis/laravel-azure-service-bus)[ RSS](/packages/marmanik-laravel-azure-service-bus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (10)Versions (9)Used By (0)

Laravel Azure Service Bus
=========================

[](#laravel-azure-service-bus)

[![run-tests](https://github.com/marmanik/laravel-azure-service-bus/actions/workflows/run-tests.yml/badge.svg)](https://github.com/marmanik/laravel-azure-service-bus/actions/workflows/run-tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/8281ebc5965972df8a3f4b683fc0e2184e9d19346602dfd61d914fd0abbbec33/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4d61726d614e696b2f6c61726176656c2d617a7572652d736572766963652d6275732e737667)](https://packagist.org/packages/MarmaNik/laravel-azure-service-bus)[![License](https://camo.githubusercontent.com/95ff4bc42106922bba39893d99c847c609f74ea933062db42b39855d5ce8d3e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f4d61726d614e696b2f6c61726176656c2d617a7572652d736572766963652d6275732e737667)](LICENSE.md)

A Laravel package to publish and consume messages from Azure Service Bus queues and topics via the REST API.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require marmanik/laravel-azure-service-bus
```

The package auto-discovers and registers itself via Laravel's package discovery.

Publish the config file:

```
php artisan vendor:publish --tag=azure-service-bus-config
```

Configuration
-------------

[](#configuration)

Add the following variables to your `.env` file.

**Option A: Connection String**

```
AZURE_SERVICE_BUS_CONNECTION_STRING="Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-key="
```

**Option B: Individual Parameters**

```
AZURE_SERVICE_BUS_NAMESPACE=your-namespace
AZURE_SERVICE_BUS_SAS_KEY_NAME=RootManageSharedAccessKey
AZURE_SERVICE_BUS_SAS_KEY=your-sas-key
```

**Optional settings:**

```
AZURE_SERVICE_BUS_QUEUE=default
AZURE_SERVICE_BUS_SAS_TTL=3600
AZURE_SERVICE_BUS_TIMEOUT=30
AZURE_SERVICE_BUS_RETRIES=3
AZURE_SERVICE_BUS_RETRY_DELAY=1000
```

The full `config/azure-service-bus.php`:

```
return [
    'connection_string' => env('AZURE_SERVICE_BUS_CONNECTION_STRING'),
    'namespace'         => env('AZURE_SERVICE_BUS_NAMESPACE'),
    'sas_key_name'      => env('AZURE_SERVICE_BUS_SAS_KEY_NAME', 'RootManageSharedAccessKey'),
    'sas_key'           => env('AZURE_SERVICE_BUS_SAS_KEY'),
    'default_queue'     => env('AZURE_SERVICE_BUS_QUEUE', 'default'),
    'sas_token_ttl'     => env('AZURE_SERVICE_BUS_SAS_TTL', 3600),
    'timeout'           => env('AZURE_SERVICE_BUS_TIMEOUT', 30),
    'retries'           => env('AZURE_SERVICE_BUS_RETRIES', 3),
    'retry_delay_ms'    => env('AZURE_SERVICE_BUS_RETRY_DELAY', 1000),
];
```

Usage (Direct Client / Facade)
------------------------------

[](#usage-direct-client--facade)

### Sending Messages

[](#sending-messages)

**Via Facade:**

```
use Marmanik\AzureServiceBus\Facades\AzureServiceBus;
use Marmanik\AzureServiceBus\ServiceBusMessage;

// Send a simple JSON message to a queue
$message = ServiceBusMessage::create(json_encode(['order_id' => 42]))
    ->withLabel('order-created')
    ->withMessageId('unique-msg-id')
    ->withTimeToLive(3600);

AzureServiceBus::sendToQueue('orders', $message);

// Send to a topic
AzureServiceBus::sendToTopic('notifications', $message);
```

**Via dependency injection:**

```
use Marmanik\AzureServiceBus\AzureServiceBusClient;
use Marmanik\AzureServiceBus\ServiceBusMessage;

class OrderController extends Controller
{
    public function __construct(private AzureServiceBusClient $bus) {}

    public function store(Request $request): JsonResponse
    {
        $message = ServiceBusMessage::create(json_encode($request->validated()))
            ->withCorrelationId($request->header('X-Correlation-ID', ''));

        $this->bus->sendToQueue('orders', $message);

        return response()->json(['status' => 'queued']);
    }
}
```

### Receiving Messages

[](#receiving-messages)

**Receive and delete (destructive read):**

```
$received = AzureServiceBus::receiveAndDelete('orders');

if ($received !== null) {
    $data = $received->getDecodedBody();
    // process $data...
}
```

**Peek-lock (safe processing with explicit complete/abandon):**

```
$received = AzureServiceBus::peekLock('orders');

if ($received !== null) {
    try {
        $data = $received->getDecodedBody();
        // process $data...

        AzureServiceBus::completeMessage(
            'orders',
            $received->getMessageId(),
            $received->getLockToken()
        );
    } catch (\Throwable $e) {
        AzureServiceBus::abandonMessage(
            'orders',
            $received->getMessageId(),
            $received->getLockToken()
        );
    }
}
```

### Topic Subscriptions

[](#topic-subscriptions)

```
// Receive from a topic subscription
$received = AzureServiceBus::receiveFromSubscription('notifications', 'email-sub');

if ($received !== null) {
    // process...
    AzureServiceBus::completeSubscriptionMessage(
        'notifications',
        'email-sub',
        $received->getMessageId(),
        $received->getLockToken()
    );
}
```

### Advanced Message Options

[](#advanced-message-options)

```
use Marmanik\AzureServiceBus\ServiceBusMessage;

$message = ServiceBusMessage::create(json_encode($payload))
    ->withContentType('application/json')
    ->withMessageId('msg-' . Str::uuid())
    ->withCorrelationId('corr-123')
    ->withSessionId('session-abc')
    ->withLabel('my-label')
    ->withTimeToLive(7200)
    ->withScheduledEnqueueTime(now()->addMinutes(5))
    ->withProperty('X-Source', 'my-service')
    ->withProperty('X-Priority', 'high');
```

Usage (Laravel Queue Driver)
----------------------------

[](#usage-laravel-queue-driver)

This package implements Laravel's queue driver interface, allowing you to use Azure Service Bus as a drop-in queue backend with `dispatch()`, `Queue::push()`, and `php artisan queue:work`.

### Queue Configuration

[](#queue-configuration)

In `config/queue.php`, add a connection:

```
'connections' => [
    // ...
    'azure' => [
        'driver'       => 'azure-service-bus',
        'queue'        => env('AZURE_SERVICE_BUS_QUEUE', 'default'),
        // Option A: connection string
        'connection_string' => env('AZURE_SERVICE_BUS_CONNECTION_STRING'),
        // Option B: individual params
        'namespace'    => env('AZURE_SERVICE_BUS_NAMESPACE'),
        'sas_key_name' => env('AZURE_SERVICE_BUS_SAS_KEY_NAME', 'RootManageSharedAccessKey'),
        'sas_key'      => env('AZURE_SERVICE_BUS_SAS_KEY'),
        // Optional
        'sas_token_ttl'  => 3600,
        'timeout'        => 30,
        'retries'        => 3,
        'retry_delay_ms' => 1000,
    ],
],
```

Set the default queue connection in `.env`:

```
QUEUE_CONNECTION=azure
```

### Dispatching Jobs

[](#dispatching-jobs)

```
// Standard Laravel dispatch
ProcessOrder::dispatch($order);

// Dispatch with delay
ProcessOrder::dispatch($order)->delay(now()->addMinutes(10));

// Dispatch to a specific queue
ProcessOrder::dispatch($order)->onQueue('priority-orders');
```

### Processing Jobs

[](#processing-jobs)

```
php artisan queue:work azure --queue=orders
```

Jobs implement the full Laravel job lifecycle including automatic retries, `delete()` on success, and `release()` (abandon) on failure.

Job Failure
-----------

[](#job-failure)

EventAzure Service BusLaravelJob throws, retries remain`abandonMessage()` — message re-queued`JobRetrying` event firedJob throws, max attempts hit`completeMessage()` — message deleted`JobFailed` event, row written to `failed_jobs`Job succeeds`completeMessage()` — message deleted`JobProcessed` event firedManage failed jobs via Artisan:

```
php artisan queue:failed
php artisan queue:retry {id}
php artisan queue:retry all
php artisan queue:flush
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Run with coverage:

```
composer test-coverage
```

Run code style fixer:

```
composer format
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Contributions are welcome. Please open an issue first to discuss what you would like to change. Ensure tests pass before submitting a pull request.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Nikolaos Marmaridis](https://github.com/marmanik)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

8

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f92b39f6f2b1ad41432382e70a1a80394fc33137ebe7761c644af4f442ad86b?d=identicon)[MarmaNik](/maintainers/MarmaNik)

---

Top Contributors

[![marmanik](https://avatars.githubusercontent.com/u/5727095?v=4)](https://github.com/marmanik "marmanik (8 commits)")

---

Tags

laravelqueueazureservice-bus

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/marmanik-laravel-azure-service-bus/health.svg)

```
[![Health](https://phpackages.com/badges/marmanik-laravel-azure-service-bus/health.svg)](https://phpackages.com/packages/marmanik-laravel-azure-service-bus)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

3786.5k](/packages/harris21-laravel-fuse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
