src/Bunny/Channel.php
public function get($queue = "", $noAck = false)
    {
        if ($this->getDeferred !== null) {
            throw new ChannelException("Another 'basic.get' already in progress. You should use 'basic.consume' instead of multiple 'basic.get'.");
        }

        $response = $this->getImpl($queue, $noAck);

        if ($response instanceof PromiseInterface) {
            $this->getDeferred = new Deferred();

            $response->done(function ($frame) {
                if ($frame instanceof MethodBasicGetEmptyFrame) {
                    // deferred has to be first nullified and then resolved, otherwise results in race condition
                    $deferred = $this->getDeferred;
                    $this->getDeferred = null;
                    $deferred->resolve(null);

                } elseif ($frame instanceof MethodBasicGetOkFrame) {
                    $this->getOkFrame = $frame;
                    $this->state = ChannelStateEnum::AWAITING_HEADER;

                } else {
                    throw new \LogicException("This statement should never be reached.");
                }
            });

            return $this->getDeferred->promise();

        } elseif ($response instanceof MethodBasicGetEmptyFrame) {
            return null;

        } elseif ($response instanceof MethodBasicGetOkFrame) {
            $this->state = ChannelStateEnum::AWAITING_HEADER;

            $headerFrame = $this->getClient()->awaitContentHeader($this->getChannelId());
            $this->headerFrame = $headerFrame;
            $this->bodySizeRemaining = $headerFrame->bodySize;
            $this->state = ChannelStateEnum::AWAITING_BODY;

            while ($this->bodySizeRemaining > 0) {
                $bodyFrame = $this->getClient()->awaitContentBody($this->getChannelId());

                $this->bodyBuffer->append($bodyFrame->payload);
                $this->bodySizeRemaining -= $bodyFrame->payloadSize;

                if ($this->bodySizeRemaining < 0) {
                    $this->state = ChannelStateEnum::ERROR;
                    $this->client->disconnect(Constants::STATUS_SYNTAX_ERROR, $errorMessage = "Body overflow, received " . (-$this->bodySizeRemaining) . " more bytes.");
                    throw new ChannelException($errorMessage);
                }
            }

            $this->state = ChannelStateEnum::READY;

            $message = new Message(
                null,
                $response->deliveryTag,
                $response->redelivered,
                $response->exchange,
                $response->routingKey,
                $this->headerFrame->toArray(),
                $this->bodyBuffer->consume($this->bodyBuffer->getLength())
            );

            $this->headerFrame = null;

            return $message;

        } else {
            throw new \LogicException("This statement should never be reached.");
        }
    }
public function get($queue = "", $noAck = false)
    {
        if ($this->getDeferred !== null) {
            throw new ChannelException("Another 'basic.get' already in progress. You should use 'basic.consume' instead of multiple 'basic.get'.");
        }

        $response = $this->getImpl($queue, $noAck);

        if ($response instanceof PromiseInterface) {
            $this->getDeferred = new Deferred();

            $response->done(function ($frame) {
                if ($frame instanceof MethodBasicGetEmptyFrame) {
                    // deferred has to be first nullified and then resolved, otherwise results in race condition
                    $deferred = $this->getDeferred;
                    $this->getDeferred = null;
                    $deferred->resolve(null);

                } elseif ($frame instanceof MethodBasicGetOkFrame) {
                    $this->getOkFrame = $frame;
                    $this->state = ChannelStateEnum::AWAITING_HEADER;

                } else {
                    throw new \LogicException("This statement should never be reached.");
                }
            });

            return $this->getDeferred->promise();

        } elseif ($response instanceof MethodBasicGetEmptyFrame) {
            return null;

        } elseif ($response instanceof MethodBasicGetOkFrame) {
            $this->state = ChannelStateEnum::AWAITING_HEADER;

            $headerFrame = $this->getClient()->awaitContentHeader($this->getChannelId());
            $this->headerFrame = $headerFrame;
            $this->bodySizeRemaining = $headerFrame->bodySize;
            $this->state = ChannelStateEnum::AWAITING_BODY;

            while ($this->bodySizeRemaining > 0) {
                $bodyFrame = $this->getClient()->awaitContentBody($this->getChannelId());

                $this->bodyBuffer->append($bodyFrame->payload);
                $this->bodySizeRemaining -= $bodyFrame->payloadSize;

                if ($this->bodySizeRemaining < 0) {
                    $this->state = ChannelStateEnum::ERROR;
                    $this->client->disconnect(Constants::STATUS_SYNTAX_ERROR, $errorMessage = "Body overflow, received " . (-$this->bodySizeRemaining) . " more bytes.");
                    throw new ChannelException($errorMessage);
                }
            }

            $this->state = ChannelStateEnum::READY;

            $message = new Message(
                null,
                $response->deliveryTag,
                $response->redelivered,
                $response->exchange,
                $response->routingKey,
                $this->headerFrame->toArray(),
                $this->bodyBuffer->consume($this->bodyBuffer->getLength())
            );

            $this->headerFrame = null;

            return $message;

        } else {
            throw new \LogicException("This statement should never be reached.");
        }
    }
public function get ( $ queue = "" , $ noAck = false ) { if ( $ this -> getDeferred !== null ) { throw new ChannelException ( "Another 'basic.get' already in progress. You should use 'basic.consume' instead of multiple 'basic.get'." ) ; } $ response = $ this -> getImpl ( $ queue , $ noAck ) ; if ( $ response instanceof PromiseInterface ) { $ this -> getDeferred = new Deferred ( ) ; $ response -> done ( function ( $ frame ) { if ( $ frame instanceof MethodBasicGetEmptyFrame ) { // deferred has to be first nullified and then resolved, otherwise results in race condition $ deferred = $ this -> getDeferred ; $ this -> getDeferred = null ; $ deferred -> resolve ( null ) ; } elseif ( $ frame instanceof MethodBasicGetOkFrame ) { $ this -> getOkFrame = $ frame ; $ this -> state = ChannelStateEnum :: AWAITING_HEADER ; } else { throw new \ LogicException ( "This statement should never be reached." ) ; } } ) ; return $ this -> getDeferred -> promise ( ) ; } elseif ( $ response instanceof MethodBasicGetEmptyFrame ) { return null ; } elseif ( $ response instanceof MethodBasicGetOkFrame ) { $ this -> state = ChannelStateEnum :: AWAITING_HEADER ; $ headerFrame = $ this -> getClient ( ) -> awaitContentHeader ( $ this -> getChannelId ( ) ) ; $ this -> headerFrame = $ headerFrame ; $ this -> bodySizeRemaining = $ headerFrame -> bodySize ; $ this -> state = ChannelStateEnum :: AWAITING_BODY ; while ( $ this -> bodySizeRemaining > 0 ) { $ bodyFrame = $ this -> getClient ( ) -> awaitContentBody ( $ this -> getChannelId ( ) ) ; $ this -> bodyBuffer -> append ( $ bodyFrame -> payload ) ; $ this -> bodySizeRemaining -= $ bodyFrame -> payloadSize ; if ( $ this -> bodySizeRemaining < 0 ) { $ this -> state = ChannelStateEnum :: ERROR ; $ this -> client -> disconnect ( Constants :: STATUS_SYNTAX_ERROR , $ errorMessage = "Body overflow, received " . ( - $ this -> bodySizeRemaining ) . " more bytes." ) ; throw new ChannelException ( $ errorMessage ) ; } } $ this -> state = ChannelStateEnum :: READY ; $ message = new Message ( null , $ response -> deliveryTag , $ response -> redelivered , $ response -> exchange , $ response -> routingKey , $ this -> headerFrame -> toArray ( ) , $ this -> bodyBuffer -> consume ( $ this -> bodyBuffer -> getLength ( ) ) ) ; $ this -> headerFrame = null ; return $ message ; } else { throw new \ LogicException ( "This statement should never be reached." ) ; } }
Synchronously returns message if there is any waiting in the queue.

@param string $queue
@param bool $noAck
@return Message|PromiseInterface
Synchronously returns message if there is any waiting in the queue .