1. Go to this page and download the library: Download lamoda/queue-bundle 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/ */
lamoda / queue-bundle example snippets
use Doctrine\ORM\Mapping as ORM;
use Lamoda\QueueBundle\Entity\QueueEntityMappedSuperclass;
/**
* @ORM\Entity(repositoryClass="Lamoda\QueueBundle\Entity\QueueRepository")
*/
class Queue extends QueueEntityMappedSuperclass
{
}
namespace App\Constant;
class Exchanges
{
public const DEFAULT = 'default';
}
namespace App\Constant;
class Queues
{
public const NOTIFICATION = 'notification';
}
namespace App\Job;
use App\Constant\Exchanges;
use App\Constant\Queues;
use Lamoda\QueueBundle\Job\AbstractJob;
use JMS\Serializer\Annotation as JMS;
class SendNotificationJob extends AbstractJob
{
/**
* @var string
*
* @JMS\Type("int")
*/
private $message;
public function __construct(string $message)
{
$this->message = $message;
}
public function getDefaultQueue(): string
{
return Queues::NOTIFICATION;
}
public function getDefaultExchange(): string
{
return Exchanges::DEFAULT;
}
}
namespace App\Handler;
use Lamoda\QueueBundle\Handler\HandlerInterface;
use Lamoda\QueueBundle\QueueInterface;
class SendNotificationHandler implements HandlerInterface
{
public function handle(QueueInterface $job): void
{
// implement service logic here
}
}
$job = new SendNotificationJob($id);
$container->get(Lamoda\QueueBundle\Factory\PublisherFactory::class)->publish($job);
namespace App\Process;
use Lamoda\QueueBundle\Entity\QueueInterface;
class MyProcess implements QueueInterface
{
// implement interface functions
}
$process = new MyProcess();
$container->get('queue.publisher')->publish($process);
namespace App\Handler;
use Lamoda\QueueBundle\Handler\HandlerInterface;
use Lamoda\QueueBundle\QueueInterface;
class SendNotificationHandler implements HandlerInterface
{
public function handle(QueueInterface $job): void
{
// implement service logic here
// Rerun queue
if ($rerun === true) {
throw new Lamoda\QueueBundle\Exception\RuntimeException('Error message');
}
// Mark queue as failed
if ($failed === true) {
throw new \Exception();
}
}
}
php
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = [
// ...
new Lamoda\QueueBundle\LamodaQueueBundle(),
// ...
];
return $bundles;
}
// ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.