From 6220cc37208023acaa6cbc134c2b5253a077c4eb Mon Sep 17 00:00:00 2001 From: David Good Date: Sat, 2 Jan 2016 20:02:35 -0600 Subject: [PATCH 1/3] Added Chapter 3 php example that works with debian packages --- php/chapter-3/rabbitmqctl-examples-debian.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 php/chapter-3/rabbitmqctl-examples-debian.php diff --git a/php/chapter-3/rabbitmqctl-examples-debian.php b/php/chapter-3/rabbitmqctl-examples-debian.php new file mode 100644 index 0000000..9943ec3 --- /dev/null +++ b/php/chapter-3/rabbitmqctl-examples-debian.php @@ -0,0 +1,32 @@ +channel(); + +$channel->exchange_declare('logs-exchange', 'topic', false, true, false); + +$channel->queue_declare('msg-inbox-errors', false, true, false, false); +$channel->queue_declare('msg-inbox-logs', false, true, false, false); +$channel->queue_declare('all-logs', false, true, false, false); + +$channel->queue_bind('msg-inbox-errors', 'logs-exchange', 'error.msg-inbox'); +$channel->queue_bind('msg-inbox-logs', 'logs-exchange', '*.msg-inbox'); + +?> From 35fc5de4d19313d5274b063fb5cb54e3dff42c72 Mon Sep 17 00:00:00 2001 From: David Good Date: Sat, 2 Jan 2016 20:05:38 -0600 Subject: [PATCH 2/3] Removed commented out code --- php/chapter-3/rabbitmqctl-examples-debian.php | 1 - 1 file changed, 1 deletion(-) diff --git a/php/chapter-3/rabbitmqctl-examples-debian.php b/php/chapter-3/rabbitmqctl-examples-debian.php index 9943ec3..fe0fad7 100644 --- a/php/chapter-3/rabbitmqctl-examples-debian.php +++ b/php/chapter-3/rabbitmqctl-examples-debian.php @@ -17,7 +17,6 @@ function ($class) { define('VHOST', '/'); $conn = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST); -//$conn = new AMQPConnection(HOST, PORT, USER, PASS); $channel = $conn->channel(); $channel->exchange_declare('logs-exchange', 'topic', false, true, false); From 385cad5536a2a14a965fecf62c20a0b3b2983aa3 Mon Sep 17 00:00:00 2001 From: David Good Date: Sun, 3 Jan 2016 01:02:57 -0600 Subject: [PATCH 3/3] Added log-listeners-debian.php and config-debian.php --- php/chapter-3/log-listeners-debian.php | 51 ++++++++++++++++++++++++++ php/config/config-debian.php | 23 ++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 php/chapter-3/log-listeners-debian.php create mode 100644 php/config/config-debian.php diff --git a/php/chapter-3/log-listeners-debian.php b/php/chapter-3/log-listeners-debian.php new file mode 100644 index 0000000..045de19 --- /dev/null +++ b/php/chapter-3/log-listeners-debian.php @@ -0,0 +1,51 @@ +channel(); + +list($errors_queue, , ) = $ch->queue_declare(); +list($warnings_queue, , ) = $ch->queue_declare(); +list($info_queue, , ) = $ch->queue_declare(); + +$exchange = 'amq.rabbitmq.log'; + +$ch->queue_bind($errors_queue, $exchange, "error"); +$ch->queue_bind($warnings_queue, $exchange, "warning"); +$ch->queue_bind($info_queue, $exchange, "info"); + +$error_callback = function($msg) { + echo 'error: ', $msg->body, "\n"; + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); +}; + +$warning_callback = function($msg) { + echo 'warning: ', $msg->body, "\n"; + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); +}; + +$info_callback = function($msg) { + echo 'info: ', $msg->body, "\n"; + $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); +}; + +$ch->basic_consume($errors_queue, "", false, + false, false, false, + $error_callback); + +$ch->basic_consume($warnings_queue, "", false, + false, false, false, + $warning_callback); + +$ch->basic_consume($info_queue, "", false, + false, false, false, + $info_callback); + +while(count($ch->callbacks)) { + $ch->wait(); +} + +?> diff --git a/php/config/config-debian.php b/php/config/config-debian.php new file mode 100644 index 0000000..4020ce0 --- /dev/null +++ b/php/config/config-debian.php @@ -0,0 +1,23 @@ + \ No newline at end of file