Last active
January 9, 2019 11:27
-
-
Save inarli/3db15c734d6ac6d1fb51807be538c2e5 to your computer and use it in GitHub Desktop.
scheduledPublish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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