Download the PHP package thefreshuk/pubsub-laravel without Composer
On this page you can find all versions of the php package thefreshuk/pubsub-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thefreshuk/pubsub-laravel
More information about thefreshuk/pubsub-laravel
Files in thefreshuk/pubsub-laravel
Package pubsub-laravel
Short Description Provides PubSub support for Laravel apps
License MIT
Informations about the package pubsub-laravel
PubSub for Laravel
This package integrates Laravel projects with Publish/Subscribe providers, using a content-based pub/sub model.
Supported Providers
- AWS SNS
Install
via composer:
Configuration
By default, this package looks for the following env variables:
You may override this by running the following in your project:
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:
And then run:
Usage
Subscriptions
There are two ways to subscribe to a topic:
1. Extend SubscriptionServiceProvider
:
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
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
The Topic
class provides a publish method that accepts a
message. It's as simple as calling this method for a given topic.
Messages
Messages are sent by publishers and received by subscribers. Every message has a 'type' and 'content':
The Pub\Sub system (preferably) filters based on the type property.
There are two ways to use Messages
:
1. Separate classes
You can use the following command to generate message classes:
This generates a message class in <app_dir>/PubSub/Messages
. You can
instantiate and publish these messages.
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.
All versions of pubsub-laravel with dependencies
aws/aws-sdk-php-laravel Version ^3.1
aws/aws-php-sns-message-validator Version 2.0.1
guzzlehttp/guzzle Version ^7.0.1
symfony/console Version ^6.2
illuminate/console Version ^10.9
illuminate/support Version ^10.9
illuminate/filesystem Version ^10.9
illuminate/routing Version ^10.9
illuminate/collections Version ^10.9