1. Go to this page and download the library: Download phpgears/event-async 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/ */
phpgears / event-async example snippets
use Gears\Event\Async\AsyncEventBus;
use Gears\Event\Async\Serializer\JsonEventSerializer;
use Gears\Event\Async\Discriminator\ParameterEventDiscriminator;
/* @var \Gears\Event\EventBus $eventBus */
/* @var Gears\Event\Async\EventQueue $eventQueue */
$eventQueue = new CustomEventQueue(new JsonEventSerializer());
$asyncEventBus new AsyncEventBus(
$eventBus,
$eventQueue,
new ParameterEventDiscriminator('async')
);
$asyncEvent = new CustomEvent(['async' => true]);
$asyncEventBus->dispatch($asyncEvent);
use Gears\Event\Async\ReceivedEvent;
use Gears\Event\Async\Serializer\JsonEventSerializer;
/* @var \Gears\Event\Async\AsyncEventBus $asyncEventBus */
/* @var your_message_queue_manager $queue */
$serializer = new JsonEventSerializer();
while (true) {
$message = $queue->getMessage();
if ($message !== null) {
$event = new ReceivedEvent($serializer->fromSerialized($message));
$asyncEventBus->dispatch($event);
}
}
use Gears\Event\Async\AbstractEventQueue;
class CustomEventQueue extends AbstractEventQueue
{
public function send(Event $event): void
{
// Do the actual enqueue of $this->getSerializedEvent($event);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.