Skip to content

Instantly share code, notes, and snippets.

@kish2011
Last active September 23, 2019 17:00
Show Gist options
  • Save kish2011/9676e25f772f8968bedc2c12acd80b93 to your computer and use it in GitHub Desktop.
Save kish2011/9676e25f772f8968bedc2c12acd80b93 to your computer and use it in GitHub Desktop.
Sending message to RabbitMQ
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
$msg = new AMQPMessage('Hello World!');
$channel->basic_publish($msg, '', 'hello');
echo " [x] Sent 'Hello World!'\n";
$channel->close();
$connection->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment