-
Notifications
You must be signed in to change notification settings - Fork 5
/
amqp_test.php
45 lines (36 loc) · 1.08 KB
/
amqp_test.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
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
//AMQP PHP library test
require_once('amqp.inc');
$EXCHANGE = 'test';
$BROKER_HOST = 'localhost';
$BROKER_PORT = 5672;
$QUEUE = 'echo';
$USER ='guest';
$PASSWORD ='guest';
$msg_body = NULL;
try
{
echo "Creating connection\n";
$conn = new AMQPConnection($BROKER_HOST, $BROKER_PORT,
$USER,
$PASSWORD);
echo "Getting channel\n";
$ch = $conn->channel();
echo "Requesting access\n";
$ch->access_request('/data', false, false, true, true);
echo "Declaring exchange\n";
$ch->exchange_declare($EXCHANGE, 'direct', false, false, false);
echo "Creating message\n";
$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain'));
echo "Publishing message\n";
$ch->basic_publish($msg, $EXCHANGE, $QUEUE);
echo "Closing channel\n";
$ch->close();
echo "Closing connection\n";
$conn->close();
echo "Done.\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage();
echo "\nTrace:\n" . $e->getTraceAsString();
}
?>