Google\Cloud\PubSub\V1\SubscriberClient::pull PHP Method

pull() public method

Sample code: try { $subscriberClient = new SubscriberClient(); $formattedSubscription = SubscriberClient::formatSubscriptionName("[PROJECT]", "[SUBSCRIPTION]"); $maxMessages = 0; $response = $subscriberClient->pull($formattedSubscription, $maxMessages); } finally { if (isset($subscriberClient)) { $subscriberClient->close(); } }
public pull ( string $subscription, integer $maxMessages, array $optionalArgs = [] ) : google\pubsub\v1\PullResponse
$subscription string The subscription from which messages should be pulled. Format is `projects/{project}/subscriptions/{sub}`.
$maxMessages integer The maximum number of messages returned for this request. The Pub/Sub system may return fewer than the number specified.
$optionalArgs array { Optional. @type bool $returnImmediately If this field set to true, the system will respond immediately even if it there are no messages available to return in the `Pull` response. Otherwise, the system may wait (for a bounded amount of time) until at least one message is available, rather than returning no messages. The client may cancel the request if it does not wish to wait any longer for the response. @type \Google\GAX\RetrySettings $retrySettings Retry settings to use for this call. If present, then $timeoutMillis is ignored. @type int $timeoutMillis Timeout to use for this call. Only used if $retrySettings is not set. }
return google\pubsub\v1\PullResponse
    public function pull($subscription, $maxMessages, $optionalArgs = [])
    {
        $request = new PullRequest();
        $request->setSubscription($subscription);
        $request->setMaxMessages($maxMessages);
        if (isset($optionalArgs['returnImmediately'])) {
            $request->setReturnImmediately($optionalArgs['returnImmediately']);
        }
        $mergedSettings = $this->defaultCallSettings['pull']->merge(new CallSettings($optionalArgs));
        $callable = ApiCallable::createApiCall($this->subscriberStub, 'Pull', $mergedSettings, $this->descriptors['pull']);
        return $callable($request, [], ['call_credentials_callback' => $this->createCredentialsCallback()]);
    }