/** * 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 * @param string $eventName Name of the event * @param EventDispatcherInterface $dispatcher * @return bool|void */ public function onNotification(NotificationEvent $event, $eventName, EventDispatcherInterface $dispatcher) { 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); $dispatcher->dispatch(Events::Message($this->name), $messageEvent); } }
public function testOnNotification() { $event = new NotificationEvent('test', NotificationEvent::TYPE_MESSAGE, new Notification(123, "test", [])); $event->setDispatcher($this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')); $this->provider->onNotification($event); }
/** * 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); }
public function AwsOnNotificationReceived(NotificationEvent $event) { $notification = $event->getNotification(); $this->assertInstanceOf('\\Uecode\\Bundle\\QPushBundle\\Message\\Notification', $notification); $this->assertEquals(123, $notification->getId()); $this->assertInternalType('array', $notification->getBody()); $this->assertEquals($notification->getBody(), ['foo' => 'bar']); $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $notification->getMetadata()); $this->assertEquals(['Type' => 'Notification', 'TopicArn' => 'SomeArn', 'Timestamp' => date('Y-m-d H:i:s', 1422040603), 'Subject' => 'aws-test'], $notification->getMetadata()->toArray()); }