Sends a message to AWS SQS service

@param string $message The content of the message, must be text or a json_encoded array
@param int    $delay   Delay in seconds. Min: 0 Max: 900 (15 minutes)
19073
public function sendDelayedMessage(string $message, int $delay = 0)
    {
        $delay = max(0, $delay);
        $delay = min(900, $delay);
        $this->sqsClient->sendMessage([
            'DelaySeconds' => $delay,
            'MessageBody'  => $message,
            'QueueUrl'     => $this->queueUrl,
        ]);
    }
615066
protected function SendMessage($message)
    {
        $this->signal_data->message = $message;
        
        $this->Send(
            \Peg\Lib\Signals\Type\Lexers::LEXER_MESSAGE,
            $this->signal_data
        );
    }
222972
protected function appendMessage(string $message): void
    {
        $this->messages[] = $message;

        if (sizeof($this->messages) > $this->config['max_messages']) {
            array_shift($this->messages);
        }
    }
978380
public function debug($message = "%s seconds")
    {
        $this->logger->debug(sprintf($message, $this->currentProfile->getDuration()));
    }
31163
public function push($message)
    {
        $message = json_decode($message, true);
        $topic = array_get($this->getTopics(), $message['topic']);
        $data = $message['data'];
        $recipient = array_get($message, 'recipient');
        
        // Handle TwoStream::stop();
        if ($message['topic'] == 'cupoftea/twostream/server/stop') {
            if ($data['secret'] == config('app.key')) {
                event(new ServerStopped());
                $this->line('Stop Command fired.');
                $this->question('Stopping Server.');
                
                die();
            } else {
                // report malicious attempt
            }
        }
        
        if (! $topic) {
            return;
        }
        
        $this->setTopic($topic);
        
        if ($recipient == 'all') {
            $topic->broadcast($data);
        } else {
            foreach ((array) $recipient as $recipient) {
                if (($sessionId = $this->getUserSessionId($recipient)) || ($sessionId = WsSession::isValidId($recipient) ? $recipient : false)) {
                    foreach ($topic->getIterator() as $client) {
                        if ($client->session == $sessionId) {
                            $client->event($topic->getId(), $data);
                        }
                    }
                } else {
                    throw new InvalidRecipientException($recipient);
                }
            }
        }
    }
895222
public function publish($topic, $message, $qos = 0, $retain = 0, &$msgid = null)
    {
        # set dup 0
        $dup = 0;

        # initial msgid = 0
        $msgid = 0;

        return $this->do_publish($topic, $message, $qos, $retain, $msgid, $dup);
    }
470184
public function sendMessage(string $queueName, $message, int $delaySeconds=0, int $priority=8, bool $base64=true) {
        if(!$queueName || !$message){
            return $this->error('参数有误');
        }
        try{
            $queue = $this->client->getQueueRef($queueName);
            if(is_array($message)){
                $requestItems = [];
                foreach ($message as $item){
                    $requestItem = new SendMessageRequestItem($item, $delaySeconds, $priority);
                    $requestItems[] = $requestItem;
                }
                $request = new BatchSendMessageRequest($requestItems, $base64);
                $queue->batchSendMessage($request);
            }else{
                $request = new SendMessageRequest($message, $delaySeconds, $priority, $base64);
                $queue->sendMessage($request);
            }
            return $this->success('发送消息成功');
        }catch(MnsException $exception){
            return $this->parseException($exception, '发送消息');
        }
    }
1255339
public void send(Object message, long delay, ActorRef sender) {
        dispatcher.sendMessage(endpoint, message, ActorTime.currentTime() + delay, sender);
    }
241603
public function sendMessage($message) {
		$message = preg_replace("/(\n\r|\n)/","\r",$message);
		$query = http_build_query(array(
			'user' => $this->_user_id,
			'pass' => $this->_api_key,
			'msg' => $message
		));
		$url = self::api_url.'?'.$query;

		$curl_handler = curl_init();
		curl_setopt($curl_handler,CURLOPT_URL,$url);
		curl_setopt($curl_handler,CURLOPT_POST,false);
		curl_setopt($curl_handler,CURLOPT_RETURNTRANSFER,true);
		curl_setopt($curl_handler,CURLOPT_HEADER,true);
		curl_setopt($curl_handler,CURLOPT_NOBODY,true);
		curl_setopt($curl_handler,CURLOPT_RETURNTRANSFER,1);
		curl_setopt($curl_handler,CURLOPT_SSL_VERIFYPEER,true);
		curl_setopt($curl_handler,CURLOPT_SSL_VERIFYHOST,2);
		curl_setopt($curl_handler,CURLOPT_CAINFO,__DIR__."/freemobile.crt");
		
		if (curl_exec($curl_handler) === false) {
			throw new Exception('Curl error : '.curl_error($curl_handler));
		}
		
		$status = curl_getinfo($curl_handler,CURLINFO_HTTP_CODE);
		curl_close($curl_handler);

		switch ($status) {
		case 200:
			return true;
			break;

		case 400:
			throw new Exception('Badly formed request');
			return false;
			break;

		case 402:
			throw new OverflowException('Too many messages sent in a short period of time');
			return false;
			break;

		case 403:
			throw new UnexpectedValueException('SMS notification service not activated or wrong credentials');
			return false;
			break;

		case 500:
			throw new RuntimeException('Server error, try later');
			return false;
			break;
			
		default:
			return false;
			break;
		}
	}
1212627
public function write_message($message)
  {
    $binary_length = strlen($message);
    
    $max_binary_frame_length = BUFFER_SIZE - 4;
    $sended_length = 0;
    
    $frames = array();
    while ($sended_length < $binary_length) {
      $not_sended_length = $binary_length - $sended_length;
      $binary_frame_length = ($not_sended_length > $max_binary_frame_length) ? $max_binary_frame_length : $not_sended_length;
      $frames[] = substr($message, $sended_length, $binary_frame_length);
      $sended_length += $binary_frame_length;
    }
    
    foreach ($frames as $frame) {
      $msg = pack("N", strlen($frame)).$frame;
      socket_write ( $this->socket, $msg, strlen($msg));
    }
    $footer = pack("N", 0);
    //socket_send ($this->socket, $header, strlen($header) , 0);
    $x = socket_write ($this->socket, $footer, strlen($footer));
    
  }
231385
protected function relayNotification($message)
    {
        $message = json_encode($message);

        foreach ($this->listenClients as $client) {
            if ($client->getState() < Net_Notifier_WebSocket_Connection::STATE_CLOSING) {

                $this->log(
                    sprintf(
                        ' ... relaying message "%s" to %s ... ',
                        $message,
                        $client->getIPAddress()
                    ),
                    Net_Notifier_Logger::VERBOSITY_CLIENT
                );

                $client->writeText($message);

                $this->log(
                    'done' . PHP_EOL,
                    Net_Notifier_Logger::VERBOSITY_CLIENT,
                    false
                );
            }
        }
    }
974235
protected function send($message)
	{
		$message = $this->encodeMessage($message);
		$this->ws->send($message);
	}
148324
public function send(Message $message)
    {
        $response = $this->guzzleClient->post('/messages', [
            'json' => [
                'originator' => $message->getOriginator(),
                'recipients' => $message->getRecipient(),
                'body'       => $message->getBody(),
            ],
            'http_errors' => false,
        ]);

        try {
            $document = JsonHelper::decode((string) $response->getBody());
        } catch (\RuntimeException $e) {
            throw new ApiRuntimeException('The MessageBird server did not return valid JSON.', [], $e);
        }

        if (isset($document['errors'])) {
            $errors = $document['errors'];
        } else {
            $errors = [];
        }

        $statusCode = (int) $response->getStatusCode();

        if (!in_array($statusCode, [200, 201, 204, 401, 404, 405, 422]) && !($statusCode >= 500 && $statusCode < 600)) {
            throw new ApiRuntimeException(sprintf('Unexpected MessageBird server behaviour (HTTP %d)', $statusCode), $errors);
        }

        if (!isset($document['recipients']['items'][0]['status'])) {
            $deliveryStatus = SendMessageResult::STATUS_NOT_SENT;
        } else {
            $deliveryStatus = $document['recipients']['items'][0]['status'];
        }

        return new SendMessageResult($deliveryStatus, $errors);
    }
586257
public function onRequeue(Message $message, $delay, $backoff)
    {
        $this->conn->onMessageRequeue($message, $delay, $backoff);
    }
1020550
public function setMessage($message, $priority)
    {
        $this->message = (string) $message;
        $this->priority = (int) $priority;
    }
97989
public function publishPeriodically($interval, Message $message, callable $generator)
    {
        if (!$this->isConnected) {
            return new RejectedPromise(new \LogicException('The client is not connected.'));
        }

        $deferred = new Deferred();

        $this->timer[] = $this->loop->addPeriodicTimer(
            $interval,
            function () use ($message, $generator, $deferred) {
                $this->publish($message->withPayload($generator($message->getTopic())))->then(
                    function ($value) use ($deferred) {
                        $deferred->notify($value);
                    },
                    function (\Exception $e) use ($deferred) {
                        $deferred->reject($e);
                    }
                );
            }
        );

        return $deferred->promise();
    }
936430
public function send($message, $signal = null, $pause = 500)
    {
        $messageArray = array();

        if (($shmId = @shmop_open($this->pid, 'a', 0, 0)) > 0) {
            // Read any existing messages in shared memory
            $readMessage = shmop_read($shmId, 0, shmop_size($shmId));
            $messageArray[] = unserialize($readMessage);
            shmop_delete($shmId);
            shmop_close($shmId);
        }

        // Add the current message to the end of the array, and serialize it
        $messageArray[] = $message;
        $serializedMessage = serialize($messageArray);

        // Write new serialized message to shared memory
        $shmId = shmop_open($this->pid, 'c', 0644, strlen($serializedMessage));
        if (!$shmId) {
            throw new ProcessControlException(sprintf('Not able to create shared memory segment for PID: %s', $this->pid));
        } else if (shmop_write($shmId, $serializedMessage, 0) !== strlen($serializedMessage)) {
            throw new ProcessControlException(
                sprintf('Not able to write message to shared memory segment for segment ID: %s', $shmId)
            );
        }

        if (false === $signal) {
            return;
        }

        $this->signal($signal ?: $this->signal);
        usleep($pause);
    }