Google\Cloud\PubSub\V1\PublisherClient::publish PHP Method

publish() public method

Sample code: try { $publisherClient = new PublisherClient(); $formattedTopic = PublisherClient::formatTopicName("[PROJECT]", "[TOPIC]"); $data = ""; $messagesElement = new PubsubMessage(); $messagesElement->setData($data); $messages = [$messagesElement]; $response = $publisherClient->publish($formattedTopic, $messages); } finally { if (isset($publisherClient)) { $publisherClient->close(); } }
public publish ( string $topic, google\pubsub\v1\PubsubMessage[] $messages, array $optionalArgs = [] ) : google\pubsub\v1\PublishResponse
$topic string The messages in the request will be published on this topic. Format is `projects/{project}/topics/{topic}`.
$messages google\pubsub\v1\PubsubMessage[] The messages to publish.
$optionalArgs array { Optional. @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\PublishResponse
    public function publish($topic, $messages, $optionalArgs = [])
    {
        $request = new PublishRequest();
        $request->setTopic($topic);
        foreach ($messages as $elem) {
            $request->addMessages($elem);
        }
        $mergedSettings = $this->defaultCallSettings['publish']->merge(new CallSettings($optionalArgs));
        $callable = ApiCallable::createApiCall($this->publisherStub, 'Publish', $mergedSettings, $this->descriptors['publish']);
        return $callable($request, [], ['call_credentials_callback' => $this->createCredentialsCallback()]);
    }