Download the PHP package entanet/pub-sub-laravel without Composer
On this page you can find all versions of the php package entanet/pub-sub-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download entanet/pub-sub-laravel
More information about entanet/pub-sub-laravel
Files in entanet/pub-sub-laravel
Package pub-sub-laravel
Short Description Wrapper for laravel events so that an event can be published without using a listener and a subscriber command
License MIT
Homepage https://github.com/Entanet/pubsublaravel
Informations about the package pub-sub-laravel
Pub Sub Laravel
Pub-sub-laravel streamlines using the pub-sub pattern in Laravel. It's based on superbalist/laravel-pubsub.
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
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
- Laravel 5.6+
- superbalist/laravel-pubsub 3.0+
Make sure you've included the laravel-pubsub service provider in config/app.php:
Installing and setting up
Run the below in your Laravel project to install the library:
Registering the service providers
To register the PubSubEventProvider and PubSub2ListenerProvider add the below line into the providers array in config/app.php in Laravel:
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:
Also you can alter the current event alias so that any current Event calls use the PubSubEvent:
Change:
To:
Overriding the Laravel global helper event
Laravel comes with a global helper 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:
Set up the listeners for this topic for PubSub2ListenerCommand
For each topic you are consuming add a mapping in Providers/EventServiceProvider.php
Using pub-sub-laravel
Using PubSubEvent via the Alias/facade
Call dispatch from the facade and supply a relevant event containing the event data and topic (new \App\Events\PubEvent($data, 'topic_name'))
Or if you have altered the existing Event alias:
Using PubSubEvent via event global helper
If you overridden the global helper:
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:
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:
If it took two variables $var1 and $var2:
All versions of pub-sub-laravel with dependencies
illuminate/support Version ^5.6
superbalist/laravel-pubsub Version ^3.0
superbalist/php-pubsub-kafka Version ^2.0