PHP code example of consilience / laravel-message-flow
1. Go to this page and download the library: Download consilience/laravel-message-flow library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
consilience / laravel-message-flow example snippets
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
// ...
// Give this connection any name other than your application name.
// You may need to set different credentials if the shared redis
// database is not the default database.
'message-flow-database' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_CACHE_DB', '0'),
'prefix' => 'message-flow:',
],
],
use Consilience\Laravel\MessageFlow\Models\MessageFlowOut;
MessageFlowOut::create(["payload" => ["data" => "test data here"]]);
MessageFlowOut::create(["payload" => $myModel]);
namespace App\Observers;
use Consilience\Laravel\MessageFlow\Models\MessageFlowIn;
class MessageFlowObserver
{
/**
* Handle the MessageFlowIn "created" event.
*
* @param \Consilience\Laravel\MessageFlow\Models\MessageFlowIn $messageFlowIn
* @return void
*/
public function created(MessageFlowIn $messageFlowIn)
{
if ($messageFlowIn->isNew()) {
// Process the message.
// ...
// A number of options once processed, either here or in
// a dispatched job:
$messageFlowIn->setComplete()->save(); // Set it as processed
$messageFlowIn->setFailed()->save(); // Set it as unprocessed
$messageFlowIn->delete(); // Delete the message (not before a dispatched job is processed)
// or a custom action or status.
}
}
}
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Consilience\Laravel\MessageFlow\Models\MessageFlowIn;
use App\Observers\MessageFlowObserver;
class EventServiceProvider extends ServiceProvider
{
//...
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
MessageFlowIn::observe(MessageFlowObserver::class);
}
}