本文整理汇总了PHP中ZMQSocket::on方法的典型用法代码示例。如果您正苦于以下问题:PHP ZMQSocket::on方法的具体用法?PHP ZMQSocket::on怎么用?PHP ZMQSocket::on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZMQSocket
的用法示例。
在下文中一共展示了ZMQSocket::on方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerHandlers
/**
*
*/
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')));
}
示例2: initZmq
/**
* @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";
}
});
}
示例3: declarePushMessaging
/**
* @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;
}
示例4: registerInboundEvents
/**
* 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);
}
});
}
示例5: declareReplyToPm
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;
}
示例6: declareLmRequester
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++;
}
});
}