/** * Handles SNS Notifications * * For Subscription notifications, this method will automatically confirm * the Subscription request * * For Message notifications, this method polls the queue and dispatches * the `{queue}.message_received` event for each message retrieved * * @param NotificationEvent $event The Notification Event */ public function onNotification(NotificationEvent $event) { if (NotificationEvent::TYPE_SUBSCRIPTION == $event->getType()) { $topicArn = $event->getNotification()->getMetadata()->get('TopicArn'); $token = $event->getNotification()->getMetadata()->get('Token'); $this->sns->confirmSubscription(['TopicArn' => $topicArn, 'Token' => $token]); $context = ['TopicArn' => $topicArn]; $this->log(200, "Subscription to SNS Confirmed", $context); return; } $messages = $this->receive(); foreach ($messages as $message) { $messageEvent = new MessageEvent($this->name, $message); $event->getDispatcher()->dispatch(Events::Message($this->name), $messageEvent); } }
/** * Polls the Queue on Notification from IronMQ * * Dispatches the `{queue}.message_received` event * * @param NotificationEvent $event The Notification Event */ public function onNotification(NotificationEvent $event) { $message = new Message($event->getNotification()->getId(), $event->getNotification()->getBody(), $event->getNotification()->getMetadata()->toArray()); $this->log(200, "Message has been received from Push Notification.", ['message_id' => $event->getNotification()->getId()]); $messageEvent = new MessageEvent($this->name, $message); $event->getDispatcher()->dispatch(Events::Message($this->name), $messageEvent); }