/**
  * Processes message from SNS
  *
  * @throws Exception
  */
 function process_message()
 {
     $this->_log('Received message');
     try {
         $message = \Message::fromRawPostData();
         $validator = new \MessageValidator();
         $error = '';
         if ($validator->isValid($message)) {
             $topic_arn = $this->_config->get_string('cluster.messagebus.sns.topic_arn');
             if (empty($topic_arn) || $topic_arn != $message->get('TopicArn')) {
                 throw new \Exception('Not my Topic. Request came from ' . $message->get('TopicArn'));
             }
             if ($message->get('Type') == 'SubscriptionConfirmation') {
                 $this->_subscription_confirmation($message);
             } elseif ($message->get('Type') == 'Notification') {
                 $this->_notification($message->get('Message'));
             }
         } else {
             $this->_log('Error processing message it was not valid.');
         }
     } catch (\Exception $e) {
         $this->_log('Error processing message: ' . $e->getMessage());
     }
     $this->_log('Message processed');
 }
Esempio n. 2
0
 /**
  * Processes message from SNS
  *
  * @throws Exception
  */
 function process_message()
 {
     $this->_log('Received message');
     try {
         $message = Message::fromRawPostData();
         $validator = new MessageValidator();
         $error = '';
         if ($validator->isValid($message)) {
             if ($message->get('Type') == 'SubscriptionConfirmation') {
                 $this->_subscription_confirmation($message);
             } else {
                 if ($message->get('Type') == 'Notification') {
                     $this->_notification($message->get('Message'));
                 }
             }
         } else {
             $this->_log('Error processing message it was not valid.');
         }
     } catch (Exception $e) {
         $this->_log('Error processing message: ' . $e->getMessage());
     }
     $this->_log('Message processed');
 }
    public function testBuildsStringToSignCorrectly()
    {
        $validator = new MessageValidator();
        $stringToSign = <<<STRINGTOSIGN
Message
foo
MessageId
bar
Timestamp
1435697129
TopicArn
baz
Type
Notification

STRINGTOSIGN;
        $this->assertEquals($stringToSign, $validator->getStringToSign($this->getTestMessage()));
    }