In comparison to push() method, this one sends messages first to output router that decides how to handle them.
This method will send 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 send ( 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 ) : mixed | mixed[] | ||
$name | string | string[] | |
$message | string | string[] | Kraken\Channel\Protocol\ProtocolInterface | |
$flags | integer | |
$success | callable | |
$failure | callable | |
$cancel | callable | |
$timeout | float | |
return | mixed | mixed[] |
/** * Send the request using passed Promise. * * @param PromiseInterface $promise * @return PromiseInterface */ protected function send(PromiseInterface $promise) { if (!$promise->isPending()) { return $promise; } $this->channel->send($this->name, $this->message, Channel::MODE_STANDARD, function ($value) use($promise) { $promise->resolve($value); }, function ($ex) use($promise) { $promise->reject($ex); }, function ($ex) use($promise) { $this->retryOrReset($promise, $ex); }, $this->params['timeout']); return $promise; }
/** * Send the request using passed Promise. * * @param PromiseInterface $promise * @return PromiseInterface * @resolves mixed * @rejects Error|Exception|string|null * @cancels Error|Exception|string|null */ protected function send(PromiseInterface $promise) { $pid = $this->protocol->getPid(); $origin = $this->protocol->getOrigin(); $message = $this->message; $channel = $this->channel; if ($message instanceof Error || $message instanceof Exception) { $answer = $channel->createProtocol($message->getMessage())->setPid($pid, true)->setException(get_class($message), true); } else { $answer = $channel->createProtocol($message)->setPid($pid, true); } $this->channel->send($origin, $answer, Channel::MODE_BUFFER_ONLINE); return $promise->resolve(); }
/** * @override * @inheritDoc */ public function sendMessage($alias, $message, $flags = Channel::MODE_DEFAULT) { $result = $this->channel->send($alias, $message, $flags); return Promise::doResolve($result); }
/** * @param Error|Exception $ex * @param mixed[] $params * @return mixed */ protected function solver($ex, $params = []) { $hash = isset($params['hash']) ? $params['hash'] : ''; return $this->channel->send($params['origin'], new RuntimeCommand('container:continue', ['hash' => $hash])); }