示例#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;
     }
 }
示例#3
0
 /**
  * @param MessageInterface $message
  */
 protected function publishMessage(MessageInterface $message)
 {
     // Connect
     $this->connector->connect();
     // Publish message
     if (true == $this->publishOnQueue) {
         $this->connector->basicPublish($message, '', $this->publicationsQueue);
     } else {
         $this->connector->basicPublish($message, $this->publicationsExchange, $this->publicationsRoutingKey);
     }
 }
示例#4
0
 /**
  * @param string $routingKey
  * @param string $procedure
  * @param array $params
  * @param bool $closeConnectionAfterCall
  *
  * @return RpcResponsePayload
  */
 public function call($routingKey, $procedure, array $params = [], $closeConnectionAfterCall = false)
 {
     // Reset current response object
     $this->resetCurrentRpcResponse();
     // Connect
     $this->connector->connect();
     // Declare responses queue
     $this->declareResponsesQueue();
     // Create an empty request message
     $request = MessagesBuilder::emptyRpcRequest($this->getSerializer()->getSerializedContentType());
     // Set message payload
     $request->setPayload(RpcRequestPayload::create($procedure, $params));
     // Set other message properties
     $request->setExpiration(1000 * $this->getTimeOut());
     $request->setReplyTo($this->responsesQueue);
     // Send request
     $this->sendRequest($request, $routingKey);
     if (true == $closeConnectionAfterCall) {
         $this->connector->closeConnection();
     }
     return $this->rpcResponse->getPayload();
 }