/** * @param LoopInterface $loop * @param WampServerInterface $app */ public function handle(LoopInterface $loop, WampServerInterface $app) { $config = $this->getConfig(); $context = new Context($loop); /* @var SocketWrapper $pull */ $this->consumer = $context->getSocket(\ZMQ::SOCKET_PULL); $this->logger->info(sprintf('ZMQ transport listening on %s:%s', $config['host'], $config['port'])); $this->consumer->bind('tcp://' . $config['host'] . ':' . $config['port']); $this->consumer->on('message', function ($data) use($app, $config) { try { /** @var MessageInterface $message */ $message = $this->serializer->deserialize($data); $request = $this->router->match(new Topic($message->getTopic())); $app->onPush($request, $message->getData(), $this->getName()); $this->eventDispatcher->dispatch(Events::PUSHER_SUCCESS, new PushHandlerEvent($data, $this)); } catch (\Exception $e) { $this->logger->error('AMQP handler failed to ack message', ['exception_message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'message' => $data]); $this->eventDispatcher->dispatch(Events::PUSHER_FAIL, new PushHandlerEvent($data, $this)); } }); }