createSubscription() public method

public createSubscription ( array $args )
$args array
Example #1
0
 /**
  * Execute a service request creating the subscription.
  *
  * The suggested way of creating a subscription is by calling through
  * {@see Google\Cloud\PubSub\Topic::subscribe()} or {@see Google\Cloud\PubSub\Topic::subscription()}.
  *
  * Returns subscription info in the format detailed in the documentation
  * for a [subscription](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#Subscription).
  *
  * **NOTE: Some methods of instantiation of a Subscription do not supply a
  * topic name. The topic name is required to create a subscription.**
  *
  * Example:
  * ```
  * $topic = $pubsub->topic('my-topic-name');
  *
  * $subscription = $topic->subscription('my-new-subscription');
  * $result = $subscription->create();
  * ```
  *
  * @see https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create Create Subscription
  *
  * @param array $options [optional] {
  *     Configuration Options
  *
  *     @type int $ackDeadlineSeconds This value is the maximum time after a
  *           subscriber receives a message before the subscriber should
  *           acknowledge the message. **Defaults to** `10`.
  *     @type array $pushConfig See {@see Google\Cloud\PubSub\Subscription::modifyPushConfig()} or
  *           [PushConfig](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#PushConfig)
  *           for usage.
  * }
  * @return array An array of subscription info
  * @throws \InvalidArgumentException
  */
 public function create(array $options = [])
 {
     // If a subscription is created via PubSubClient::subscription(),
     // it may or may not have a topic name. This is fine for most API
     // interactions, but a topic name is required to create a subscription.
     if (!$this->topicName) {
         throw new InvalidArgumentException('A topic name is required to
             create a subscription.');
     }
     $this->info = $this->connection->createSubscription($options + ['name' => $this->name, 'topic' => $this->topicName]);
     return $this->info;
 }