/** * @test */ public function addSubscriberDelegatesToEventDispatcher() { $subscriber = $this->getMock('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface'); $this->ed->expects($this->once())->method('addSubscriber')->with($subscriber); $ret = $this->queue->addSubscriber($subscriber); $this->assertSame($this->queue, $ret); }
/** * @param callable $callback * @param array $params * @return Message */ public function execute(callable $callback, $params = []) { if (!$this->attached) { throw new LogicException('Must be attached to a file library'); } $command = new SerializedCallback($callback, $params); return $this->queue->enqueue('xi_filelib.asynchrony.command', $command); }
/** * @param Queue $queue */ public function __construct(EventDispatchingQueue $queue) { $this->queue = $queue; $this->eventDispatcher = $queue->getEventDispatcher(); }
{ return $message->getType() == 'reservation.create'; } /** * @param Message $message * @return Result */ public function handle(Message $message, QueueInterface $queue) { /** @var ReservationRequest $reservation */ $reservation = $message->getData(); if (rand(1, 100) >= 75) { // If a result is not successful the message will stay on the queue. $result = new Result(false, 'Oh dear, the reservation could not be created. It will be retried... soon!'); } else { $msg = sprintf("Reservation created from %s to %s", $reservation->getFrom()->format('Y-m-d H:i:d'), $reservation->getTo()->format('Y-m-d H:i:d')); // If a result is successful, the message is acked (acknowledged to be processed, removed from queue) $result = new Result(true, $msg); } return $result; } } // Creates an IronMQ backed queue $innerQueue = new Queue(new IronMQAdapter(IRONMQ_TOKEN, IRONMQ_PROJECT_ID, 'pekkis-queue-example')); // Adds our own data serializer for reservation requests $innerQueue->addDataSerializer(new ReservationRequestDataSerializer()); // Wrap the queue with Symfony events $queue = new EventDispatchingQueue($innerQueue, new EventDispatcher()); // Create a console output and attach a queue subscriber to get queue event messages to console output. $output = new ConsoleOutput(); $queue->addSubscriber(new ConsoleOutputSubscriber($output));