private function connect()
 {
     self::$connection = new AMQPStreamConnection(self::RABBIT_MQ_HOST, self::RABBIT_MQ_PORT, self::RABBIT_MQ_USER, self::RABBIT_MQ_PASSWORD);
     self::$channel = self::$connection->channel();
     self::$channel->queue_declare(self::RABBIT_MQ_QUEUE, false, true, false, false);
 }
 public static function calcAverage($recipient_id)
 {
     self::connect();
     $criteria = array('recipient_id' => $recipient_id);
     $ratings = self::$collection->find($criteria, array('rating' => 1));
     $ratingsCount = self::$collection->count($criteria);
     self::closeConnection();
     $result = 0;
     foreach ($ratings as $rating) {
         $result += $rating['rating'];
     }
     $average = round(round($result / $ratingsCount, 3, PHP_ROUND_HALF_EVEN), 1);
     $userRating = array('id' => $recipient_id, 'rating' => $average);
     UserRatingPublisher::publish($userRating);
 }