Google\Cloud\PubSub\PubSubClient::subscribe PHP Method

subscribe() public method

Use {@see \Google\Cloud\PubSub\PubSubClient::subscription()} to create a subscription object without any API requests. If the topic already exists, an exception will be thrown. When in doubt, use {@see \Google\Cloud\PubSub\PubSubClient::subscription()}. Example: Create a subscription. If it doesn't exist in the API, it will be created. $subscription = $pubsub->subscribe('my-new-subscription', 'my-topic-name');
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create Create Subscription
public subscribe ( string $name, string $topicName, array $options = [] ) : Subscription
$name string A subscription name
$topicName string The topic to which the new subscription will be subscribed.
$options array [optional] Please see {@see \Google\Cloud\PubSub\Subscription::create()} for configuration details.
return Subscription
    public function subscribe($name, $topicName, array $options = [])
    {
        $subscription = $this->subscriptionFactory($name, $topicName);
        $subscription->create($options);
        return $subscription;
    }