/** * @return null */ public function startCommunication() { $this->initLoop(); $this->context = new \ZMQContext(); $this->pulsarRequestSocket = $this->context->getSocket(\ZMQ::SOCKET_REQ); $this->performersReplySocket = $this->context->getSocket(\ZMQ::SOCKET_REP); $this->initStreams(); $replyStackErrorDtoAlreadySent = false; /** * Receive sockets params from Pulsar and start cyclical communication */ $this->readStream->on(EventsConstants::DATA, function ($data) use($replyStackErrorDtoAlreadySent) { $replyStackDto = null; $replyStackDto = @unserialize($data); if ($replyStackDto !== false && $replyStackDto instanceof ReplyStackDto) { $this->pulsarRequestSocket->connect($replyStackDto->getReplyStackVsPulsarSocketAddress()); $this->performersReplySocket->bind($replyStackDto->getReplyStackVsPerformersSocketAddress()); $this->moduleDto = $replyStackDto; $initDto = new InitStartMethodDto(); $initDto->setShutDownArg('warning'); $this->initStartMethods($initDto); //TODO: make resolver of ways of ReplyStack logging //$this->logger->debug("ReplyStack receive initDto from Pulsar."); $this->loop->nextTick([$this, 'startStackWork']); } else { if ($replyStackErrorDtoAlreadySent === false) { $replyStackErrorDtoAlreadySent = true; $replyStackError = new ReplyStackErrorDto(); $replyStackError->setErrorLevel(ErrorsConstants::CRITICAL); $replyStackError->setErrorReason(PulsarErrorConstants::REPLY_STACK_RECEIVE_NOT_CORRECT_DTO); //write to Pulsar's allotted STDIN about critical error $this->writeStream->write(serialize($replyStackError)); $this->loop->nextTick(function () { $this->loop->stop(); }); } } }); $this->loop->run(); return null; }
/** * @param InitStartMethodDto * @return null */ protected function initStartMethods(InitStartMethodDto $initDto = null) { $this->initLoggers(); $this->registerShutDown($initDto ? $initDto->getShutDownArg() : null); return null; }
/** * @return null * @throws PublisherPulsarException */ public function manage() { if (!$this->publisherPulsarDto instanceof PublisherPulsarDto) { throw new PublisherPulsarException("PublisherPulsarDto wasn't set."); } $initDto = new InitStartMethodDto(); $initDto->setShutDownArg('warning'); $this->initStartMethods($initDto); $this->context = new Context($this->loop); $this->shouldBeSubscribersNumber = $this->publisherPulsarDto->getSubscribersPerIteration(); $this->maxWaitReplyStackResult = $this->publisherPulsarDto->getMaxWaitReplyStackResult() ?: $this->maxWaitReplyStackResult; if (is_null($this->shouldBeSubscribersNumber)) { throw new PublisherPulsarException("Subscribers per iteration number wasn't set."); } $this->pulsarSocketsParams = $this->publisherPulsarDto->getPulsarSocketsParams(); $this->initResultingPushMessagesWaiting(); $this->initSockets(); $this->initReplyStackProcess(); $this->declareReplyToReplyStackMessaging(); $this->declarePushMessaging(); $this->initPulsar(); $this->loop->run(); return null; }