예제 #1
0
    public function testCanSave()
    {
        $json = <<<JSON
{
    "userId": "134256",
    "currencyFrom": "EUR",
    "currencyTo": "GBP",
    "amountSell": 1000,
    "amountBuy": 747.1,
    "rate": 0.7471,
    "timePlaced": "24-JAN-15 10:27:44",
    "originatingCountry": "FR"
}
JSON;
        $queueMessage = new AMQPMessage($json);
        $transaction = new Transaction();
        $transaction->userId = 134256;
        $transaction->currencyFrom = 'EUR';
        $transaction->currencyTo = 'GBP';
        $transaction->amountSell = 1000;
        $transaction->amountBuy = 747.1;
        $transaction->rate = 0.7471;
        $transaction->timePlaced = '2015-01-24 10:27:44';
        $transaction->originatingCountry = 'FR';
        $this->transactionDbModel->expects($this->once())->method('save')->with($transaction);
        $processor = new MessageProcessor($this->transactionDbModel, $this->logger);
        $processor->process($queueMessage);
    }
예제 #2
0
 /**
  * Gets a message from RabbitMQ, checks it's a valid transaction and saves it into DB.
  *
  * @param AMQPMessage $rawMessage
  */
 public function process(AMQPMessage $rawMessage)
 {
     $this->logger->debug('Processing message ' . $rawMessage->body);
     try {
         $message = Transaction::extractFromJson($rawMessage->body);
         $message->checkSanity();
         $this->messageDbModel->save($message);
     } catch (Exception $e) {
         // either transaction contains invalid data or there was an error in db
         $this->logger->warn($e->getMessage());
     }
 }