Пример #1
0
 /**
  * Helper:  remove  message   sequence  record(s)  for  the  given
  * basic.{n}ack (RMQ Confirm key)
  */
 private function removeConfirmSeqs(wire\Method $meth, $event)
 {
     if (!$this->callbackHandler) {
         trigger_error("Received publish confirmations with no channel event handler in place", E_USER_WARNING);
         return;
     }
     $dtag = $meth->getField('delivery-tag');
     if ($meth->getField('multiple')) {
         foreach (array_keys($this->confirmSeqs) as $sk) {
             if ($sk <= $dtag) {
                 $this->callbackHandler->{$event}($this->confirmSeqs[$sk]);
                 unset($this->confirmSeqs[$sk]);
             }
         }
     } else {
         if (array_key_exists($dtag, $this->confirmSeqs)) {
             $this->callbackHandler->{$event}($this->confirmSeqs[$dtag]);
             unset($this->confirmSeqs[$dtag]);
         }
     }
 }
Пример #2
0
 /**
  * Send the given method immediately, optionally wait for the response.
  * @arg  Method     $inMeth         The method to send
  * @arg  boolean    $noWait         Flag that prevents the default behaviour of immediately
  *                                  waiting for a response - used mainly during consume.  NOTE
  *                                  that this mechanism can also be triggered via. the use of
  *                                  an Amqp no-wait domain field set to true
  */
 function invoke(wire\Method $inMeth, $noWait = false)
 {
     if (!$this->write($inMeth->toBin($this->getProtocolLoader()))) {
         throw new \Exception("Send message failed (1)", 5623);
     }
     if (!$noWait && $inMeth->getMethodProto()->getSpecResponseMethods()) {
         if ($inMeth->getMethodProto()->hasNoWaitField()) {
             foreach ($inMeth->getMethodProto()->getFields() as $f) {
                 if ($f->getSpecDomainName() == 'no-wait' && $inMeth->getField($f->getSpecFieldName())) {
                     return;
                 }
             }
         }
         while (true) {
             if (!($buff = $this->read())) {
                 throw new \Exception(sprintf("(2) Send message failed for %s", $inMeth->amqpClass), 5624);
             }
             $meths = $this->readMessages($buff);
             foreach (array_keys($meths) as $k) {
                 $meth = $meths[$k];
                 unset($meths[$k]);
                 if ($inMeth->isResponse($meth)) {
                     if ($meths) {
                         $this->unDelivered = array_merge($this->unDelivered, $meths);
                     }
                     return $meth;
                 } else {
                     $this->unDelivered[] = $meth;
                 }
             }
         }
     }
 }