Skip to content
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d218232
chore: regenerate the library with microgenerator
plamut Jul 14, 2020
529c853
Update setup.py for Python 3.6+
plamut Jul 14, 2020
a744caf
Fix GAPIC types imports
plamut Jul 14, 2020
f416327
Inject SERVICE_ADDRESS and _DEFAULT_SCOPES to generated classes
plamut Jul 15, 2020
256081a
Cleanup types.py
plamut Jul 15, 2020
dbf76f0
Adjust determining message size to new protobufs
plamut Jul 14, 2020
1c08fc4
Adjust Message.publish_time property to new protobuf
plamut Jul 14, 2020
8568830
Remove client_config argument to publisher client
plamut Jul 14, 2020
5a881e5
Remove subscriber client config
plamut Jul 14, 2020
022e710
Fix method patch in gapic instance method test
plamut Jul 14, 2020
d44494f
Fix transport-related test failures
plamut Jul 14, 2020
19952aa
Adjust calls to changed client.publish() signature
plamut Jul 14, 2020
d8b0a34
Remove obsolete replacement rules from synth.py
plamut Jul 15, 2020
cd8ad7e
Fix streaming pull monkeypatch (no prefetch)
plamut Jul 15, 2020
1253156
Update supported Python versions in README
plamut Jul 15, 2020
5a78181
Adjust system tests to new method signatures
plamut Jul 16, 2020
2b01cc4
Adjust method calls in samples to new client
plamut Jul 14, 2020
b336b2f
Fix tests creating subscription with custom settings
plamut Jul 17, 2020
1170672
Regenerate library with latest synthtool
plamut Jul 23, 2020
466a8db
Adjust IAM tests to new IAM method signatures
plamut Jul 23, 2020
7d82ece
Fix docstring format in generated *_iam_policy() methods
plamut Jul 23, 2020
4add1b9
Iterate directly over topic subscriptions response
plamut Jul 24, 2020
758a470
Copy default publish Retry to a class variable
plamut Jul 28, 2020
62d0d07
Adjust retry deadline if publish with ordering key
plamut Jul 30, 2020
2ed758e
Add suport for custom publish retry settings
plamut Jul 30, 2020
4c6a6a0
Add UPGRADING guide to docs
plamut Jul 31, 2020
5624026
Mention default retry settings in sample comments
plamut Aug 5, 2020
fe3d041
Merge branch 'master' into use-microgenerator
plamut Aug 15, 2020
3eb9a05
Remove synth URL changes from templates
plamut Aug 15, 2020
3bc393b
Adjust the ordering key sample to new code
plamut Aug 18, 2020
9f5aeee
Adjust client to changes in generated code
plamut Aug 19, 2020
c57c8b2
Regenerate the code to pick the latest changes
plamut Aug 19, 2020
cca5683
Bump dependencies to latest versions
plamut Aug 19, 2020
c29d7f8
Optimize creating and accesing pubsub messages
plamut Aug 20, 2020
23e1612
Regenerate the code with the latest changes
plamut Sep 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix GAPIC types imports
  • Loading branch information
plamut committed Jul 16, 2020
commit a744caf8b9adea14c0f88d63cd451952e59ce33c
10 changes: 5 additions & 5 deletions google/cloud/pubsub_v1/publisher/_batch/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import six

import google.api_core.exceptions
from google.cloud.pubsub_v1 import types
from google.cloud.pubsub_v1.publisher import exceptions
from google.cloud.pubsub_v1.publisher import futures
from google.cloud.pubsub_v1.publisher._batch import base
from google.pubsub_v1 import types as gapic_types


_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(

# The initial size is not zero, we need to account for the size overhead
# of the PublishRequest message itself.
self._base_request_size = types.PublishRequest(topic=topic).ByteSize()
self._base_request_size = gapic_types.PublishRequest(topic=topic).ByteSize()
self._size = self._base_request_size

@staticmethod
Expand Down Expand Up @@ -323,8 +323,8 @@ def publish(self, message):
"""

# Coerce the type, just in case.
if not isinstance(message, types.PubsubMessage):
message = types.PubsubMessage(**message)
if not isinstance(message, gapic_types.PubsubMessage):
message = gapic_types.PubsubMessage(**message)

future = None

Expand All @@ -336,7 +336,7 @@ def publish(self, message):
if self.status != base.BatchStatus.ACCEPTING_MESSAGES:
return

size_increase = types.PublishRequest(messages=[message]).ByteSize()
size_increase = gapic_types.PublishRequest(messages=[message]).ByteSize()

if (self._base_request_size + size_increase) > _SERVER_PUBLISH_MAX_BYTES:
err_msg = (
Expand Down
22 changes: 19 additions & 3 deletions google/cloud/pubsub_v1/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@

from google.cloud.pubsub_v1 import _gapic
from google.cloud.pubsub_v1 import types
from google.cloud.pubsub_v1.gapic import publisher_client
from google.cloud.pubsub_v1.gapic.transports import publisher_grpc_transport
from google.cloud.pubsub_v1.publisher import exceptions
from google.cloud.pubsub_v1.publisher import futures
from google.cloud.pubsub_v1.publisher._batch import thread
from google.cloud.pubsub_v1.publisher._sequencer import ordered_sequencer
from google.cloud.pubsub_v1.publisher._sequencer import unordered_sequencer
from google.cloud.pubsub_v1.publisher.flow_controller import FlowController
from google.pubsub_v1 import types as gapic_types
from google.pubsub_v1.services.publisher import client as publisher_client
from google.pubsub_v1.services.publisher.transports import (
grpc as publisher_grpc_transport,
)

__version__ = pkg_resources.get_distribution("google-cloud-pubsub").version

Expand All @@ -48,6 +51,19 @@
"from_service_account_json",
)

# TODO: inject via synth?
# What is DEFAULT_ENDPOINT? A replacement for SERVICE_ADDRESS?

# The scopes needed to make gRPC calls to all of the methods defined in
# this service
publisher_client.PublisherClient._DEFAULT_SCOPES = (
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/pubsub",
)

publisher_client.PublisherClient.SERVICE_ADDRESS = "pubsub.googleapis.com:443"
"""The default address of the service."""


def _set_nested_value(container, value, keys):
current = container
Expand Down Expand Up @@ -370,7 +386,7 @@ def publish(self, topic, data, ordering_key="", **attrs):
)

# Create the Pub/Sub message object.
message = types.PubsubMessage(
message = gapic_types.PubsubMessage(
data=data, ordering_key=ordering_key, attributes=attrs
)

Expand Down
6 changes: 3 additions & 3 deletions google/cloud/pubsub_v1/subscriber/_protocol/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import math
import threading

from google.cloud.pubsub_v1 import types
from google.cloud.pubsub_v1.subscriber._protocol import helper_threads
from google.cloud.pubsub_v1.subscriber._protocol import requests
from google.pubsub_v1 import types as gapic_types


_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -140,7 +140,7 @@ def ack(self, items):
total_chunks = int(math.ceil(len(items) / _ACK_IDS_BATCH_SIZE))

for _ in range(total_chunks):
request = types.StreamingPullRequest(
request = gapic_types.StreamingPullRequest(
ack_ids=itertools.islice(ack_ids, _ACK_IDS_BATCH_SIZE)
)
self._manager.send(request)
Expand Down Expand Up @@ -181,7 +181,7 @@ def modify_ack_deadline(self, items):
total_chunks = int(math.ceil(len(items) / _ACK_IDS_BATCH_SIZE))

for _ in range(total_chunks):
request = types.StreamingPullRequest(
request = gapic_types.StreamingPullRequest(
modify_deadline_ack_ids=itertools.islice(ack_ids, _ACK_IDS_BATCH_SIZE),
modify_deadline_seconds=itertools.islice(seconds, _ACK_IDS_BATCH_SIZE),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from google.cloud.pubsub_v1.subscriber._protocol import requests
import google.cloud.pubsub_v1.subscriber.message
import google.cloud.pubsub_v1.subscriber.scheduler
from google.pubsub_v1 import types as gapic_types

_LOGGER = logging.getLogger(__name__)
_RPC_ERROR_THREAD_NAME = "Thread-OnRpcTerminated"
Expand Down Expand Up @@ -369,7 +370,7 @@ def _send_unary_request(self, request):
stream.

Args:
request (types.StreamingPullRequest): The stream request to be
request (gapic_types.StreamingPullRequest): The stream request to be
mapped into unary requests.
"""
if request.ack_ids:
Expand Down Expand Up @@ -430,7 +431,7 @@ def heartbeat(self):
``self._UNARY_REQUESTS`` is set or not.
"""
if self._rpc is not None and self._rpc.is_active:
self._rpc.send(types.StreamingPullRequest())
self._rpc.send(gapic_types.StreamingPullRequest())

def open(self, callback, on_callback_error):
"""Begin consuming messages.
Expand Down Expand Up @@ -555,7 +556,7 @@ def _get_initial_request(self, stream_ack_deadline_seconds):
The default message acknowledge deadline for the stream.

Returns:
google.cloud.pubsub_v1.types.StreamingPullRequest: A request
google.pubsub_v1.types.StreamingPullRequest: A request
suitable for being the first request on the stream (and not
suitable for any other purpose).
"""
Expand All @@ -569,7 +570,7 @@ def _get_initial_request(self, stream_ack_deadline_seconds):
lease_ids = []

# Put the request together.
request = types.StreamingPullRequest(
request = gapic_types.StreamingPullRequest(
modify_deadline_ack_ids=list(lease_ids),
modify_deadline_seconds=[self.ack_deadline] * len(lease_ids),
stream_ack_deadline_seconds=stream_ack_deadline_seconds,
Expand Down
19 changes: 17 additions & 2 deletions google/cloud/pubsub_v1/subscriber/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

from google.cloud.pubsub_v1 import _gapic
from google.cloud.pubsub_v1 import types
from google.cloud.pubsub_v1.gapic import subscriber_client
from google.cloud.pubsub_v1.gapic.transports import subscriber_grpc_transport
from google.cloud.pubsub_v1.subscriber import futures
from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
from google.pubsub_v1.services.subscriber import client as subscriber_client
from google.pubsub_v1.services.subscriber.transports import (
grpc as subscriber_grpc_transport,
)


__version__ = pkg_resources.get_distribution("google-cloud-pubsub").version
Expand All @@ -39,6 +41,19 @@
"from_service_account_json",
)

# TODO: inject via synth?
# What is DEFAULT_ENDPOINT? A replacement for SERVICE_ADDRESS?

# The scopes needed to make gRPC calls to all of the methods defined in
# this service
subscriber_client.SubscriberClient._DEFAULT_SCOPES = (
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/pubsub",
)

subscriber_client.SubscriberClient.SERVICE_ADDRESS = "pubsub.googleapis.com:443"
"""The default address of the service."""


@_gapic.add_methods(subscriber_client.SubscriberClient, blacklist=_BLACKLISTED_METHODS)
class Client(object):
Expand Down
158 changes: 158 additions & 0 deletions google/cloud/pubsub_v1/subscriber/subscriber_client_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Copyright 2020, Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

config = {
"interfaces": {
"google.pubsub.v1.Subscriber": {
"retry_codes": {
"idempotent": ["ABORTED", "UNAVAILABLE", "UNKNOWN"],
"non_idempotent": ["UNAVAILABLE"],
"idempotent2": ["DEADLINE_EXCEEDED", "UNAVAILABLE"],
"streaming_pull": [
"ABORTED",
"DEADLINE_EXCEEDED",
"INTERNAL",
"RESOURCE_EXHAUSTED",
"UNAVAILABLE",
],
},
"retry_params": {
"default": {
"initial_retry_delay_millis": 100,
"retry_delay_multiplier": 1.3,
"max_retry_delay_millis": 60000,
"initial_rpc_timeout_millis": 60000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 60000,
"total_timeout_millis": 600000,
},
"messaging": {
"initial_retry_delay_millis": 100,
"retry_delay_multiplier": 1.3,
"max_retry_delay_millis": 60000,
"initial_rpc_timeout_millis": 25000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 25000,
"total_timeout_millis": 600000,
},
"streaming_messaging": {
"initial_retry_delay_millis": 100,
"retry_delay_multiplier": 1.3,
"max_retry_delay_millis": 60000,
"initial_rpc_timeout_millis": 600000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 600000,
"total_timeout_millis": 600000,
},
},
"methods": {
"CreateSubscription": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"GetSubscription": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"UpdateSubscription": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"ListSubscriptions": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"DeleteSubscription": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"GetSnapshot": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent2",
"retry_params_name": "default",
},
"ModifyAckDeadline": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"Acknowledge": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "messaging",
},
"Pull": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "messaging",
},
"StreamingPull": {
"timeout_millis": 900000,
"retry_codes_name": "streaming_pull",
"retry_params_name": "streaming_messaging",
},
"ModifyPushConfig": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"ListSnapshots": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"CreateSnapshot": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"UpdateSnapshot": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"DeleteSnapshot": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"Seek": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"SetIamPolicy": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"GetIamPolicy": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"TestIamPermissions": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
},
}
}
}
5 changes: 3 additions & 2 deletions google/cloud/pubsub_v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from google.protobuf import timestamp_pb2

from google.api_core.protobuf_helpers import get_messages
from google.cloud.pubsub_v1.proto import pubsub_pb2

# from google.cloud.pubsub_v1.proto import pubsub_pb2


# Define the default values for batching.
Expand Down Expand Up @@ -178,7 +179,7 @@ class LimitExceededBehavior(str, enum.Enum):
timestamp_pb2,
]

_local_modules = [pubsub_pb2]
_local_modules = [] # [pubsub_pb2]


names = ["BatchSettings", "FlowControl"]
Expand Down
Loading