switch to a topical exchange

This commit is contained in:
Graham Christensen 2017-10-31 04:09:06 -04:00
parent 3f0fcfbc4b
commit 544a32776e
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C

View file

@ -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);
} 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";