/**
  * @param array       $vars
  * @param Client      $client
  * @param HttpRequest $httpRequest
  * @return mixed
  */
 public function relay($vars, Client $client, HttpRequest $httpRequest)
 {
     $url = $client->webHookEndPoint();
     $httpRequest->setAuth($client->name(), $client->apiKey());
     $httpRequest->post($url, $vars);
     return $httpRequest->statusCode() == 200 ? true : false;
 }
 /**
  * Listener for the queue
  * @param string $consumer_url
  * @param array $post_vars
  */
 public function consume($consumer_url, $post_vars = array())
 {
     $this->consumer_url = $consumer_url;
     $this->consumer_post = $post_vars;
     if ($this->consumer_count < $this->consumer_max) {
         $this->consumer_start = time();
         $callback = function (AMQPMessage $message) {
             $post_vars = $this->consumer_post;
             $post_vars['url'] = $this->consumer_url;
             $post_vars['queue'] = $this->queue;
             $post_vars['message'] = $message->body;
             $response = $this->httpRequest->post($this->consumer_url, $post_vars);
             $code = $this->httpRequest->statusCode();
             if ($code == 200) {
                 $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
             } else {
                 // log the error to a file
                 $log_message = $code . "\n\n";
                 $log_message .= $message->body . "\n\n";
                 $log_message .= print_r($message, true);
                 $log_message .= "\n\n\n";
                 $log_message .= print_r($response, true);
                 Log::error($log_message);
             }
             if ($this->consumer_start + $this->ttl < time()) {
                 $this->channel->basic_cancel($message->delivery_info['consumer_tag']);
             }
         };
         $this->channel->basic_consume($this->queue, '', false, false, false, false, $callback);
         while (count($this->channel->callbacks)) {
             $this->channel->wait();
         }
     }
 }
 /**
  * @param HttpRequest $httpRequest
  */
 public function fire(HttpRequest $httpRequest)
 {
     // the index is the name of the queue, the value is the URL the consumer should call to
     //     process the queue item
     $queues = array('AmbitiousMailSenderEmailSend' => Route('queueConsumerEmailSend'));
     $queue_consumer_url = Route('queueConsumerSetup');
     echo $queue_consumer_url;
     foreach ($queues as $queue_name => $url) {
         $requestData = ['url' => $url, 'queue_name' => $queue_name];
         $httpRequest->post($queue_consumer_url, $requestData, 1, true, false);
     }
 }