Client(**kwargs)
A subscriber client for Google Cloud Pub/Sub.
This creates an object that is capable of subscribing to messages. Generally, you can instantiate this client with no arguments, and you get sensible defaults.
Parameter
Name | Description |
kwargs |
dict Example: .. code-block:: python from google.cloud import pubsub_v1 subscriber_client = pubsub_v1.SubscriberClient( # Optional client_options = { "api_endpoint": REGIONAL_ENDPOINT } )
Any additional arguments provided are sent as keyword keyword arguments to the underlying SubscriberClient. Generally you should not need to set additional keyword arguments. Optionally, regional endpoints can be set via |
Inheritance
builtins.object > ClientProperties
api
The underlying gapic API client.
target
Return the target (where the API is).
Type | Description |
str | The location of the API. |
Methods
acknowledge
acknowledge(request: google.cloud.pubsub_v1.types.AcknowledgeRequest = None, *, subscription: str = None, ack_ids: Sequence[str] = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Acknowledges the messages associated with the ack_ids
in the
AcknowledgeRequest
. The Pub/Sub system can remove the
relevant messages from the subscription.
Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later. Acknowledging a message more than once will not result in an error.
Name | Description |
request |
google.pubsub_v1.types.AcknowledgeRequest
The request object. Request for the Acknowledge method. |
subscription |
str
Required. The subscription whose message is being acknowledged. Format is |
ack_ids |
Sequence[str]
Required. The acknowledgment ID for the messages being acknowledged that was returned by the Pub/Sub system in the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
close
close()
Close the underlying channel to release socket resources.
After a channel has been closed, the client instance cannot be used anymore.
This method is idempotent.
common_billing_account_path
common_billing_account_path(billing_account: str)
Return a fully-qualified billing_account string.
common_folder_path
common_folder_path(folder: str)
Return a fully-qualified folder string.
common_location_path
common_location_path(project: str, location: str)
Return a fully-qualified location string.
common_organization_path
common_organization_path(organization: str)
Return a fully-qualified organization string.
common_project_path
common_project_path(project: str)
Return a fully-qualified project string.
create_snapshot
create_snapshot(request: google.cloud.pubsub_v1.types.CreateSnapshotRequest = None, *, name: str = None, subscription: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Creates a snapshot from the requested subscription. Snapshots
are used in
Seek <https://cloud.google.com/pubsub/docs/replay-overview>
__
operations, which allow you to manage message acknowledgments in
bulk. That is, you can set the acknowledgment state of messages
in an existing subscription to the state captured by a snapshot.
If the snapshot already exists, returns ALREADY_EXISTS
. If
the requested subscription doesn't exist, returns NOT_FOUND
.
If the backlog in the subscription is too old -- and the
resulting snapshot would expire in less than 1 hour -- then
FAILED_PRECONDITION
is returned. See also the
Snapshot.expire_time
field. If the name is not provided in
the request, the server will assign a random name for this
snapshot on the same project as the subscription, conforming to
the resource name format. The
generated name is populated in the returned Snapshot object.
Note that for REST API requests, you must specify a name in the
request.
Name | Description |
request |
google.pubsub_v1.types.CreateSnapshotRequest
The request object. Request for the |
name |
str
Required. User-provided name for this snapshot. If the name is not provided in the request, the server will assign a random name for this snapshot on the same project as the subscription. Note that for REST API requests, you must specify a name. See the resource name rules. Format is |
subscription |
str
Required. The subscription whose backlog the snapshot retains. Specifically, the created snapshot is guaranteed to retain: (a) The existing backlog on the subscription. More precisely, this is defined as the messages in the subscription's backlog that are unacknowledged upon the successful completion of the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.Snapshot | A snapshot resource. Snapshots are used in [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. |
create_subscription
create_subscription(request: google.cloud.pubsub_v1.types.Subscription = None, *, name: str = None, topic: str = None, push_config: google.cloud.pubsub_v1.types.PushConfig = None, ack_deadline_seconds: int = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Creates a subscription to a given topic. See the resource name
rules. 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. The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.
Name | Description |
request |
google.pubsub_v1.types.Subscription
The request object. A subscription resource. |
name |
str
Required. The name of the subscription. It must have the format |
topic |
str
Required. The name of the topic from which this subscription is receiving messages. Format is |
push_config |
google.pubsub_v1.types.PushConfig
If push delivery is used with this subscription, this field is used to configure it. An empty |
ack_deadline_seconds |
int
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 |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.Subscription | A subscription resource. |
delete_snapshot
delete_snapshot(request: google.cloud.pubsub_v1.types.DeleteSnapshotRequest = None, *, snapshot: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Removes an existing snapshot. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. When the snapshot is deleted, all messages retained in the snapshot are immediately dropped. After a snapshot is deleted, a new one may be created with the same name, but the new one has no association with the old snapshot or its subscription, unless the same subscription is specified.
Name | Description |
request |
google.pubsub_v1.types.DeleteSnapshotRequest
The request object. Request for the |
snapshot |
str
Required. The name of the snapshot to delete. Format is |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
delete_subscription
delete_subscription(request: google.cloud.pubsub_v1.types.DeleteSubscriptionRequest = None, *, subscription: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Deletes an existing subscription. All messages retained in the
subscription are immediately dropped. Calls to Pull
after
deletion will return NOT_FOUND
. After a subscription is
deleted, a new one may be created with the same name, but the
new one has no association with the old subscription or its
topic unless the same topic is specified.
Name | Description |
request |
google.pubsub_v1.types.DeleteSubscriptionRequest
The request object. Request for the DeleteSubscription method. |
subscription |
str
Required. The subscription to delete. Format is |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
from_service_account_file
from_service_account_file(filename, **kwargs)
Creates an instance of this client using the provided credentials file.
Name | Description |
filename |
str
The path to the service account private key json file. |
from_service_account_info
from_service_account_info(info: dict, *args, **kwargs)
Creates an instance of this client using the provided credentials info.
Name | Description |
info |
dict
The service account private key info. |
Type | Description |
SubscriberClient | The constructed client. |
from_service_account_json
from_service_account_json(filename, **kwargs)
Creates an instance of this client using the provided credentials file.
Name | Description |
filename |
str
The path to the service account private key json file. |
get_iam_policy
get_iam_policy(request: google.iam.v1.iam_policy_pb2.GetIamPolicyRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Gets the IAM access control policy for a function. Returns an empty policy if the function exists and does not have a policy set.
Name | Description |
request |
`.iam_policy.GetIamPolicyRequest`
The request object. Request message for |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
`.policy.Policy` | Defines an Identity and Access Management (IAM) policy. It is used to specify access control policies for Cloud Platform resources. A ``Policy`` is a collection of ``bindings``. A ``binding`` binds one or more ``members`` to a single ``role``. Members can be user accounts, service accounts, Google groups, and domains (such as G Suite). A ``role`` is a named list of permissions (defined by IAM or configured by users). A ``binding`` can optionally specify a ``condition``, which is a logic expression that further constrains the role binding based on attributes about the request and/or target resource. **JSON Example**:: { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": ["user:eve@example.com"], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01t00:00:00.000z')",="" }="" }="" ]="" }="" **yaml="" example**::="" bindings:="" -="" members:="" -="" user:mike@example.com="" -="" group:admins@example.com="" -="" domain:google.com="" -="" serviceaccount:my-project-id@appspot.gserviceaccount.com="" role:="" roles/resourcemanager.organizationadmin="" -="" members:="" -="" user:eve@example.com="" role:="" roles/resourcemanager.organizationviewer="" condition:="" title:="" expirable="" access="" description:="" does="" not="" grant="" access="" after="" sep="" 2020="" expression:="" request.time="">< timestamp('2020-10-01t00:00:00.000z')="" for="" a="" description="" of="" iam="" and="" its="" features,="" see="" the="" `iam="" developer's="" guide=""> |
get_snapshot
get_snapshot(request: google.cloud.pubsub_v1.types.GetSnapshotRequest = None, *, snapshot: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Gets the configuration details of a snapshot. Snapshots are used in a href="https://cloud.google.com/pubsub/docs/replay- overview"Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
Name | Description |
request |
google.pubsub_v1.types.GetSnapshotRequest
The request object. Request for the GetSnapshot method. |
snapshot |
str
Required. The name of the snapshot to get. Format is |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.Snapshot | A snapshot resource. Snapshots are used in [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. |
get_subscription
get_subscription(request: google.cloud.pubsub_v1.types.GetSubscriptionRequest = None, *, subscription: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Gets the configuration details of a subscription.
Name | Description |
request |
google.pubsub_v1.types.GetSubscriptionRequest
The request object. Request for the GetSubscription method. |
subscription |
str
Required. The name of the subscription to get. Format is |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.Subscription | A subscription resource. |
list_snapshots
list_snapshots(request: google.cloud.pubsub_v1.types.ListSnapshotsRequest = None, *, project: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Lists the existing snapshots. Snapshots are used in
Seek <https://cloud.google.com/pubsub/docs/replay-overview>
__
operations, which allow you to manage message acknowledgments in
bulk. That is, you can set the acknowledgment state of messages
in an existing subscription to the state captured by a snapshot.
Name | Description |
request |
google.pubsub_v1.types.ListSnapshotsRequest
The request object. Request for the |
project |
str
Required. The name of the project in which to list snapshots. Format is |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.services.subscriber.pagers.ListSnapshotsPager | Response for the ListSnapshots method. Iterating over this object will yield results and resolve additional pages automatically. |
list_subscriptions
list_subscriptions(request: google.cloud.pubsub_v1.types.ListSubscriptionsRequest = None, *, project: str = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Lists matching subscriptions.
Name | Description |
request |
google.pubsub_v1.types.ListSubscriptionsRequest
The request object. Request for the |
project |
str
Required. The name of the project in which to list subscriptions. Format is |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.services.subscriber.pagers.ListSubscriptionsPager | Response for the ListSubscriptions method. Iterating over this object will yield results and resolve additional pages automatically. |
modify_ack_deadline
modify_ack_deadline(request: google.cloud.pubsub_v1.types.ModifyAckDeadlineRequest = None, *, subscription: str = None, ack_ids: Sequence[str] = None, ack_deadline_seconds: int = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Modifies the ack deadline for a specific message. This method is
useful to indicate that more time is needed to process a message
by the subscriber, or to make the message available for
redelivery if the processing was interrupted. Note that this
does not modify the subscription-level ackDeadlineSeconds
used for subsequent messages.
Name | Description |
request |
google.pubsub_v1.types.ModifyAckDeadlineRequest
The request object. Request for the ModifyAckDeadline method. |
subscription |
str
Required. The name of the subscription. Format is |
ack_ids |
Sequence[str]
Required. List of acknowledgment IDs. This corresponds to the |
ack_deadline_seconds |
int
Required. The new ack deadline with respect to the time this request was sent to the Pub/Sub system. For example, if the value is 10, the new ack deadline will expire 10 seconds after the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
modify_push_config
modify_push_config(request: google.cloud.pubsub_v1.types.ModifyPushConfigRequest = None, *, subscription: str = None, push_config: google.cloud.pubsub_v1.types.PushConfig = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Modifies the PushConfig
for a specified subscription.
This may be used to change a push subscription to a pull one
(signified by an empty PushConfig
) or vice versa, or change
the endpoint URL and other attributes of a push subscription.
Messages will accumulate for delivery continuously through the
call regardless of changes to the PushConfig
.
Name | Description |
request |
google.pubsub_v1.types.ModifyPushConfigRequest
The request object. Request for the ModifyPushConfig method. |
subscription |
str
Required. The name of the subscription. Format is |
push_config |
google.pubsub_v1.types.PushConfig
Required. The push configuration for future deliveries. An empty |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
parse_common_billing_account_path
parse_common_billing_account_path(path: str)
Parse a billing_account path into its component segments.
parse_common_folder_path
parse_common_folder_path(path: str)
Parse a folder path into its component segments.
parse_common_location_path
parse_common_location_path(path: str)
Parse a location path into its component segments.
parse_common_organization_path
parse_common_organization_path(path: str)
Parse a organization path into its component segments.
parse_common_project_path
parse_common_project_path(path: str)
Parse a project path into its component segments.
parse_snapshot_path
parse_snapshot_path(path: str)
Parse a snapshot path into its component segments.
parse_subscription_path
parse_subscription_path(path: str)
Parse a subscription path into its component segments.
parse_topic_path
parse_topic_path(path: str)
Parse a topic path into its component segments.
pull
pull(request: google.cloud.pubsub_v1.types.PullRequest = None, *, subscription: str = None, return_immediately: bool = None, max_messages: int = None, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Pulls messages from the server. The server may return
UNAVAILABLE
if there are too many concurrent pull requests
pending for the given subscription.
Name | Description |
request |
google.pubsub_v1.types.PullRequest
The request object. Request for the |
subscription |
str
Required. The subscription from which messages should be pulled. Format is |
return_immediately |
bool
Optional. If this field set to true, the system will respond immediately even if it there are no messages available to return in the |
max_messages |
int
Required. The maximum number of messages to return for this request. Must be a positive integer. The Pub/Sub system may return fewer than the number specified. This corresponds to the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.PullResponse | Response for the Pull method. |
seek
seek(request: google.cloud.pubsub_v1.types.SeekRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Seeks an existing subscription to a point in time or to a given snapshot, whichever is provided in the request. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. Note that both the subscription and the snapshot must be on the same topic.
Name | Description |
request |
google.pubsub_v1.types.SeekRequest
The request object. Request for the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.SeekResponse | Response for the Seek method (this response is empty). |
set_iam_policy
set_iam_policy(request: google.iam.v1.iam_policy_pb2.SetIamPolicyRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Sets the IAM access control policy on the specified function. Replaces any existing policy.
Name | Description |
request |
`.iam_policy.SetIamPolicyRequest`
The request object. Request message for |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
`.policy.Policy` | Defines an Identity and Access Management (IAM) policy. It is used to specify access control policies for Cloud Platform resources. A ``Policy`` is a collection of ``bindings``. A ``binding`` binds one or more ``members`` to a single ``role``. Members can be user accounts, service accounts, Google groups, and domains (such as G Suite). A ``role`` is a named list of permissions (defined by IAM or configured by users). A ``binding`` can optionally specify a ``condition``, which is a logic expression that further constrains the role binding based on attributes about the request and/or target resource. **JSON Example**:: { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:mike@example.com", "group:admins@example.com", "domain:google.com", "serviceAccount:my-project-id@appspot.gserviceaccount.com" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": ["user:eve@example.com"], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01t00:00:00.000z')",="" }="" }="" ]="" }="" **yaml="" example**::="" bindings:="" -="" members:="" -="" user:mike@example.com="" -="" group:admins@example.com="" -="" domain:google.com="" -="" serviceaccount:my-project-id@appspot.gserviceaccount.com="" role:="" roles/resourcemanager.organizationadmin="" -="" members:="" -="" user:eve@example.com="" role:="" roles/resourcemanager.organizationviewer="" condition:="" title:="" expirable="" access="" description:="" does="" not="" grant="" access="" after="" sep="" 2020="" expression:="" request.time="">< timestamp('2020-10-01t00:00:00.000z')="" for="" a="" description="" of="" iam="" and="" its="" features,="" see="" the="" `iam="" developer's="" guide=""> |
snapshot_path
snapshot_path(project: str, snapshot: str)
Return a fully-qualified snapshot string.
streaming_pull
streaming_pull(requests: Iterator[google.cloud.pubsub_v1.types.StreamingPullRequest] = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Establishes a stream with the server, which sends messages down
to the client. The client streams acknowledgements and ack
deadline modifications back to the server. The server will close
the stream and return the status on any error. The server may
close the stream with status UNAVAILABLE
to reassign
server-side resources, in which case, the client should
re-establish the stream. Flow control can be achieved by
configuring the underlying RPC channel.
Name | Description |
requests |
Iterator[google.pubsub_v1.types.StreamingPullRequest]
The request object iterator. Request for the |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
Iterable[google.pubsub_v1.types.StreamingPullResponse] | Response for the StreamingPull method. This response is used to stream messages from the server to the client. |
subscribe
subscribe(
subscription,
callback,
flow_control=(),
scheduler=None,
use_legacy_flow_control=False,
await_callbacks_on_shutdown=False,
)
Asynchronously start receiving messages on a given subscription.
This method starts a background thread to begin pulling messages from
a Pub/Sub subscription and scheduling them to be processed using the
provided callback
.
The callback
will be called with an individual
xref_Message. It is the
responsibility of the callback to either call ack()
or nack()
on the message when it finished processing. If an exception occurs in
the callback during processing, the exception is logged and the message
is nack()
ed.
The flow_control
argument can be used to control the rate of at
which messages are pulled. The settings are relatively conservative by
default to prevent "message hoarding" - a situation where the client
pulls a large number of messages but can not process them fast enough
leading it to "starve" other clients of messages. Increasing these
settings may lead to faster throughput for messages that do not take
a long time to process.
The use_legacy_flow_control
argument disables enforcing flow control
settings at the Cloud Pub/Sub server, and only the client side flow control
will be enforced.
This method starts the receiver in the background and returns a
Future representing its execution. Waiting on the future (calling
result()
) will block forever or until a non-recoverable error
is encountered (such as loss of network connectivity). Cancelling the
future will signal the process to shutdown gracefully and exit.
Example:
from google.cloud import pubsub_v1
subscriber_client = pubsub_v1.SubscriberClient()
# existing subscription
subscription = subscriber_client.subscription_path(
'my-project-id', 'my-subscription')
def callback(message):
print(message)
message.ack()
future = subscriber_client.subscribe(
subscription, callback)
try:
future.result()
except KeyboardInterrupt:
future.cancel() # Trigger the shutdown.
future.result() # Block until the shutdown is complete.
Name | Description |
subscription |
str
The name of the subscription. The subscription should have already been created (for example, by using |
callback |
Callable[Message]
The callback function. This function receives the message as its only argument and will be called from a different thread/ process depending on the scheduling strategy. |
flow_control |
FlowControl
The flow control settings. Use this to prevent situations where you are inundated with too many messages at once. |
scheduler |
Scheduler
An optional scheduler to use when executing the callback. This controls how callbacks are executed concurrently. This object must not be shared across multiple SubscriberClients. |
use_legacy_flow_control |
bool
If set to |
await_callbacks_on_shutdown |
bool
If |
subscription_path
subscription_path(project: str, subscription: str)
Return a fully-qualified subscription string.
test_iam_permissions
test_iam_permissions(request: google.iam.v1.iam_policy_pb2.TestIamPermissionsRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Tests the specified permissions against the IAM access control policy for a function. If the function does not exist, this will return an empty set of permissions, not a NOT_FOUND error.
Name | Description |
request |
`.iam_policy.TestIamPermissionsRequest`
The request object. Request message for |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
`.iam_policy.TestIamPermissionsResponse` | Response message for ``TestIamPermissions`` method. |
topic_path
topic_path(project: str, topic: str)
Return a fully-qualified topic string.
update_snapshot
update_snapshot(request: google.cloud.pubsub_v1.types.UpdateSnapshotRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Updates an existing snapshot. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
Name | Description |
request |
google.pubsub_v1.types.UpdateSnapshotRequest
The request object. Request for the UpdateSnapshot method. |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.Snapshot | A snapshot resource. Snapshots are used in [Seek](https://cloud.google.com/pubsub/docs/replay-overview) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. |
update_subscription
update_subscription(request: google.cloud.pubsub_v1.types.UpdateSubscriptionRequest = None, *, retry: google.api_core.retry.Retry = <object object>, timeout: float = None, metadata: Sequence[Tuple[str, str]] = ())
Updates an existing subscription. Note that certain properties of a subscription, such as its topic, are not modifiable.
Name | Description |
request |
google.pubsub_v1.types.UpdateSubscriptionRequest
The request object. Request for the UpdateSubscription method. |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. |
timeout |
float
The timeout for this request. |
metadata |
Sequence[Tuple[str, str]]
Strings which should be sent along with the request as metadata. |
Type | Description |
google.pubsub_v1.types.Subscription | A subscription resource. |