Skip to content

Instantly share code, notes, and snippets.

@benedmunds
Created April 22, 2017 21:07
Show Gist options
  • Save benedmunds/ab6b546fe0a053f06d390726f36c3de1 to your computer and use it in GitHub Desktop.
Save benedmunds/ab6b546fe0a053f06d390726f36c3de1 to your computer and use it in GitHub Desktop.
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
//connect to rabbit server
$connection = new AMQPStreamConnection(
'localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
//create the queue
/*public function queue_declare(
$queue = '',
$passive = false,
$durable = false,
$exclusive = false,
$auto_delete = true,
$nowait = false,
$arguments = null,
$ticket = null
)
*/
$channel->queue_declare('notification', false, true, false, false);
//generate a message obj
$notification = [
'id' => microtime(),
'sender_id' => 1,
'recipient_id' => 2,
'message' => 'yo',
'callbackQueue' => 'calendarComplete123'
];
//send it!
$msg = new AMQPMessage(json_encode($notification));
$channel->basic_publish($msg, '', 'notification');
//$ rabbitmqadmin get queue=notifications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment