Callback executed when a message is received. Dumps the message body, delivery_info and properties.

@param AMQPMessage $msg The received message.

@return void
342505
public function execute(AMQPMessage $msg)
    {
        echo str_repeat('-', 60).PHP_EOL;

        echo '[RECV ' . date('c') . ']' . PHP_EOL .'<content>' .
            PHP_EOL . $msg->body . PHP_EOL . '</content>'.PHP_EOL.PHP_EOL;

        echo "*" . ' INFO ' . PHP_EOL;
        foreach ($msg->{'delivery_info'} as $key => $value) {
            if (is_scalar($value)) {
                echo "** " . $key . ' = ' . $value . PHP_EOL;
            }
        }
        echo "*" . ' PROPERTIES ' . PHP_EOL;
        foreach ($msg->get_properties() as $property => $value) {
            if (is_scalar($value)) {
                echo "** " . $property . ' = ' . $value . PHP_EOL;
            }
        }
    }
1016128
protected function log($msg)
    {
        if (is_null($this->logger) === false) {
            $this->logger->log('Chatkit: '.$msg);
        }
    }
712263
private function getMessageHeader(AMQPMessage $message, $header)
    {
        $headers = $message->has('application_headers') ? $message->get('application_headers') : [];

        return array_key_exists($header, $headers) ? $headers[$header] : null;
    }
448457
public function acknowledge(AMQPMessage $message)
    {
        $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);

        if ($message->body === 'quit') {
            $message->delivery_info['channel']->basic_cancel($message->delivery_info['consumer_tag']);
        }
    }
1198616
public function onClientHandlerMessage(ClientHandlerJobRequest $msg)
    {
        $request = new Request($msg->getRequestId(), $msg->getActionName(), $msg->getParameters());
        $this->addRequest($request);

        $this->getStream('clientHandler')->send(
            new ClientHandlerJobResponse(
                $msg->getRequestId(),
                $this->getId()
            )
        );
    }
1298840
public function onServiceMessage(MessageInterface $msg)
    {
        $this->serviceStreamReady = true;

        $this->getLogger()->debug('Received Service Message of Type: '.get_class($msg));

        if ($msg instanceof ActionListResponse) {
            $actions = $msg->getActions();
            $this->getLogger()->debug('The action list is: '.implode(', ', $actions).'.');
            $this->worker->setActions($actions);

            $reply = new Register();
            $reply->setActions($actions);
            $this->sendToWorkerHandler($reply);
            unset($reply);

            return;
        }

        if ($msg instanceof ExecuteJobResponse) {
            $requestId = $msg->getRequestId();
            $result    = $msg->getResult();
            $this->getLogger()->debug('Result for: '.$requestId.': '.$result);
            $this->worker->setResult($requestId, $result);

            return;
        }

        $this->getLogger()->error('Unknown service response: '.get_class($msg).'.');
    }
774142
public function onWorkerHandlerMessage(ClientHandlerJobResponse $msg)
    {
        $this->workerHandlerReady = true;

        $requestId = $msg->getRequestId();
        if (isset($this->workerHandlerQueue[$requestId])) {
            unset($this->workerHandlerQueue[$requestId]);
        }

        $workerHandler = $msg->getWorkerHandlerId();
        $request       = $this->getRequest($requestId);

        if ($request === null) {
            $this->getLogger()->info(
                sprintf(
                    'WorkerHandler %s accepted request %s, but request is unknown.',
                    $workerHandler,
                    $requestId
                )
            );

            return;
        }

        $this->getLogger()->debug(
            sprintf(
                'Worker-handler %s accepted request: %s.',
                $workerHandler,
                $requestId
            )
        );

        $request->setWorkerHandlerId($workerHandler);
    }
556270
public static function loading(string $msg = 'Loading ', $ended = false): void
    {
        self::pending($msg, $ended);
    }
146726
public static function log($msg){
        Timer::add(1, function() use ($msg) {
            Worker::log($msg);
        }, null, false);
    }
976932
private function processMessage($msg, $qos)
    {
        // Package starts with topic
        $tlen = (ord($msg{0})<<8) + ord($msg{1});
        $msg_topic = substr($msg,2,$tlen);

        // QoS 1 and 2 packets also contain identifier
        $msg_id = null;
        if($qos == 0) {
            $msg = substr($msg,$tlen+2);
        } else {
            $msg_id = substr($msg,$tlen+2,2);
            $msg = substr($msg,$tlen+4);
        }

        // Then comes the message itself
        $found = false;
        foreach($this->topics as $topic=>$data) {

            $t_topic = str_replace("+","[^/]*", $topic);
            $t_topic = str_replace("/","\/",$t_topic);
            $t_topic = str_replace("$","\$",$t_topic);
            $t_topic = str_replace("#",".*",$t_topic);

            if(!preg_match("/^".$t_topic."$/", $msg_topic)) {
                continue;
            }

            $found = true;

            $this->debugMessage("Packet received (QoS: ".$qos." ; topic: ".$msg_topic." ; msg: ".$msg.")",2);

            // Is callback for this topic set?
            if(isset($data["function"]) && is_callable($data["function"])) {
                call_user_func($data["function"], $msg_topic, $msg, $qos);
            }
        }

        //
        if(!$found) {
            $this->debugMessage("Package received, but it doesn't match subscriptions");
        }

        // QoS 1 package requires PUBACK packet
        if($qos==1) {
            $this->debugMessage("Packet with QoS 1 received, sending PUBACK");
            $payload = chr(0x40).chr(0x02).$msg_id;
            fwrite($this->socket, $payload, 4);
        }

        // QoS 2 package requires PUBRECT packet, but we won't give it :)
        if($qos==2) {
            // FIXME
            $this->debugMessage("Packet with QoS 2 received, but feature is not implemented");
        }
    }
206272
public static function log($msg)
    {
        $msg = $msg . "\n";
        if (!self::$daemonize) {
            self::safeEcho($msg);
        }
        file_put_contents((string)self::$logFile, date('Y-m-d H:i:s') . ' ' . 'pid:' . getmypid() . ' ' . $msg, FILE_APPEND | LOCK_EX);
    }
124628
private function log($msg)
    {
        $logger = $this->getConfig('logger');
        if (!$logger) return false;
        return call_user_func_array($logger, array($msg));
    }
1173280
public function processMessage(AMQPMessage $message)
    {
        try {
            $message->delivery_info['channel']
                ->basic_ack($message->delivery_info['delivery_tag']);
            $result = call_user_func($this->callback, $message->body);
            $this->sendReply($result, $message->get('reply_to'), $message->get('correlation_id'));
        } catch (AMQPRuntimeException $exception) {
            $this->sendReply(
                'error: ' . $exception->getMessage(),
                $message->get('reply_to'),
                $message->get('correlation_id')
            );
        } catch (AMQPInvalidArgumentException $exception) {
            $this->sendReply(
                'error: ' . $exception->getMessage(),
                $message->get('reply_to'),
                $message->get('correlation_id')
            );
        }
    }
1304663
protected function logDebug($msg)
    {
        $logger = $this->client->getAsteriskLogger();
        $ani = $this->client->getChannelVariables()->getCallerIdName();
        $dnis = $this->client->getChannelVariables()->getDNIS();
        $logger->debug("NodeController: {$this->name}: $ani -> $dnis: $msg");
    }
574964
public function addText($msg)
    {
        if ($this->message === null) {
            $this->message = "";
        }
        $this->message .= $this->project->replaceProperties($msg);
    }
335981
private function onMessage($msg, $socket) {
        try {
            $payload = @json_decode($msg, true);
            if (!$payload) {
                $this->response($socket, ['error' => 403, 'message' => 'error request']);

                return;
            }
            $command = isset($payload['command']) ? $payload['command'] : 'status';
            $service = isset($payload['args']['service']) ? $payload['args']['service'] : '';
            switch ($command) {
                case 'stop':
                    if ($service) {
                        $rst = $this->stopService($service);
                        $this->response($socket, ['status' => $rst ? 'done' : 'fail']);
                    } else {
                        $this->response($socket, ['status' => 'done']);
                        $this->shutdown = true;
                        $this->rSignal  = SIGTERM;
                    }
                    break;
                case 'start':
                    if ($service) {
                        $rst = $this->startService($service);
                        $this->response($socket, ['status' => $rst ? 'done' : 'fail']);
                    } else {
                        $this->response($socket, ['status' => 'fail']);
                    }
                    break;
                case 'reload':
                    $rst = $this->reloadConfig(null, $service);
                    $this->response($socket, ['status' => $rst ? 'done' : 'fail']);
                    break;
                case 'ps':
                    if ($service) {
                        if (isset($this->services[ $service ])) {
                            $pids = isset($this->services[ $service ]['pids']) ? $this->services[ $service ]['pids'] : [];
                            $this->response($socket, [
                                'ps'   => [$service => $pids],
                                'ssid' => posix_getpid()
                            ]);
                        } else {
                            $this->response($socket, ['ps' => [], 'ssid' => posix_getpid()]);
                        }
                    } else {
                        $ps = [];
                        foreach ($this->services as $s => $ser) {
                            $ps[ $s ] = isset($ser['pids']) ? $ser['pids'] : [];
                        }
                        $this->response($socket, ['ps' => $ps, 'ssid' => posix_getpid()]);
                    }
                    break;
                case 'status':
                default:
                    if ($service) {
                        if (isset($this->services[ $service ])) {
                            $this->response($socket, [
                                'status' => $this->services[ $service ]['status'],
                                'detail' => $this->services[ $service ]
                            ]);
                        } else {
                            $this->response($socket, ['status' => 'unknown', 'detail' => []]);
                        }
                    } else {
                        $this->response($socket, ['status' => 'running', 'services' => $this->services]);
                    }
            }
        } catch (\Exception $e) {
            $this->response($socket, ['error' => 500, 'msg' => $e->getMessage()]);
        }
    }
323562
public function executeMsg(JobMessage $msg, ExecutionContext $execution = null)
    {
        if (null === $execution) {
            $execution = $this->createJobExecutionFromMessage($msg);
        }

        return $msg->execute($execution, $this->msgFactory);
    }