Skip to content

Instantly share code, notes, and snippets.

@inarli
Last active January 9, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inarli/3db15c734d6ac6d1fb51807be538c2e5 to your computer and use it in GitHub Desktop.
Save inarli/3db15c734d6ac6d1fb51807be538c2e5 to your computer and use it in GitHub Desktop.
scheduledPublish
<?php
public function scheduledPublish()
{
$headers = new AMQPTable();
$delay = 60000; // 1 minute
$headers->set('x-delay', $delay, AMQPTable::T_INT_LONG);
$exchangeName = 'delayed';
$routingKey = 'delayed-messages';
$properties = [
'content_type' => 'text/plain',
'delivery_mode' => 2
];
$payload = [
'message' => 'A scheduled RabbitMQ message'
];
$msg = new AMQPMessage(json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), $properties);
$msg->set('application_headers', $headers);
try {
$this->channel->basic_publish($msg, $exchangeName, $routingKey, true);
$this->channel->wait_for_pending_acks();
} catch (\Exception $e) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment