Esempio n. 1
0
 /**
  * @Pre\Subscribe
  * @param View $view
  */
 public function registerView(View $view)
 {
     $mailing = $this->repository->find($view->mailingId());
     $mailing->view($view);
     $logger = LoggerFactory::getLogger(__CLASS__);
     $logger->debug("Mailing with ID {} was viewed", [$mailing->getId()]);
 }
Esempio n. 2
0
 /**
  * @Pre\Subscribe
  * @param Click $click
  */
 public function registerClick(Click $click)
 {
     $mailing = $this->repository->find($click->mailingId());
     $mailing->click($click);
     $logger = LoggerFactory::getLogger(__CLASS__);
     $logger->debug("Mailing with ID {} has been clicked", [$mailing->getId()]);
 }
Esempio n. 3
0
 /**
  * @param string $queueName
  * @param string $fqcn
  */
 public function consume($queueName, $fqcn)
 {
     $this->queue = new AMQPQueue($this->channel);
     $this->queue->setName($queueName);
     $this->queue->declareQueue();
     $this->exchange = new AMQPExchange($this->channel);
     $this->exchange->setName('exchange-messages');
     $this->exchange->setType(AMQP_EX_TYPE_FANOUT);
     $this->exchange->declareExchange();
     $this->queue->bind($this->exchange->getName());
     $dispatcher = $this->dispatcher;
     $serializer = $this->serializer;
     $this->queue->consume(function (AMQPEnvelope $envelope, AMQPQueue $queue) use($dispatcher, $serializer, $fqcn) {
         $queue->ack($envelope->getDeliveryTag());
         $object = $serializer->deserialize($envelope->getBody(), $fqcn, 'json');
         $logger = LoggerFactory::getLogger(__CLASS__);
         $logger->debug("Message '{}' with type '{}' has arrived for queue '{}'", [$envelope->getDeliveryTag(), get_class($object), $queue->getName()]);
         $dispatcher->messageArrived(new DefaultQueue($queue->getName()), new MessageWrapper($object));
     }, AMQP_NOPARAM, COMPONENT . '.' . QUEUE . '-consumer');
 }
Esempio n. 4
0
 /**
  * @Pre\Subscribe
  * @param Click $click
  */
 public function forClick(Click $click)
 {
     $logger = LoggerFactory::getLogger(__CLASS__);
     $logger->info("Reward for clicking mailing mailing with ID {} was given", [$click->mailingId()]);
 }
Esempio n. 5
0
 /** @param View $view */
 public function view(View $view)
 {
     $logger = LoggerFactory::getLogger(__CLASS__);
     $logger->info("View has been registered");
 }
Esempio n. 6
0
#!/usr/bin/php
<?php 
use JMS\Parser\SyntaxErrorException;
use Silex\Application;
use lf4php\LoggerFactory;
use jb\messaging\common\infrastructure\amqp\AmqpConsumer;
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/Amsterdam');
if (!extension_loaded("amqp")) {
    die('AMQP module not installed' . PHP_EOL);
}
if ($argc < 4) {
    die('Usage: bin/consumer.php COMPONENT QUEUE MODEL' . PHP_EOL);
}
define('COMPONENT', $argv[1]);
define('QUEUE', $argv[2]);
define('MODEL', $argv[3]);
$app = (require_once __DIR__ . '/../bootstrap.php');
$logger = LoggerFactory::getLogger(QUEUE);
try {
    /** @var AmqpConsumer $consumer */
    $consumer = $app['amqp.consumer'];
    $consumer->consume(QUEUE, MODEL);
    $logger->info('Started consumer');
} catch (SyntaxErrorException $se) {
    $logger->error("Incorrect JSON syntax received: '{}'", [$se->getMessage()], $se);
} catch (Exception $e) {
    $logger->error("{}: '{}'", [get_class($e), $e->getMessage()], $e);
}
Esempio n. 7
0
 /**
  * @Pre\Subscribe
  * @param Click $click
  */
 public function giveRewardFor(Click $click)
 {
     $logger = LoggerFactory::getLogger(__CLASS__);
     $logger->debug("User '{}' has been rewarded for clicking on mailing '{}'", [$click->userId(), $click->mailingId()]);
 }