Creates a subscription to a given topic. See the [resource name rules] (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names). If the subscription already exists, returns ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND. If the name is not provided in the request, the server will assign a random name for this subscription on the same project as the topic, conforming to the [resource name format] (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names). The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.

Scopes

You will need authorization for at least one of the following scopes to make a valid call:

  • https://www.googleapis.com/auth/cloud-platform
  • https://www.googleapis.com/auth/pubsub

If unset, the scope for this method defaults to https://www.googleapis.com/auth/cloud-platform. You can set the scope for this method like this: pubsub1 --scope <scope> projects subscriptions-create ...

Required Scalar Argument

  • <name> (string)
    • Required. The name of the subscription. It must have the format &#34;projects/{project}/subscriptions/{subscription}&#34;. {subscription} must start with a letter, and contain only letters ([A-Za-z]), numbers ([0-9]), dashes (-), underscores (_), periods (.), tildes (~), plus (+) or percent signs (%). It must be between 3 and 255 characters in length, and it must not start with &#34;goog&#34;.

Required Request Value

The request value is a data-structure with various fields. Each field may be a simple scalar or another data-structure. In the latter case it is advised to set the field-cursor to the data-structure's field to specify values more concisely.

For example, a structure like this:

Subscription:
  ack-deadline-seconds: integer
  bigquery-config:
    drop-unknown-fields: boolean
    service-account-email: string
    state: string
    table: string
    use-table-schema: boolean
    use-topic-schema: boolean
    write-metadata: boolean
  cloud-storage-config:
    avro-config:
      write-metadata: boolean
    bucket: string
    filename-prefix: string
    filename-suffix: string
    max-bytes: string
    max-duration: string
    service-account-email: string
    state: string
  dead-letter-policy:
    dead-letter-topic: string
    max-delivery-attempts: integer
  detached: boolean
  enable-exactly-once-delivery: boolean
  enable-message-ordering: boolean
  expiration-policy:
    ttl: string
  filter: string
  labels: { string: string }
  message-retention-duration: string
  name: string
  push-config:
    attributes: { string: string }
    no-wrapper:
      write-metadata: boolean
    oidc-token:
      audience: string
      service-account-email: string
    push-endpoint: string
  retain-acked-messages: boolean
  retry-policy:
    maximum-backoff: string
    minimum-backoff: string
  state: string
  topic: string
  topic-message-retention-duration: string

can be set completely with the following arguments which are assumed to be executed in the given order. Note how the cursor position is adjusted to the respective structures, allowing simple field names to be used most of the time.

  • -r . ack-deadline-seconds=58
    • Optional. The approximate amount of time (on a best-effort basis) Pub/Sub waits for the subscriber to acknowledge receipt before resending the message. In the interval after the message is delivered and before it is acknowledged, it is considered to be outstanding. During that time period, the message will not be redelivered (on a best-effort basis). For pull subscriptions, this value is used as the initial value for the ack deadline. To override this value for a given message, call ModifyAckDeadline with the corresponding ack_id if using non-streaming pull or send the ack_id in a StreamingModifyAckDeadlineRequest if using streaming pull. The minimum custom deadline you can specify is 10 seconds. The maximum custom deadline you can specify is 600 seconds (10 minutes). If this parameter is 0, a default value of 10 seconds is used. For push delivery, this value is also used to set the request timeout for the call to the push endpoint. If the subscriber never acknowledges the message, the Pub/Sub system will eventually redeliver the message.
  • bigquery-config drop-unknown-fields=false
    • Optional. When true and use_topic_schema is true, any fields that are a part of the topic schema that are not part of the BigQuery table schema are dropped when writing to BigQuery. Otherwise, the schemas must be kept in sync and any messages with extra fields are not written and remain in the subscription's backlog.
  • service-account-email=sed
    • Optional. The service account to use to write to BigQuery. The subscription creator or updater that specifies this field must have iam.serviceAccounts.actAs permission on the service account. If not specified, the Pub/Sub service agent, service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com, is used.
  • state=no
    • Output only. An output-only field that indicates whether or not the subscription can receive messages.
  • table=stet
    • Optional. The name of the table to which to write data, of the form {projectId}.{datasetId}.{tableId}
  • use-table-schema=true
    • Optional. When true, use the BigQuery table's schema as the columns to write to in BigQuery. use_table_schema and use_topic_schema cannot be enabled at the same time.
  • use-topic-schema=true
    • Optional. When true, use the topic's schema as the columns to write to in BigQuery, if it exists. use_topic_schema and use_table_schema cannot be enabled at the same time.
  • write-metadata=false

    • Optional. When true, write the subscription name, message_id, publish_time, attributes, and ordering_key to additional columns in the table. The subscription name, message_id, and publish_time fields are put in their own columns while all other message properties (other than data) are written to a JSON object in the attributes column.
  • ..cloud-storage-config.avro-config write-metadata=false

    • Optional. When true, write the subscription name, message_id, publish_time, attributes, and ordering_key as additional fields in the output. The subscription name, message_id, and publish_time fields are put in their own fields while all other message properties other than data (for example, an ordering_key, if present) are added as entries in the attributes map.
  • .. bucket=duo

    • Required. User-provided name for the Cloud Storage bucket. The bucket must be created by the user. The bucket name must be without any prefix like "gs://". See the [bucket naming requirements] (https://cloud.google.com/storage/docs/buckets#naming).
  • filename-prefix=dolore
  • filename-suffix=et
  • max-bytes=voluptua.
    • Optional. The maximum bytes that can be written to a Cloud Storage file before a new file is created. Min 1 KB, max 10 GiB. The max_bytes limit may be exceeded in cases where messages are larger than the limit.
  • max-duration=amet.
    • Optional. The maximum duration that can elapse before a new Cloud Storage file is created. Min 1 minute, max 10 minutes, default 5 minutes. May not exceed the subscription's acknowledgement deadline.
  • service-account-email=consetetur
    • Optional. The service account to use to write to Cloud Storage. The subscription creator or updater that specifies this field must have iam.serviceAccounts.actAs permission on the service account. If not specified, the Pub/Sub service agent, service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com, is used.
  • state=diam

    • Output only. An output-only field that indicates whether or not the subscription can receive messages.
  • ..dead-letter-policy dead-letter-topic=dolor

    • Optional. The name of the topic to which dead letter messages should be published. Format is projects/{project}/topics/{topic}.The Pub/Sub service account associated with the enclosing subscription's parent project (i.e., service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com) must have permission to Publish() to this topic. The operation will fail if the topic does not exist. Users should ensure that there is a subscription attached to this topic since messages published to a topic with no subscriptions are lost.
  • max-delivery-attempts=83

    • Optional. The maximum number of delivery attempts for any message. The value must be between 5 and 100. The number of delivery attempts is defined as 1 + (the sum of number of NACKs and number of times the acknowledgement deadline has been exceeded for the message). A NACK is any call to ModifyAckDeadline with a 0 deadline. Note that client libraries may automatically extend ack_deadlines. This field will be honored on a best effort basis. If this parameter is 0, a default value of 5 is used.
  • .. detached=false

    • Optional. Indicates whether the subscription is detached from its topic. Detached subscriptions don't receive messages from their topic and don't retain any backlog. Pull and StreamingPull requests will return FAILED_PRECONDITION. If the subscription is a push subscription, pushes to the endpoint will not be made.
  • enable-exactly-once-delivery=false
    • Optional. If true, Pub/Sub provides the following guarantees for the delivery of a message with a given value of message_id on this subscription: * The message sent to a subscriber is guaranteed not to be resent before the message's acknowledgement deadline expires. * An acknowledged message will not be resent to a subscriber. Note that subscribers may still receive multiple copies of a message when enable_exactly_once_delivery is true if the message was published multiple times by a publisher client. These copies are considered distinct by Pub/Sub and have distinct message_id values.
  • enable-message-ordering=false
    • Optional. If true, messages published with the same ordering_key in PubsubMessage will be delivered to the subscribers in the order in which they are received by the Pub/Sub system. Otherwise, they may be delivered in any order.
  • expiration-policy ttl=vero

    • Optional. Specifies the "time-to-live" duration for an associated resource. The resource expires if it is not active for a period of ttl. The definition of "activity" depends on the type of the associated resource. The minimum and maximum allowed values for ttl depend on the type of the associated resource, as well. If ttl is not set, the associated resource never expires.
  • .. filter=invidunt

    • Optional. An expression written in the Pub/Sub filter language. If non-empty, then only PubsubMessages whose attributes field matches the filter are delivered on this subscription. If empty, then no messages are filtered out.
  • labels=key=stet
  • message-retention-duration=vero
    • Optional. How long to retain unacknowledged messages in the subscription's backlog, from the moment a message is published. If retain_acked_messages is true, then this also configures the retention of acknowledged messages, and thus configures how far back in time a Seek can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10 minutes.
  • name=elitr
    • Required. The name of the subscription. It must have the format &#34;projects/{project}/subscriptions/{subscription}&#34;. {subscription} must start with a letter, and contain only letters ([A-Za-z]), numbers ([0-9]), dashes (-), underscores (_), periods (.), tildes (~), plus (+) or percent signs (%). It must be between 3 and 255 characters in length, and it must not start with &#34;goog&#34;.
  • push-config attributes=key=lorem
    • Optional. Endpoint configuration attributes that can be used to control different aspects of the message delivery. The only currently supported attribute is x-goog-version, which you can use to change the format of the pushed message. This attribute indicates the version of the data expected by the endpoint. This controls the shape of the pushed message (i.e., its fields and metadata). If not present during the CreateSubscription call, it will default to the version of the Pub/Sub API used to make such call. If not present in a ModifyPushConfig call, its value will not be changed. GetSubscription calls will always return a valid version, even if the subscription was created without this attribute. The only supported values for the x-goog-version attribute are: * v1beta1: uses the push format defined in the v1beta1 Pub/Sub API. * v1 or v1beta2: uses the push format defined in the v1 Pub/Sub API. For example: attributes { &#34;x-goog-version&#34;: &#34;v1&#34; }
    • the value will be associated with the given key
  • no-wrapper write-metadata=true

    • Optional. When true, writes the Pub/Sub message metadata to x-goog-pubsub-: headers of the HTTP request. Writes the Pub/Sub message attributes to : headers of the HTTP request.
  • ..oidc-token audience=ipsum

    • Optional. Audience to be used when generating OIDC token. The audience claim identifies the recipients that the JWT is intended for. The audience value is a single case-sensitive string. Having multiple values (array) for the audience field is not supported. More info about the OIDC JWT token audience here: https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified, the Push endpoint URL will be used.
  • service-account-email=accusam

  • .. push-endpoint=takimata

    • Optional. A URL locating the endpoint to which messages should be pushed. For example, a Webhook endpoint might use https://example.com/push.
  • .. retain-acked-messages=true

    • Optional. Indicates whether to retain acknowledged messages. If true, then messages are not expunged from the subscription's backlog, even if they are acknowledged, until they fall out of the message_retention_duration window. This must be true if you would like to [Seek to a timestamp] (https://cloud.google.com/pubsub/docs/replay-overview#seek_to_a_time) in the past to replay previously-acknowledged messages.
  • retry-policy maximum-backoff=voluptua.
    • Optional. The maximum delay between consecutive deliveries of a given message. Value should be between 0 and 600 seconds. Defaults to 600 seconds.
  • minimum-backoff=et

    • Optional. The minimum delay between consecutive deliveries of a given message. Value should be between 0 and 600 seconds. Defaults to 10 seconds.
  • .. state=erat

    • Output only. An output-only field indicating whether or not the subscription can receive messages.
  • topic=consetetur
    • Required. The name of the topic from which this subscription is receiving messages. Format is projects/{project}/topics/{topic}. The value of this field will be _deleted-topic_ if the topic has been deleted.
  • topic-message-retention-duration=amet.
    • Output only. Indicates the minimum duration for which a message is retained after it is published to the subscription's topic. If this field is set, messages published to the subscription's topic in the last topic_message_retention_duration are always available to subscribers. See the message_retention_duration field in Topic. This field is set only in responses from the server; it is ignored if it is set in any requests.

About Cursors

The cursor position is key to comfortably set complex nested structures. The following rules apply:

  • The cursor position is always set relative to the current one, unless the field name starts with the . character. Fields can be nested such as in -r f.s.o .
  • The cursor position is set relative to the top-level structure if it starts with ., e.g. -r .s.s
  • You can also set nested fields without setting the cursor explicitly. For example, to set a value relative to the current cursor position, you would specify -r struct.sub_struct=bar.
  • You can move the cursor one level up by using ... Each additional . moves it up one additional level. E.g. ... would go three levels up.

Optional Output Flags

The method's return value a JSON encoded structure, which will be written to standard output by default.

  • -o out
    • out specifies the destination to which to write the server's result to. It will be a JSON-encoded structure. The destination may be - to indicate standard output, or a filepath that is to contain the received bytes. If unset, it defaults to standard output.

Optional General Properties

The following properties can configure any call, and are not specific to this method.

  • -p $-xgafv=string

    • V1 error format.
  • -p access-token=string

    • OAuth access token.
  • -p alt=string

    • Data format for response.
  • -p callback=string

    • JSONP
  • -p fields=string

    • Selector specifying which fields to include in a partial response.
  • -p key=string

    • API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
  • -p oauth-token=string

    • OAuth 2.0 token for the current user.
  • -p pretty-print=boolean

    • Returns response with indentations and line breaks.
  • -p quota-user=string

    • Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
  • -p upload-type=string

    • Legacy upload protocol for media (e.g. "media", "multipart").
  • -p upload-protocol=string

    • Upload protocol for media (e.g. "raw", "multipart").