Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
0b55ff5
wip
lukesneeringer Jun 3, 2017
210ef3b
Wrote some docs; not much else.
lukesneeringer Jun 3, 2017
7cd6156
subscriber wip
lukesneeringer Jun 4, 2017
fc4ead3
WIP
Jun 5, 2017
890de3a
wip
Jun 5, 2017
12ace0e
wip
Jun 7, 2017
7305000
wip
lukesneeringer Jun 14, 2017
e5a27ae
Fix a couple minor lint issues.
Jun 27, 2017
d50a22e
Adapting a subscriber that will work.
Jun 27, 2017
14f200a
WIP
Jun 27, 2017
6a7e846
Implement lease management.
Jun 28, 2017
3bb130b
WIP
Jun 29, 2017
f97dc23
WIP
Jun 29, 2017
303436c
WIP
Jul 5, 2017
933d2f3
WIP
Jul 13, 2017
1df0ccf
WIP
Jul 13, 2017
acb4534
WIP
Jul 13, 2017
2fb2785
Update subscriber client config to be sane.
Jul 13, 2017
ef178e9
Start adding unit tests.
Jul 18, 2017
147ad18
Beginning work on unit tests.
Jul 19, 2017
c96367a
Merge branch 'pubsub-publisher' into pubsub-subscriber
Jul 20, 2017
9c701e3
Publisher tests complete.
Jul 25, 2017
de38b83
subscriber/client.py tests
Jul 26, 2017
faeaa8e
Consumer tests
Jul 26, 2017
d467719
Fix minor linting error.
Jul 26, 2017
c821d33
Histogram tests
Jul 26, 2017
ed750b2
Minor fix based on Max feedback.
Jul 26, 2017
216310c
starting on helper thread tests
Jul 26, 2017
a1fd287
Add tests for helper_threads.
Jul 27, 2017
32701e1
Almost done with unit tests.
Jul 27, 2017
34272ad
Full coverage.
lukesneeringer Jul 27, 2017
e1c7c84
Do not send policy across the concurrency boundary.
Jul 31, 2017
2b21f48
Shift flow control to the policy class.
Jul 31, 2017
7f4b91c
Move the request queue to using keyword arguments.
Jul 31, 2017
3852805
Can has flow control.
Aug 1, 2017
b697be2
Merge branch 'public-master' into pubsub-subscriber
Aug 1, 2017
81b37f4
Subscription fixes.
Aug 3, 2017
5784d4d
Change batch time, add gRPC time logging.
Aug 3, 2017
97d8431
Unit test fix.
Aug 3, 2017
cb7dc05
Minor RST fixes (thanks @jonparrott).
Aug 4, 2017
6994465
Remove the ignore in .flake8.
Aug 4, 2017
eae7e14
Set gRPC limit to 20MB + 1
Aug 9, 2017
6afcd2a
Suppress not-working grpc options.
lukesneeringer Aug 15, 2017
e8c0a78
Merge branch 'public-master' into pubsub-subscriber
Aug 18, 2017
41cfc08
Merge branch 'public-master' into pubsub-subscriber
Aug 21, 2017
dd096e1
Merge branch 'pubsub-publisher' into pubsub-subscriber
Aug 21, 2017
b76d363
Merge branch 'pubsub-publisher' into pubsub-subscriber
Aug 21, 2017
760bef6
Merge branch 'pubsub-publisher' into pubsub-subscriber
Aug 21, 2017
f196b5e
Fix some tests to match new futures.
Aug 21, 2017
5dbfd0a
Merge branch 'pubsub-publisher' into pubsub-subscriber
Aug 21, 2017
ee144aa
Move the future tests to match the code.
Aug 21, 2017
40ea1e6
Merge branch 'pubsub-publisher' into pubsub-subscriber
Aug 21, 2017
8cb8f98
Fix a publish failure test.
Aug 21, 2017
47678c3
Fix final test.
Aug 21, 2017
90ef40f
Sane max_workers default for 2.7 and 3.4
Aug 21, 2017
34c8273
Mock credentials appropriately.
Aug 21, 2017
831fe75
Remove fail_under from .coveragerc.
Aug 22, 2017
02fa81f
Make histogram and helper_threads private.
Aug 22, 2017
2458b55
Add a publishing system test.
Aug 22, 2017
aa56a9b
Merge branch 'pubsub-subscriber' of github.com:GoogleCloudPlatform/go…
Aug 22, 2017
17b6544
Subscription system test.
Aug 22, 2017
f469381
Merge branch 'pubsub-publisher' into pubsub-subscriber
Aug 22, 2017
a24c0a7
Update tests.
Aug 22, 2017
a054324
Make the wait test work on 2.7
Aug 22, 2017
3735da5
Discarding unused mocks.
Aug 22, 2017
ac9f182
Make _consumer a private module.
Aug 22, 2017
f272eca
Switch from recursion to while for maintain_leases.
Aug 22, 2017
e6bcbe7
Add exception logging in the callback.
Aug 22, 2017
b9115ca
Fix a long line. Whups.
Aug 23, 2017
6ae46cb
Accept an executor.
Aug 23, 2017
852438e
Fix a minor flake8 complaint.
Aug 23, 2017
13c2205
No longer need to use inf for exception timeout.
Aug 23, 2017
6a03f48
Fixes discussed in chat with @jonparrott.
Aug 23, 2017
f1dde8f
Pub/Sub Docs (#3849)
lukesneeringer Aug 23, 2017
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
6 changes: 6 additions & 0 deletions pubsub/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ exclude =
.git,
*.pyc,
conf.py

ignore =

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

# Allow "under-indented" continuation lines.
E124,
# Allow closing parentheses to column-match the opening call.
E128
13 changes: 11 additions & 2 deletions pubsub/google/cloud/gapic/pubsub/v1/subscriber_client_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 12000,
"total_timeout_millis": 600000
},
"streaming": {
"initial_retry_delay_millis": 100,
"retry_delay_multiplier": 1.3,
"max_retry_delay_millis": 60000,
"initial_rpc_timeout_millis": 900000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 900000,
"total_timeout_millis": 900000
}
},
"methods": {
Expand Down Expand Up @@ -79,9 +88,9 @@
"retry_params_name": "messaging"
},
"StreamingPull": {
"timeout_millis": 60000,
"timeout_millis": 900000,
"retry_codes_name": "pull",
"retry_params_name": "messaging"
"retry_params_name": "streaming"
},
"ModifyPushConfig": {
"timeout_millis": 60000,
Expand Down
4 changes: 2 additions & 2 deletions pubsub/google/cloud/pubsub_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from __future__ import absolute_import

from google.cloud.pubsub_v1 import types
from google.cloud.pubsub_v1.publisher import PublisherClient
from google.cloud.pubsub_v1.subscriber import SubscriberClient
from google.cloud.pubsub_v1.publisher import Client as PublisherClient
from google.cloud.pubsub_v1.subscriber import Client as SubscriberClient

__all__ = (
'PublisherClient',
Expand Down
22 changes: 22 additions & 0 deletions pubsub/google/cloud/pubsub_v1/subscriber/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2017, Google Inc. All rights reserved.
#
# 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
#
# http://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.

from __future__ import absolute_import

from google.cloud.pubsub_v1.subscriber.client import Client


__all__ = (
'Client',
)
100 changes: 100 additions & 0 deletions pubsub/google/cloud/pubsub_v1/subscriber/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright 2017, Google Inc. All rights reserved.
#
# 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
#
# http://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.

from __future__ import absolute_import

import pkg_resources

from google.cloud.gapic.pubsub.v1 import subscriber_client

from google.cloud.pubsub_v1 import _gapic
from google.cloud.pubsub_v1.subscriber.policy import thread


__VERSION__ = pkg_resources.get_distribution('google-cloud-pubsub').version


@_gapic.add_methods(subscriber_client.SubscriberClient,
blacklist=('pull', 'streaming_pull'))
class Client(object):
"""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.
Args:
flow_control (~.pubsub_v1.types.FlowControl): The flow control
settings. Use this to prevent situations where you are
inundated with too many messages at once.
policy_class (class): A class that describes how to handle

This comment was marked as spam.

subscriptions. You may subclass the
:class:`.pubsub_v1.subscriber.policy.base.BasePolicy`
class in order to define your own consumer. This is primarily
provided to allow use of different concurrency models; the default
is based on :class:`threading.Thread`.
kwargs (dict): Any additional arguments provided are sent as keyword
keyword arguments to the underlying
:class:`~.gapic.pubsub.v1.subscriber_client.SubscriberClient`.
Generally, you should not need to set additional keyword
arguments.
"""
def __init__(self, flow_control=(), policy_class=thread.Policy,
**kwargs):
# Add the metrics headers, and instantiate the underlying GAPIC
# client.
kwargs['lib_name'] = 'gccl'
kwargs['lib_version'] = __VERSION__
self.api = subscriber_client.SubscriberClient(**kwargs)

# The subcription class is responsible to retrieving and dispatching
# messages.
self._policy_class = policy_class

def subscribe(self, subscription, callback=None):
"""Return a representation of an individual subscription.
This method creates and returns a ``Consumer`` object (that is, a
:class:`~.pubsub_v1.subscriber.consumer.base.BaseConsumer`)
subclass) bound to the topic. It does `not` create the subcription
on the backend (or do any API call at all); it simply returns an
object capable of doing these things.
If the ``callback`` argument is provided, then the :meth:`open` method
is automatically called on the returned object. If ``callback`` is
not provided, the subscription is returned unopened.
.. note::
It only makes sense to provide ``callback`` here if you have
already created the subscription manually in the API.
Args:
subscription (str): The name of the subscription. The
subscription should have already been created (for example,
by using :meth:`create_subscription`).
callback (function): The callback function. This function receives
the :class:`~.pubsub_v1.types.PubsubMessage` as its only
argument.
flow_control (~.pubsub_v1.types.FlowControl): The flow control
settings. Use this to prevent situations where you are
inundated with too many messages at once.
Returns:
~.pubsub_v1.subscriber.consumer.base.BaseConsumer: An instance
of the defined ``consumer_class`` on the client.
"""
subscr = self._policy_class(self, subscription)

This comment was marked as spam.

This comment was marked as spam.

if callable(callback):
subscr.open(callback)
return subscr
Loading