-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublisher.php
32 lines (24 loc) · 838 Bytes
/
publisher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require_once '../vendor/autoload.php';
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Connection\AMQPStreamConnection;
// CloudAMQP configuration
$host = 'crane.rmq.cloudamqp.com';
$port = 5672;
$user = 'xxxxx';
$password = 'xxxxx';
$vhost = 'xxxxx';
// Initiated connection to CloudAMQP
$conn = new AMQPStreamConnection($host, $port, $user, $password, $vhost);
$channel = $conn->channel();
// Queue name, this name must be same with consumer.
$queueName = 'profile';
$channel->queue_declare($queueName, false, false, false, false);
// Initiate message to be send to consumer
$txt = 'My name is Mohd Norlihazmey Ghazali';
$msg = new AMQPMessage($txt);
$channel->basic_publish($msg, '', $queueName);
echo 'Message has been sent and place inside queue.';
// Close channel and connection
$channel->close();
$conn->close();