/** * */ private function registerHandlers() { $this->hbSocket->on('error', new HbErrorHandler($this->logger->withName('HbErrorHandler'))); $this->hbSocket->on('messages', new HbMessagesHandler($this->logger->withName('HbMessagesHandler'))); $this->iopubSocket->on('messages', new IOPubMessagesHandler($this->logger->withName('IOPubMessagesHandler'))); $this->shellSocket->on('messages', new ShellMessagesHandler($this->broker, $this->iopubSocket, $this->shellSocket, $this->logger->withName('ShellMessagesHandler'))); }
/** * @param LoopInterface $loop */ public function initZmq(LoopInterface $loop) { /** @var \ZMQContext $context */ $context = new \React\ZMQ\Context($loop); $this->listener = $context->getSocket(\ZMQ::SOCKET_PUSH); $this->listener->connect('tcp://127.0.0.1:5559'); $this->receiver = $context->getSocket(\ZMQ::SOCKET_PULL); $this->receiver->connect('tcp://127.0.0.1:5557'); $this->receiver->on('message', function ($msg) { $message = json_decode($msg, true); if (is_array($message) && isset($message['outputs']) && is_array($message['outputs'])) { $cumulative = array(); foreach ($message['outputs'] as $output) { $script = pack("H*", $output['script']); if (!isset($cumulative[$script])) { $cumulative[$script] = $output['value']; } else { $cumulative[$script] += $output['value']; } } $message['requirements'] = $cumulative; $this->contracts[$message['slug']] = $message; echo "New contract: " . $msg . "\n"; } }); }
/** * @return null */ protected function declarePushMessaging() { $this->pullActionInfo->on(EventsConstants::MESSAGE, function ($pushDto) { $this->resolvePushMessage(unserialize($pushDto)); $this->logger->debug("Receive push message {$pushDto}."); }); $this->pullActionInfo->on(EventsConstants::ERROR, function ($error) { $this->logger->error(LoggingExceptions::getExceptionString($error)); }); return null; }
/** * Registers inbound data events. */ private function registerInboundEvents() { // Handle requests from queue via SUBSCRIBER $this->zmqInboundQueue->on('message', function ($msg) { $this->runtimeStatistics->incrementAddedObjectCount(); try { $message = RequestMessage::fromStringToArray($msg); $this->getQueue()->push($message['key'], $message['data'], round(microtime(true) * 1000000) + $message['timeout'], $message['type']); if ($this->isInLogLevel(Logger::DEBUG)) { $this->logger->debug("[OnMessage] Data for key '{$message['key']}' [type '{$message['type']}', exp {$message['timeout']} ms]: " . str_replace("\n", "", var_export($message['data'], true))); } } catch (\Exception $e) { $this->logger->error($e); } }); }
protected function declareReplyToPm() { $this->replyToPmSocket = $this->context->getSocket(\ZMQ::SOCKET_REP); $this->replyToPmSocket->bind($this->loadManagerDto->getPmLmSocketsParams()->getPmLmRequestAddress()); $this->replyToPmSocket->on(EventsConstants::ERROR, function (\Exception $e) { $this->logger->error(LoggingExceptions::getExceptionString($e)); }); $this->replyToPmSocket->on(EventsConstants::MESSAGE, function ($receivedDtoContainer) { /** * @var DtoContainer $dtoContainer */ $dtoContainer = unserialize($receivedDtoContainer); $this->processReceivedControlDto($dtoContainer->getDto()); $this->receivePmInfo = true; $this->replyToPmSocket->send(serialize($this->dtoContainer)); }); return null; }
protected function declareLmRequester() { $this->lmRequesterSocket = $this->context->getSocket(\ZMQ::SOCKET_REQ); $this->lmRequesterSocket->connect($this->processManagerDto->getPmLmSocketsParams()->getPmLmRequestAddress()); $this->lmRequesterSocket->on(EventsConstants::ERROR, function (\Exception $e) { $this->logger->error(LoggingExceptions::getExceptionString($e)); }); $this->lmRequesterSocket->on(EventsConstants::MESSAGE, function ($receivedDtoContainer) { $this->logger->alert("Received dto from LM." . $this->loggerPostfix); usleep($this->processManagerDto->getInterMessageInterval()); /** * @var DtoContainer $dtoContainer */ $dtoContainer = unserialize($receivedDtoContainer); $this->processReceivedControlDto($dtoContainer->getDto()); if ($this->allowSending) { $this->lmRequesterSocket->send(serialize($this->dtoContainer)); $this->logger->alert("Send a request " . $this->requestNumber . $this->loggerPostfix); $this->requestNumber++; } }); }