Beispiel #1
0
def list_subscriptions(stub, topic):
    """Lists topics in the given project."""
    req = pubsub_pb2.ListTopicSubscriptionsRequest(topic=topic, page_size=1)
    try:
        resp = stub.ListTopicSubscriptions(req, TIMEOUT)
        for t in resp.subscriptions:
            print("Subscription is: {}".format(t))
    except NetworkError, e:
        logging.warning('Failed to list topics: {}'.format(e))
        sys.exit(1)
    def list_topic_subscriptions(self, topic, page_size=0, options=None):
        """
        Lists the name of the subscriptions for this topic.

        Example:
          >>> from google.cloud.gapic.pubsub.v1 import publisher_api
          >>> from google.gax import CallOptions, INITIAL_PAGE
          >>> api = publisher_api.PublisherApi()
          >>> topic = api.topic_path('[PROJECT]', '[TOPIC]')
          >>>
          >>> # Iterate over all results
          >>> for element in api.list_topic_subscriptions(topic):
          >>>   # process element
          >>>   pass
          >>>
          >>> # Or iterate over results one page at a time
          >>> for page in api.list_topic_subscriptions(topic, options=CallOptions(page_token=INITIAL_PAGE)):
          >>>   for element in page:
          >>>     # process element
          >>>     pass

        Args:
          topic (string): The name of the topic that subscriptions are attached to.
          page_size (int): The maximum number of resources contained in the
            underlying API response. If page streaming is performed per-
            resource, this parameter does not affect the return value. If page
            streaming is performed per-page, this determines the maximum number
            of resources in a page.
          options (:class:`google.gax.CallOptions`): Overrides the default
            settings for this call, e.g, timeout, retries etc.

        Returns:
          A :class:`google.gax.PageIterator` instance. By default, this
          is an iterable of string instances.
          This object can also be configured to iterate over the pages
          of the response through the `CallOptions` parameter.

        Raises:
          :exc:`google.gax.errors.GaxError` if the RPC is aborted.
          :exc:`ValueError` if the parameters are invalid.
        """
        request = pubsub_pb2.ListTopicSubscriptionsRequest(topic=topic,
                                                           page_size=page_size)
        return self._list_topic_subscriptions(request, options)