Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.