push() публичный Метод

In comparison to send() method skips routing mechanisms and tries to push message directly to receiver, therefore this method should be used with caution. This method will push multiple messages separately. If any of the callback handlers are set, then message(s) will be treated as Request(s) and Channel will asynchronously await response(s). On the other hand, if none are set, then message(s) will be send without creating handler making the process faster and better memory-optimized. However, in that case Channel will not be able to process any returned values. Timeout works only for requests and represents number of seconds after which handler will automatically cancel. Flags might be one of: Channel::MODE_STANDARD - sends message if both sender and receiver are online. Channel::MODE_BUFFER_OFFLINE - works in similar way as MODE_STANDARD, but also enables buffering messages in case that sender is offline. Channel::MODE_BUFFER_ONLINE - works in similar way as MODE_STANDARD, but also enables buffering messages in case that receiver is offline. Channel::MODE_BUFFER - sends message if both sender and receiver are online or buffers it if one of them is offline.
public push ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : RequestRecord | RequestRecord[] | null | null[] | boolean | bool[]
$name string | string[]
$message string | string[] | Kraken\Channel\Protocol\ProtocolInterface
$flags integer
$success callable
$failure callable
$cancel callable
$timeout float
Результат Kraken\Channel\Record\RequestRecord | Kraken\Channel\Record\RequestRecord[] | null | null[] | boolean | bool[]
Пример #1
0
 /**
  * @param ChannelInterface $channel
  */
 protected function applyConsoleController(ChannelInterface $channel)
 {
     $router = $channel->getInput();
     $router->addDefault(new RuleHandler(function ($params) {
     }));
     $router = $channel->getOutput();
     $router->addDefault(new RuleHandler(function ($params) use($channel) {
         $channel->push($params['alias'], $params['protocol'], $params['flags'], $params['success'], $params['failure'], $params['cancel'], $params['timeout']);
     }));
 }
Пример #2
0
 /**
  * @param RuntimeContainerInterface $runtime
  * @param ChannelCompositeInterface $composite
  * @param ChannelInterface $console
  */
 private function applyRootRouting(RuntimeContainerInterface $runtime, ChannelCompositeInterface $composite, ChannelInterface $console)
 {
     $master = $composite->getBus('master');
     $slave = $composite->getBus('slave');
     $router = $composite->getInput();
     $router->addDefault(new RuleHandler(function ($params) {
         return true;
     }));
     $router = $composite->getOutput();
     $router->addDefault(function ($receiver, ProtocolInterface $protocol, $flags, callable $success = null, callable $failure = null, callable $cancel = null, $timeout = 0.0) use($runtime, $slave, $console) {
         if ($receiver === Runtime::RESERVED_CONSOLE_CLIENT || $protocol->getDestination() === Runtime::RESERVED_CONSOLE_CLIENT) {
             $console->push(Runtime::RESERVED_CONSOLE_CLIENT, $protocol, $flags, $success, $failure, $cancel, $timeout);
         } else {
             if ($runtime->getManager()->existsRuntime($receiver) || $slave->isConnected($receiver)) {
                 $slave->push($receiver, $protocol, $flags, $success, $failure, $cancel, $timeout);
             } else {
                 $slave->push($slave->getConnected(), $protocol, $flags, $success, $failure, $cancel, $timeout);
             }
         }
     });
     $router = $master->getInput();
     $router->addRule(new RuleMatchDestination($master->getName()), new RuleHandler(function ($params) use($runtime, $composite) {
         $this->executeProtocol($runtime, $composite, $params['protocol']);
     }));
     $router->addDefault(new RuleHandler(function ($params) use($slave) {
         $slave->push($slave->getConnected(), $params['protocol'], $params['flags']);
     }));
     $router = $slave->getInput();
     $router->addRule(new RuleMatchDestination($slave->getName()), new RuleHandler(function ($params) use($runtime, $composite) {
         $this->executeProtocol($runtime, $composite, $params['protocol']);
     }));
     $router->addDefault(new RuleHandler(function ($params) use($runtime, $slave, $console) {
         $receiver = $params['alias'];
         $protocol = $params['protocol'];
         if ($receiver === Runtime::RESERVED_CONSOLE_CLIENT || $protocol->getDestination() === Runtime::RESERVED_CONSOLE_CLIENT) {
             $console->push(Runtime::RESERVED_CONSOLE_CLIENT, $protocol, $params['flags']);
         } else {
             $slave->push($slave->getConnected(), $params['protocol'], $params['flags']);
         }
     }));
     $router = $master->getOutput();
     $router->addDefault(function ($sender, ProtocolInterface $protocol, $flags, callable $success = null, callable $failure = null, callable $cancel = null, $timeout = 0.0) use($master) {
         $master->push($sender, $protocol, $flags, $success, $failure, $cancel, $timeout);
     });
     $router = $slave->getOutput();
     $router->addDefault(function ($sender, ProtocolInterface $protocol, $flags, callable $success = null, callable $failure = null, callable $cancel = null, $timeout = 0.0) use($slave) {
         $slave->push($sender, $protocol, $flags, $success, $failure, $cancel, $timeout);
     });
 }