PHPackages                             entanet/pub-sub-laravel - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. entanet/pub-sub-laravel

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

entanet/pub-sub-laravel
=======================

Wrapper for laravel events so that an event can be published without using a listener and a subscriber command

v1.0(7y ago)0197MITPHPPHP &gt;=7.2.0

Since Dec 7Pushed 7y ago8 watchersCompare

[ Source](https://github.com/Entanet/pubsublaravel)[ Packagist](https://packagist.org/packages/entanet/pub-sub-laravel)[ Docs](https://github.com/Entanet/pubsublaravel)[ RSS](/packages/entanet-pub-sub-laravel/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Pub Sub Laravel
===============

[](#pub-sub-laravel)

Pub-sub-laravel streamlines using the pub-sub pattern in Laravel. It's based on [superbalist/laravel-pubsub](https://github.com/Superbalist/laravel-pubsub).

### Publishing to a topic overview

[](#publishing-to-a-topic-overview)

Pub-sub-laravel allows you to publish a message to an external queue via an event without having to add a listener to publish the message. It uses the PubSubEvent via alias/facade or a bit of tinkering with the Laravel global helper.

### Subscribing to a topic overview

[](#subscribing-to-a-topic-overview)

You can subscribe to a queue using the PubSub2ListenerCommand so that you don't need to create an event to trigger the target listeners.

Prerequisities
--------------

[](#prerequisities)

- [Laravel](https://laravel.com/) 5.6+
- [superbalist/laravel-pubsub](https://github.com/Superbalist/laravel-pubsub) 3.0+

Make sure you've included the laravel-pubsub service provider in config/app.php:

```
    'providers' => [
    ...
    Superbalist\LaravelPubSub\PubSubServiceProvider::class,
    ...

```

Installing and setting up
-------------------------

[](#installing-and-setting-up)

Run the below in your Laravel project to install the library:

```
    composer require entanet/pub-sub-laravel

```

### Registering the service providers

[](#registering-the-service-providers)

To register the PubSubEventProvider and PubSub2ListenerProvider add the below line into the providers array in config/app.php in Laravel:

```
    'providers' => [
    ...

    \Entanet\PubSubLaravel\PubSubEventServiceProvider::class,
    \Entanet\PubSubLaravel\PubSub2ListenerProvider::class

    ...

```

### Add an alias to the PubSubEventFacade

[](#add-an-alias-to-the-pubsubeventfacade)

To add an alias to the facade add the following to the alias array in config/app.php in Laravel:

```
    'aliases' => [
    ...
    'PubSubEvent' => \Entanet\PubSubLaravel\PubSubEventFacade::class,
    ...

```

Also you can alter the current event alias so that any current Event calls use the PubSubEvent:

Change:

```
    'aliases' => [
    ...
    'Event' =>  Illuminate\Support\Facades\Event::class,
    ...

```

To:

```
    'aliases' => [
    ...
    'Event' => \Entanet\PubSubLaravel\PubSubEventFacade::class,
    ...

```

### Overriding the Laravel global helper event

[](#overriding-the-laravel-global-helper-event)

Laravel comes with a global helper [event](https://laravel.com/docs/5.6/helpers#method-event) which dispatches the given event so you don't have to use the facade. If you want to override that helper with the PubSubEvent you need to require the PubSubEventHelper.php file before the vendor/autoload.php. Here is an example, altering the public/index.php file in Laravel 5.6:

```
   // PubSubEventHelper.php is used to override the laravel global event helper.
   require __DIR__.'/../vendor/entanet/pub-sub-laravel/src/PubSubEventHelper.php';
   require __DIR__.'/../vendor/autoload.php';

```

### Set up the listeners for this topic for PubSub2ListenerCommand

[](#set-up-the-listeners-for-this-topic-for-pubsub2listenercommand)

For each topic you are consuming add a mapping in Providers/EventServiceProvider.php

```
    protected $listen = [
    ...
         'test_topic' => [
            TestListener::class
        ]
   ...
   ]

```

Using pub-sub-laravel
---------------------

[](#using-pub-sub-laravel)

### Using PubSubEvent via the Alias/facade

[](#using-pubsubevent-via-the-aliasfacade)

Call dispatch from the facade and supply a relevant event containing the event data and topic (new \\App\\Events\\PubEvent($data, 'topic\_name'))

```
    PubSubEvent::dispatch(new \App\Events\PubEvent($data), 'topic_name');

```

Or if you have altered the existing Event alias:

```
    Event::dispatch(new \App\Events\PubEvent($data), 'topic_name');

```

### Using PubSubEvent via event global helper

[](#using-pubsubevent-via-event-global-helper)

If you overridden the global helper:

```
    event(new \App\Events\PubEvent($data), 'topic_name');

```

### Using a PubSub2ListenerCommand to listen to a topic

[](#using-a-pubsub2listenercommand-to-listen-to-a-topic)

run the following artisan command appended with the topic name, in this instance the topic is test\_topic:

```
    php artisan pubsub:consumer test_topic

```

### Using PubSubTest

[](#using-pubsubtest)

PubSubTest sets a mock of the PubSubInterface for you to use in your unit tests and also includes a handy invokeMethod which can be used to test protected/private functions. So If you had a privateMethod method in a TricksyClass you'd do something like this:

```
   $tricksyInstance = new TricksyClass();
   $response = $this->invokeMethod($tricksyInstance, 'privateMethod');

```

If it took two variables $var1 and $var2:

```
    $var1 = 5;
    $var2 = 'Impossible!';
    $tricksyInstance = new TricksyClass();
    $response = $this->invokeMethod($tricksyInstance, 'privateMethod', [$var1, $var2]);

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

2713d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6546fb2ad80a5dca7970363700647c34b8ae058527ff2569439089f27b2a868b?d=identicon)[mark-jones-entanet](/maintainers/mark-jones-entanet)

---

Top Contributors

[![mark-jones-entanet](https://avatars.githubusercontent.com/u/43141232?v=4)](https://github.com/mark-jones-entanet "mark-jones-entanet (1 commits)")

### Embed Badge

![Health badge](/badges/entanet-pub-sub-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/entanet-pub-sub-laravel/health.svg)](https://phpackages.com/packages/entanet-pub-sub-laravel)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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