PHPackages                             thefreshuk/pubsub-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. thefreshuk/pubsub-laravel

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

thefreshuk/pubsub-laravel
=========================

Provides PubSub support for Laravel apps

v3.3.0(3mo ago)02[1 issues](https://github.com/thefreshuk/pubsub-laravel/issues)MITPHPPHP &gt;=8.1|&lt;8.4

Since Dec 7Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/thefreshuk/pubsub-laravel)[ Packagist](https://packagist.org/packages/thefreshuk/pubsub-laravel)[ RSS](/packages/thefreshuk-pubsub-laravel/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (8)Dependencies (11)Versions (16)Used By (0)

PubSub for Laravel
==================

[](#pubsub-for-laravel)

This package integrates Laravel projects with Publish/Subscribe providers, using a content-based pub/sub model.

Supported Providers
-------------------

[](#supported-providers)

- AWS SNS

Install
-------

[](#install)

via composer:

```
$ composer require thefreshuk/pubsub-laravel

```

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

[](#configuration)

By default, this package looks for the following env variables:

```
PUBSUB_PROVIDER=sns
PUBSUB_TOPIC=
PUBSUB_ALLOW_HTTP=
PUBSUB_SNS_HOST_PATTERN=

```

You may override this by running the following in your project:

```
php artisan vendor:publish

```

With regards to `PUBSUB_ALLOW_HTTP`, this configures the library to allow HTTP endpoints. Right now, only the signature cert URL is checked as part of SNS message verification. Setting this to `true`requires the use of a forked package (AWS SNS message validator doesn't allow HTTP at all out of the box). To set this up, add the following to your `composer.json` file:

```
"repositories": [
  {
    "type": "vcs",
    "url": "git@github.com:thefreshuk/aws-php-sns-message-validator.git"
  }
]

```

And then run:

```
$ composer update

```

Usage
-----

[](#usage)

### Subscriptions

[](#subscriptions)

There are two ways to subscribe to a topic:

#### 1. Extend `SubscriptionServiceProvider`:

[](#1-extend-subscriptionserviceprovider)

```
use TheFresh\PubSub\SubscriptionServiceProvider as ServiceProvider;

class MockSubscriptionServiceProvider extends ServiceProvider
{
    public static $booted = false;

    /**
     * Like RouteServiceProvider, this namespace is applied to
     * the routes generated by this service provider.
     *
     * @var string $namespace
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * A mapping of message types to routes/controller actions that capture
     * messages.
     *
     * @var string $subscribe
     */
    protected $subscribe = [
        'test_type1' => ['/subscriptions/test-type', 'MockController@onTestType']
    ];

    public function boot()
    {
        parent::boot();

        static::$booted = true;
    }
}

```

This allows you to specify a mapping of 'types' to routes and controllers.

Types are our way of distinguishing between messages. Combined with content-based filtering, this provides a system that feels like a multi-topic system without the proliferation of topics in traditional SNS.

#### 2. Inject Topic

[](#2-inject-topic)

The `Topic` class is available for use however you wish. By providing a `ClientInterface` object and a topic name, as a string, you can use multiple topics with this library.

Laravel will inject the default `Topic` into relevant type-hinted constructors. Since the library has been designed for use with a content-based Pub\\Sub system, there must be a 'default' topic or else this will fail.

### Publishing

[](#publishing)

The `Topic` class provides a publish method that accepts a message. It's as simple as calling this method for a given topic.

```
$topic->publish($message);

```

### Messages

[](#messages)

Messages are sent by publishers and received by subscribers. Every message has a 'type' and 'content':

```
{
  type: string,
  content: {}
}

```

The Pub\\Sub system (preferably) filters based on the type property.

There are two ways to use `Messages`:

#### 1. Separate classes

[](#1-separate-classes)

You can use the following command to generate message classes:

```
$ artisan make:message ExampleMessage

```

This generates a message class in `/PubSub/Messages`. You can instantiate and publish these messages.

#### 2. DynamicMessage

[](#2-dynamicmessage)

You can also use the `TheFresh\PubSub\Messages\DynamicMessage`class. This accepts `$type` and `$content` constructor arguments. All messages received through subscriptions are `DynamicMessage`s.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance86

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 58.8% 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 ~145 days

Recently: every ~261 days

Total

14

Last Release

97d ago

Major Versions

v1.0.1 → v2.0.02021-01-20

v2.0.5 → v3.0.02022-05-16

PHP version history (3 changes)v1.0.0PHP &gt;=7.1

v3.1.1PHP &gt;=8.1

v3.3.0PHP &gt;=8.1|&lt;8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/e358675192ffa2c14a119a9dcf9d95ee9edee978a1f430a1dcaa4282a369d601?d=identicon)[jwdunne](/maintainers/jwdunne)

---

Top Contributors

[![jwdunne](https://avatars.githubusercontent.com/u/577498?v=4)](https://github.com/jwdunne "jwdunne (30 commits)")[![Llanilek](https://avatars.githubusercontent.com/u/7037867?v=4)](https://github.com/Llanilek "Llanilek (12 commits)")[![BigRD](https://avatars.githubusercontent.com/u/17591491?v=4)](https://github.com/BigRD "BigRD (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thefreshuk-pubsub-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/thefreshuk-pubsub-laravel/health.svg)](https://phpackages.com/packages/thefreshuk-pubsub-laravel)
```

###  Alternatives

[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)

PHPackages © 2026

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