本文整理汇总了PHP中Aws\Sqs\SqsClient::sendMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP SqsClient::sendMessage方法的具体用法?PHP SqsClient::sendMessage怎么用?PHP SqsClient::sendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\Sqs\SqsClient
的用法示例。
在下文中一共展示了SqsClient::sendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: publish
/**
* Send message to sqs and trigger lambda
*
* @param string $message to be send via sqs
*
*/
public function publish($message)
{
// http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sqs.SqsClient.html#_sendMessage
$this->sqs->sendMessage(['QueueUrl' => $this->sqsQueueUrl, 'MessageBody' => $message]);
// http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sns.SnsClient.html#_publish
$this->sns->publish(['TopicArn' => $this->snsTopicArn, 'Message' => 'SQS Message send', 'Subject' => 'SQS Message send']);
}
示例2: enqueue
/**
* {@inheritDoc}
*/
public function enqueue(MessageInterface $message)
{
$result = $this->client->sendMessage(['QueueUrl' => $this->getUrl(), 'MessageBody' => $this->getEncoder()->encode($message), 'DelaySeconds' => $this->getMessageDelay($message)]);
if ($result instanceof Model) {
$message->setId($result->get('MessageId'));
}
}
示例3: enqueue
/**
* @inheritDoc
*/
public function enqueue($queueName, Message $message)
{
$queueUrl = $this->getQueueUrl($queueName);
$env = new DefaultEnvelope($message);
$data = $this->serialize($env);
$result = $this->client->sendMessage(array('QueueUrl' => $queueUrl, 'MessageBody' => $data));
return new SqsEnvelope($result['MessageId'], $env);
}
示例4: schedule
/**
* Schedule a job in the future
*
* @access public
* @param Job $job
* @param DateTime $dateTime
* @return $this
*/
public function schedule(Job $job, DateTime $dateTime)
{
$now = new DateTime();
$when = clone $dateTime;
$delay = $when->getTimestamp() - $now->getTimestamp();
$this->sqsClient->sendMessage(array('QueueUrl' => $this->sqsUrl, 'MessageBody' => $job->serialize(), 'VisibilityTimeout' => $delay));
return $this;
}
示例5: publish
/**
* {@inheritDoc}
*/
public function publish(MessageInterface $message)
{
$result = $this->client->sendMessage(array('MessageBody' => $message->getBody(), 'QueueUrl' => $this->queueUrl));
$message->addAttribute('MD5OfMessageAttributes', $result['MD5OfMessageAttributes']);
$message->addAttribute('MD5OfMessageBody', $result['MD5OfMessageBody']);
$message->addAttribute('MessageId', $result['MessageId']);
return $message;
}
示例6: sendSqsMessage
/**
* @param mixed[] $args
* @return Result
* @throws ExceptionInterface
*/
private function sendSqsMessage(array $args = [])
{
$claimCheckSerializer = $this->configuration->getClaimCheckSerializer();
$message = array_key_exists('MessageBody', $args) ? $args['MessageBody'] : '';
$claimCheck = $this->storeMessageInS3($message);
$args['MessageBody'] = $claimCheckSerializer->serialize($claimCheck);
return $this->sqsClient->sendMessage($args);
}
示例7: enqueue
/**
* @param $jobId int
* @param $data array
* @param $delay int
* @return int $messageId
*/
public function enqueue($jobId, $data = [], $delay = 0)
{
$job = ['jobId' => $jobId, 'component' => $this->componentName];
if (count($data)) {
$job = array_merge($job, $data);
}
$message = $this->client->sendMessage(['QueueUrl' => $this->queueUrl, 'MessageBody' => json_encode($job), 'DelaySeconds' => $delay]);
return $message['MessageId'];
}
示例8: postJob
/**
* Post the job to queue.
*
* @param Job $job The job posted to the queue.
*
* @return boolean whether operation succeed.
*/
public function postJob(Job $job)
{
$model = $this->_client->sendMessage(['QueueUrl' => $this->url, 'MessageBody' => $this->serialize($job)]);
if ($model !== null) {
$job->id = $model['MessageId'];
return true;
} else {
return false;
}
}
示例9: send
/**
* Sends a message to SQS using a JSON output from a given Message object
*
* @param Message $message A message object to be sent to the queue
* @return bool returns true if message is sent successfully, otherwise false
*/
public function send(Message $message)
{
try {
// Send the message
$this->sqs_client->sendMessage(array('QueueUrl' => $this->url, 'MessageBody' => $message->asJson()));
return true;
} catch (Exception $e) {
echo 'Error sending message to queue ' . $e->getMessage();
return false;
}
}
示例10: addMessage
/**
* @inheritdoc
*
* @throws SqsException
*/
public function addMessage($queueName, $message, $priority = null)
{
if (null === $priority) {
$priority = $this->priorityHandler->getDefault();
}
if (empty($queueName)) {
throw new InvalidArgumentException('Parameter queueName empty or not defined.');
}
if (empty($message)) {
throw new InvalidArgumentException('Parameter message empty or not defined.');
}
$message = serialize($message);
$queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl');
$this->sqsClient->sendMessage(['QueueUrl' => $queueUrl, 'MessageBody' => $message]);
return $this;
}
示例11: send
/**
* @param MessageInterface $message
*
* @throws \RuntimeException
*
* @return Model
*/
public function send(MessageInterface $message)
{
$packer = $this->getPacker();
if (!$packer) {
throw new \RuntimeException('Packer not defined');
}
return $this->client->sendMessage(array('QueueUrl' => $this->getQueueUrl(), 'MessageBody' => $packer->encode($message)));
}
示例12: sendJSON
/**
* Send JSON data
*
* @link http://docs.aws.amazon.com/aws-sdk-php/v2/api/class-Aws.Sqs.SqsClient.html#_sendMessage
* @param $data
* @param null $delaySeconds
* @param null $priority
* @return bool|\Guzzle\Service\Resource\Model
*/
public function sendJSON($data, $delaySeconds = null, $priority = null)
{
if (empty($this->url)) {
return false;
}
$sendData = ['QueueUrl' => $this->url, 'MessageBody' => SafeJson::encode($data)];
if ($delaySeconds != null) {
$sendData['DelaySeconds'] = $delaySeconds;
}
if ($priority != null) {
$sendData['MessageAttributes'] = ["Priority" => ['DataType' => 'Number', 'StringValue' => $priority]];
}
return $this->client->sendMessage($sendData);
}
示例13: sendMessage
public function sendMessage($payroll, $delay = 0, $attributes = [])
{
$args = ["QueueUrl" => $this->getQueueUrl(), "MessageBody" => $payroll];
if ($delay) {
$args['DelaySeconds'] = $delay;
}
if ($attributes) {
$args['MessageAttributes'] = $attributes;
}
$result = $this->client->sendMessage($args);
$sent_msg = new SqsSentMessage($result->toArray());
$md5 = md5($payroll);
if ($result['MD5OfMessageBody'] != $md5) {
throw new \RuntimeException("MD5 of payroll is different on sent message!");
}
return $sent_msg;
}
示例14: addMessage
/**
* @inheritdoc
*
* @throws \InvalidArgumentException
* @throws \InvalidArgumentException
* @throws QueueAccessException
*/
public function addMessage($queueName, $message, Priority $priority = null, $delaySeconds = 0)
{
if (empty($queueName)) {
throw new \InvalidArgumentException('Queue name empty or not defined.');
}
if (empty($message)) {
throw new InvalidMessageException($message, 'Message empty or not defined.');
}
if (null === $priority) {
$priority = $this->priorityHandler->getDefault();
}
$message = serialize($message);
try {
$queueUrl = $this->sqsClient->getQueueUrl(['QueueName' => $this->getQueueNameWithPrioritySuffix($queueName, $priority)])->get('QueueUrl');
$this->sqsClient->sendMessage(['QueueUrl' => $queueUrl, 'MessageBody' => $message, 'delaySeconds' => $delaySeconds]);
} catch (SqsException $e) {
throw new QueueAccessException('Cannot add message in queue.', 0, $e);
}
return $this;
}
示例15: publish
/**
* {@inheritDoc}
*
* This method will either use a SNS Topic to publish a queued message or
* straight to SQS depending on the application configuration.
*
* @return string
*/
public function publish(array $message, array $options = [])
{
$options = $this->mergeOptions($options);
$publishStart = microtime(true);
// ensures that the SQS Queue and SNS Topic exist
if (!$this->queueExists()) {
$this->create();
}
if ($options['push_notifications']) {
if (!$this->topicExists()) {
$this->create();
}
$message = ['default' => $this->getNameWithPrefix(), 'sqs' => json_encode($message), 'http' => $this->getNameWithPrefix(), 'https' => $this->getNameWithPrefix()];
$result = $this->sns->publish(['TopicArn' => $this->topicArn, 'Subject' => $this->getName(), 'Message' => json_encode($message), 'MessageStructure' => 'json']);
$context = ['TopicArn' => $this->topicArn, 'MessageId' => $result->get('MessageId'), 'push_notifications' => $options['push_notifications'], 'publish_time' => microtime(true) - $publishStart];
$this->log(200, "Message published to SNS", $context);
return $result->get('MessageId');
}
$result = $this->sqs->sendMessage(['QueueUrl' => $this->queueUrl, 'MessageBody' => json_encode($message), 'DelaySeconds' => $options['message_delay']]);
$context = ['QueueUrl' => $this->queueUrl, 'MessageId' => $result->get('MessageId'), 'push_notifications' => $options['push_notifications']];
$this->log(200, "Message published to SQS", $context);
return $result->get('MessageId');
}