From 544a32776e66845ff00a90f1e6e7bd6fe05868f2 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 31 Oct 2017 04:09:06 -0400 Subject: [PATCH] switch to a topical exchange --- web/index.php | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/web/index.php b/web/index.php index 5435e52..3af86bc 100644 --- a/web/index.php +++ b/web/index.php @@ -6,22 +6,39 @@ use PhpAmqpLib\Message\AMQPMessage; $connection = rabbitmq_conn(); $channel = $connection->channel(); -$input = json_decode(file_get_contents('php://input'), true); -if (!isset($input['repository']['full_name'])) { +$raw = file_get_contents('php://input'); +$input = json_decode($raw); +if (!isset($input->repository->full_name)) { echo "no full_name set?"; - exit(0); + exit(); +} else { + echo "full_name present\n"; } - -$name = strtolower($input['repository']['full_name']); +$name = strtolower($input->repository->full_name); if (!GHE\ACL::isRepoEligible($name)) { - echo "repo not in ok name list"; - exit(1); + echo "repo not in ok name list"; + exit(1); +} else { + echo "full_name ok\n"; } -$channel->exchange_declare($name, 'fanout', false, true, false); +$dec = $channel->exchange_declare('github-events', 'topic', false, true, false); $message = new AMQPMessage(json_encode($input), - array('content_type' => 'application/json')); + array( + 'content_type' => 'application/json', + 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT, + )); -$channel->basic_publish($message, $name); +try { + $etype = \GHE\EventClassifier::classifyEvent($input); +} catch (\GHE\EventClassifierUnknownException $e) { + $etype = "unknown"; +} + +$routing_key = "$etype.$name"; +var_dump($routing_key); +$rec = $channel->basic_publish($message, 'github-events', $routing_key); + +echo "ok"; \ No newline at end of file