コード例 #1
0
ファイル: Consumer.php プロジェクト: Mailclark/bot2hook
 public function incoming($msg)
 {
     $body = json_decode($msg->body);
     $retry = empty($body->retry) ? 0 : $body->retry;
     $this->rabbitmq->ack($msg);
     $this->execute('b2h_incoming', $msg->body, $retry);
 }
コード例 #2
0
 protected function retry(\Exception $e, $queue, $data, $retry)
 {
     $this->logger->err($e->getMessage());
     echo $e->getMessage() . "\n";
     echo $e->getTraceAsString() . "\n";
     if (is_object($data)) {
         $data->retry = $retry + 1;
     } elseif (is_array($data)) {
         $data['retry'] = $retry + 1;
     } else {
         $temp_data = json_decode($data);
         if (!empty($temp_data)) {
             if (is_object($data)) {
                 $temp_data->retry = $retry + 1;
             } elseif (is_array($data)) {
                 $temp_data['retry'] = $retry + 1;
             }
             $data = json_encode($temp_data);
         }
     }
     try {
         if ($retry <= 5) {
             $delay = 30;
         } elseif ($retry <= 10) {
             $delay = 2 * 60;
         } elseif ($retry <= 15) {
             $delay = 30 * 60;
         } elseif ($retry <= 20) {
             $delay = 4 * 60 * 60;
         } elseif ($retry <= 25) {
             $delay = 24 * 60 * 60;
         } else {
             throw $e;
         }
         $this->rabbitmq->publishStringDelayed($delay, $queue, json_encode($data));
     } catch (\Exception $e) {
         $this->logger->err('Stop retry for consumer queue ' . $queue . ': ' . print_r(json_encode($data), true));
     }
 }
コード例 #3
0
ファイル: Server.php プロジェクト: Mailclark/bot2hook
 protected function publish(Bot $bot, $data)
 {
     $this->rabbitmq->publishString($this->config['rabbit_outgoing_queue'], json_encode(array_merge(['bot' => $bot->bot_id, 'team' => $bot->team_id], $data)));
 }