# Cloud Pub/Sub API . subscriptions

## Instance Methods

Acknowledges a particular received message: the Pub/Sub system can remove the given message from the subscription. Acknowledging a message whose Ack deadline has expired may succeed, but the message could have been already redelivered. Acknowledging a message more than once will not result in an error. This is only used for messages received via pull.

Creates a subscription on a given topic for a given subscriber. If the subscription already exists, returns ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND.

Deletes an existing subscription. All pending messages in the subscription are immediately dropped. Calls to Pull after deletion will return NOT_FOUND.

Gets the configuration details of a subscription.

Lists matching subscriptions.

Retrieves the next page of results.

Modifies the Ack deadline for a message received from a pull request.

Modifies the PushConfig for a specified subscription. This method can be used to suspend the flow of messages to an end point by clearing the PushConfig field in the request. Messages will be accumulated for delivery even if no push configuration is defined or while the configuration is modified.

Pulls a single message from the server. If return_immediately is true, and no messages are available in the subscription, this method returns FAILED_PRECONDITION. The system is free to return an UNAVAILABLE error if no messages are available in a reasonable amount of time (to reduce system load).

### Method Details

`acknowledge(body)`

    Acknowledges a particular received message: the Pub/Sub system can remove the given message from the subscription. Acknowledging a message whose Ack deadline has expired may succeed, but the message could have been already redelivered. Acknowledging a message more than once will not result in an error. This is only used for messages received via pull.

    Args:
      body: object, The request body. (required)
        The object takes the form of:

    {
        "ackId": [ # The Ack ID for the message being acknowledged. This was returned by the Pub/Sub system in the Pull response.
          "A String",
        ],
        "subscription": "A String", # The subscription whose message is being acknowledged.
      }

`create(body)`

    Creates a subscription on a given topic for a given subscriber. If the subscription already exists, returns ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND.

    Args:
      body: object, The request body. (required)
        The object takes the form of:

    { # A subscription resource.
      "ackDeadlineSeconds": 42, # For either push or pull delivery, the value is the maximum time after a subscriber receives a message before the subscriber should acknowledge or Nack the message. If the Ack deadline for a message passes without an Ack or a Nack, the Pub/Sub system will eventually redeliver the message. If a subscriber acknowledges after the deadline, the Pub/Sub system may accept the Ack, but it is possible that the message has been already delivered again. Multiple Acks to the message are allowed and will succeed.
          #
          # For push delivery, this value is used to set the request timeout for the call to the push endpoint.
          #
          # For pull delivery, this value is used as the initial value for the Ack deadline. It may be overridden for a specific pull request (message) with ModifyAckDeadline. While a message is outstanding (i.e. it has been delivered to a pull subscriber and the subscriber has not yet Acked or Nacked), the Pub/Sub system will not deliver that message to another pull subscriber (on a best-effort basis).
      "topic": "A String", # The name of the topic from which this subscription is receiving messages.
      "pushConfig": { # Configuration for a push delivery endpoint. # If push delivery is used with this subscription, this field is used to configure it.
        "pushEndpoint": "A String", # A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use "https://example.com/push".
      },
      "name": "A String", # Name of the subscription.
    }

    Returns:
      An object of the form:

        { # A subscription resource.
        "ackDeadlineSeconds": 42, # For either push or pull delivery, the value is the maximum time after a subscriber receives a message before the subscriber should acknowledge or Nack the message. If the Ack deadline for a message passes without an Ack or a Nack, the Pub/Sub system will eventually redeliver the message. If a subscriber acknowledges after the deadline, the Pub/Sub system may accept the Ack, but it is possible that the message has been already delivered again. Multiple Acks to the message are allowed and will succeed.
            #
            # For push delivery, this value is used to set the request timeout for the call to the push endpoint.
            #
            # For pull delivery, this value is used as the initial value for the Ack deadline. It may be overridden for a specific pull request (message) with ModifyAckDeadline. While a message is outstanding (i.e. it has been delivered to a pull subscriber and the subscriber has not yet Acked or Nacked), the Pub/Sub system will not deliver that message to another pull subscriber (on a best-effort basis).
        "topic": "A String", # The name of the topic from which this subscription is receiving messages.
        "pushConfig": { # Configuration for a push delivery endpoint. # If push delivery is used with this subscription, this field is used to configure it.
          "pushEndpoint": "A String", # A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use "https://example.com/push".
        },
        "name": "A String", # Name of the subscription.
      }

`delete(subscription)`

    Deletes an existing subscription. All pending messages in the subscription are immediately dropped. Calls to Pull after deletion will return NOT_FOUND.

    Args:
      subscription: string, The subscription to delete. (required)

`get(subscription)`

    Gets the configuration details of a subscription.

    Args:
      subscription: string, The name of the subscription to get. (required)

    Returns:
      An object of the form:

        { # A subscription resource.
        "ackDeadlineSeconds": 42, # For either push or pull delivery, the value is the maximum time after a subscriber receives a message before the subscriber should acknowledge or Nack the message. If the Ack deadline for a message passes without an Ack or a Nack, the Pub/Sub system will eventually redeliver the message. If a subscriber acknowledges after the deadline, the Pub/Sub system may accept the Ack, but it is possible that the message has been already delivered again. Multiple Acks to the message are allowed and will succeed.
            #
            # For push delivery, this value is used to set the request timeout for the call to the push endpoint.
            #
            # For pull delivery, this value is used as the initial value for the Ack deadline. It may be overridden for a specific pull request (message) with ModifyAckDeadline. While a message is outstanding (i.e. it has been delivered to a pull subscriber and the subscriber has not yet Acked or Nacked), the Pub/Sub system will not deliver that message to another pull subscriber (on a best-effort basis).
        "topic": "A String", # The name of the topic from which this subscription is receiving messages.
        "pushConfig": { # Configuration for a push delivery endpoint. # If push delivery is used with this subscription, this field is used to configure it.
          "pushEndpoint": "A String", # A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use "https://example.com/push".
        },
        "name": "A String", # Name of the subscription.
      }

`list(pageToken=None, maxResults=None, query=None)`

    Lists matching subscriptions.

    Args:
      pageToken: string, The value obtained in the last ListSubscriptionsResponse for continuation.
      maxResults: integer, Maximum number of subscriptions to return.
      query: string, A valid label query expression.

    Returns:
      An object of the form:

        {
        "nextPageToken": "A String", # If not empty, indicates that there are more subscriptions that match the request and this value should be passed to the next ListSubscriptionsRequest to continue.
        "subscription": [ # The subscriptions that match the request.
          { # A subscription resource.
            "ackDeadlineSeconds": 42, # For either push or pull delivery, the value is the maximum time after a subscriber receives a message before the subscriber should acknowledge or Nack the message. If the Ack deadline for a message passes without an Ack or a Nack, the Pub/Sub system will eventually redeliver the message. If a subscriber acknowledges after the deadline, the Pub/Sub system may accept the Ack, but it is possible that the message has been already delivered again. Multiple Acks to the message are allowed and will succeed.
                #
                # For push delivery, this value is used to set the request timeout for the call to the push endpoint.
                #
                # For pull delivery, this value is used as the initial value for the Ack deadline. It may be overridden for a specific pull request (message) with ModifyAckDeadline. While a message is outstanding (i.e. it has been delivered to a pull subscriber and the subscriber has not yet Acked or Nacked), the Pub/Sub system will not deliver that message to another pull subscriber (on a best-effort basis).
            "topic": "A String", # The name of the topic from which this subscription is receiving messages.
            "pushConfig": { # Configuration for a push delivery endpoint. # If push delivery is used with this subscription, this field is used to configure it.
              "pushEndpoint": "A String", # A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use "https://example.com/push".
            },
            "name": "A String", # Name of the subscription.
          },
        ],
      }

`list_next(previous_request, previous_response)`

    Retrieves the next page of results.

    Args:
      previous_request: The request for the previous page. (required)
      previous_response: The response from the request for the previous page. (required)

    Returns:
      A request object that you can call 'execute()' on to request the next
      page. Returns None if there are no more items in the collection.

`modifyAckDeadline(body)`

    Modifies the Ack deadline for a message received from a pull request.

    Args:
      body: object, The request body. (required)
        The object takes the form of:

    {
        "ackDeadlineSeconds": 42, # The new Ack deadline. Must be >= 0.
        "ackId": "A String", # The Ack ID.
        "subscription": "A String", # The name of the subscription from which messages are being pulled.
      }

`modifyPushConfig(body)`

    Modifies the PushConfig for a specified subscription. This method can be used to suspend the flow of messages to an end point by clearing the PushConfig field in the request. Messages will be accumulated for delivery even if no push configuration is defined or while the configuration is modified.

    Args:
      body: object, The request body. (required)
        The object takes the form of:

    {
        "pushConfig": { # Configuration for a push delivery endpoint. # An empty push_config indicates that the Pub/Sub system should pause pushing messages from the given subscription.
          "pushEndpoint": "A String", # A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use "https://example.com/push".
        },
        "subscription": "A String", # The name of the subscription.
      }

`pull(body)`

    Pulls a single message from the server. If return_immediately is true, and no messages are available in the subscription, this method returns FAILED_PRECONDITION. The system is free to return an UNAVAILABLE error if no messages are available in a reasonable amount of time (to reduce system load).

    Args:
      body: object, The request body. (required)
        The object takes the form of:

    {
        "returnImmediately": True or False, # If this is specified as true the system will respond immediately even if it is not able to return a message in the Pull response. Otherwise the system is allowed to wait until at least one message is available rather than returning FAILED_PRECONDITION. The client may cancel the request if it does not wish to wait any longer for the response.
        "subscription": "A String", # The subscription from which a message should be pulled.
      }

    Returns:
      An object of the form:

        { # Either a PubsubMessage or a truncation event. One of these two must be populated.
        "pubsubEvent": { # An event indicating a received message or truncation event. # A pubsub message or truncation event.
          "deleted": True or False, # Indicates that this subscription has been deleted. (Note that pull subscribers will always receive NOT_FOUND in response in their pull request on the subscription, rather than seeing this boolean.)
          "message": { # A message data and its labels. # A received message.
            "data": "A String", # The message payload.
            "label": [ # Optional list of labels for this message. Keys in this collection must be unique.
              { # A key-value pair applied to a given object.
                "numValue": "A String", # An integer value.
                "strValue": "A String", # A string value.
                "key": "A String", # The key of a label is a syntactically valid URL (as per RFC 1738) with the "scheme" and initial slashes omitted and with the additional restrictions noted below. Each key should be globally unique. The "host" portion is called the "namespace" and is not necessarily resolvable to a network endpoint. Instead, the namespace indicates what system or entity defines the semantics of the label. Namespaces do not restrict the set of objects to which a label may be associated.
                    #
                    # Keys are defined by the following grammar:
                    #
                    # key = hostname "/" kpath kpath = ksegment *[ "/" ksegment ] ksegment = alphadigit | *[ alphadigit | "-" | "_" | "." ]
                    #
                    # where "hostname" and "alphadigit" are defined as in RFC 1738.
                    #
                    # Example key: spanner.google.com/universe
              },
            ],
          },
          "truncated": True or False, # Indicates that this subscription has been truncated.
          "subscription": "A String", # The subscription that received the event.
        },
        "ackId": "A String", # This ID must be used to acknowledge the received event or message.
      }