Example #1
0
 /**
  * @return void
  */
 public function run()
 {
     $this->connector->connect();
     $this->connector->defineQoS(1);
     $this->connector->basicConsume($this->requestsQueue, $this->getCallback());
     while (count($this->connector->getChannelCallbacks())) {
         $this->logger->debug('Waiting...');
         $this->connector->wait();
     }
     $this->connector->closeConnection();
 }
 /**
  * @throws \Exception
  */
 public function run()
 {
     $this->numberOfReceivedMessages = 0;
     try {
         // Connect
         $this->connector->connect();
         // Start consuming
         $this->connector->basicConsume($this->queue, $this->getCallback());
         while (0 < count($this->connector->getChannelCallbacks())) {
             $this->connector->wait();
         }
         // Close connection
         $this->connector->closeConnection();
     } catch (ConnectorException $e) {
         $this->logger->warning($e->getMessage());
         // Try reconnection
         $this->connector->connect(true);
     } catch (\ErrorException $e) {
         $this->logger->warning($e->getMessage());
         // Try reconnection
         $this->connector->connect(true);
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage());
         throw $e;
     }
 }
Example #3
0
 /**
  * @param RpcRequestMessage $request
  * @param string $routingKey
  */
 protected final function sendRequest(RpcRequestMessage $request, $routingKey)
 {
     $this->correlarionId = $request->getCorrelationId();
     // Publish request message
     $this->connector->basicPublish($request, $this->exchange, $routingKey);
     // Wait for response
     $this->logger->debug('Waiting for response...', ['body' => $request->getBody(), 'properties' => $request->getProperties()]);
     $this->connector->basicConsume($this->responsesQueue, $this->getCallback());
     while (!$this->rpcResponse) {
         $this->connector->wait($this->getTimeOut());
     }
 }