-
Notifications
You must be signed in to change notification settings - Fork 14
docs: add documentation #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
31caacd
add license header and use try
anguillanneuf e8933ef
add types to nav
anguillanneuf bfb1318
add admin docs
anguillanneuf 99d6d0c
add publisher
anguillanneuf a21d7a2
add subscriber and update index
anguillanneuf 3635134
remove docs for api services
anguillanneuf fb74634
clean up types
anguillanneuf 1abd013
mention disabled flow control
anguillanneuf a6aac7c
resolve merge conflicts
anguillanneuf 8c670e7
update subscriber sample
anguillanneuf a301ec7
clean up types
anguillanneuf b933a93
resolve merge conflicts
anguillanneuf 5555fa1
use CloudRegion in samples and docs
anguillanneuf 767aefb
add space after code-block
anguillanneuf 8c96c8f
add empty line after code-block
anguillanneuf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Admin Client API | ||
| ================ | ||
|
|
||
| .. automodule:: google.cloud.pubsublite.admin_client | ||
| :members: | ||
| :inherited-members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| Admin Operations | ||
| ================ | ||
|
|
||
| Admin operations are handled through the | ||
| :class:`~.pubsublite.admin_client.AdminClient` class (aliased as | ||
| ``google.cloud.pubsublite.AdminClient``). | ||
|
|
||
| Instantiating an admin client requires you to provide a valid cloud region | ||
| for the Pub/Sub Lite service: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from google.cloud.pubsublite import AdminClient | ||
| cloud_region = CloudRegion("us-central1") | ||
| admin_client = AdminClient(cloud_region) | ||
|
|
||
|
|
||
| Create a topic | ||
| -------------- | ||
|
|
||
| To create a message, use the | ||
| :meth:`~.pubsublite.admin_client.AdminClient.create_topic` method. This method accepts | ||
| one positional arguments: a :class:`~.pubsublite_v1.types.Topic` object, where the name | ||
| of the topic is passed along as a string. | ||
|
|
||
| Pub/Sub Lite topics have the canonical form of | ||
|
|
||
| ``projects/{project_number}/locations/{location}/topics/{topic_id}`` | ||
|
|
||
| A location (a.k.a. `zone`_) is comprised of a cloud region and a zone ID. | ||
|
|
||
| .. _zone: https://cloud.google.com/pubsub/lite/docs/locations/ | ||
|
|
||
| A call to create a Pub/Sub Lite topic looks like: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from google.cloud.pubsublite import AdminClient, Topic | ||
| from google.cloud.pubsublite.types import ( | ||
| CloudRegion, CloudZone, TopicPath, | ||
| ) | ||
|
|
||
| project_number = 1122334455 | ||
| zone_id = "a" | ||
| topic_id = "your-topic-id" | ||
|
|
||
| cloud_region = CloudRegion(cloud_region) | ||
| location = CloudZone(cloud_region, zone_id) | ||
| topic_path = TopicPath(project_number, location, topic_id) | ||
|
|
||
| topic = Topic( | ||
| name=str(topic_path), | ||
| partition_config=Topic.PartitionConfig( | ||
| # 1 partition | ||
| count=1, | ||
| # Publish at 4 MiB/s and subscribe at 8 MiB/s | ||
| capacity=Topic.PartitionConfig.Capacity( | ||
| publish_mib_per_sec=4, | ||
| subscribe_mib_per_sec=8, | ||
| ), | ||
| ), | ||
| retention_config=Topic.RetentionConfig( | ||
| # 30 GiB | ||
| per_partition_bytes=30 * 1024 * 1024 * 1024, | ||
| # 7 days | ||
| period=Duration(seconds=60 * 60 * 24 * 7), | ||
| ), | ||
| ) | ||
|
|
||
| admin_client = AdminClient(cloud_region) | ||
| response = admin_client.create_topic(topic) | ||
|
|
||
|
|
||
| API Reference | ||
| ------------- | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 2 | ||
|
|
||
| api/client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Publisher Client API | ||
| ==================== | ||
|
|
||
| .. automodule:: google.cloud.pubsublite.cloudpubsub.publisher_client | ||
| :members: | ||
| :inherited-members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| Publisher Client | ||
| ================ | ||
|
|
||
| Publish operations are handled through the | ||
| :class:`~.pubsublite.cloudpubsub.publisher_client.PublisherClient` class (aliased as | ||
| ``google.cloud.pubsublite.cloudpubsub.PublisherClient``). | ||
|
|
||
| You should instantiate a publisher client using a context manager: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from google.cloud.pubsublite.cloudpubsub import PublisherClient | ||
|
|
||
| with PublisherClient() as publisher_client: | ||
| # Use publisher_client | ||
|
|
||
| When not using a context manager, you need to call | ||
| :meth:`~.pubsublite.cloudpubsub.publisher_client.PublisherClient.__enter__`. | ||
|
|
||
| Publish a message | ||
| ----------------- | ||
|
|
||
| To publish a message, use the | ||
| :meth:`~.pubsublite.cloudpubsub.publisher_client.PublisherClient.publish` | ||
| method. This method accepts | ||
| two positional arguments: a :class:`~.pubsublite.types.TopicPath` object | ||
| and a message in byte string. | ||
|
|
||
| A call to publish a message looks like: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from google.cloud.pubsublite.cloudpubsub import PublisherClient | ||
| from google.cloud.pubsublite.types import ( | ||
| CloudRegion, CloudZone, TopicPath, | ||
| ) | ||
|
|
||
| project_number = 1122334455 | ||
| cloud_region = "us-central1" | ||
| zone_id = "a" | ||
| topic_id = "your-topic-id" | ||
|
|
||
| location = CloudZone(CloudRegion(cloud_region), zone_id) | ||
| topic_path = TopicPath(project_number, location, topic_id) | ||
|
|
||
| with PublisherClient() as publisher_client: | ||
| data = "Hello world!" | ||
| api_future = publisher_client.publish(t | ||
| opic_path, data.encode("utf-8") | ||
| ) | ||
| message_id = api_future.result() | ||
|
|
||
|
|
||
| API Reference | ||
| ------------- | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 2 | ||
|
|
||
| api/client | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Subscriber Client API | ||
| ===================== | ||
|
|
||
| .. automodule:: google.cloud.pubsublite.cloudpubsub.subscriber_client | ||
| :members: | ||
| :inherited-members: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| Subscriber Client | ||
| ================= | ||
|
|
||
| Subscribe operations are handled through the | ||
| :class:`~.pubsublite.cloudpubsub.subscriber_client.SubscriberClient` class (aliased as | ||
| ``google.cloud.pubsublite.cloudpubsub.SubscriberClient``). | ||
|
|
||
| You should instantiate a subscriber client using a context manager: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from google.cloud.pubsublite.cloudpubsub import SubscriberClient | ||
|
anguillanneuf marked this conversation as resolved.
|
||
|
|
||
| with SubscriberClient() as subscriber_client: | ||
| # Use subscriber_client | ||
|
|
||
| When not using a context manager, you need to call | ||
| :meth:`~.pubsublite.cloudpubsub.subscriber_client.SubscriberClient.__enter__`. | ||
|
|
||
| Receive messages | ||
| ---------------- | ||
|
|
||
| To receive messages, use the | ||
| :meth:`~.pubsublite.cloudpubsub.subscriber_client.SubscriberClient.subscribe` | ||
| method. This method requires | ||
| three positional arguments: a :class:`~.pubsublite.types.SubscriptionPath` object, | ||
| a callback function, and a :class:`~.pubsublite.types.FlowControlSettings` object. | ||
|
|
||
| Receiving messages looks like: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from google.cloud.pubsublite.cloudpubsub import SubscriberClient | ||
| from google.cloud.pubsublite.types import ( | ||
| CloudRegion, | ||
| CloudZone, | ||
| SubscriptionPath, | ||
| DISABLED_FLOW_CONTROL, | ||
| ) | ||
|
|
||
| project_number = 1122334455 | ||
| cloud_region = "us-central1" | ||
| zone_id = "a" | ||
| subscription_id = "your-subscription-id" | ||
|
|
||
| location = CloudZone(CloudRegion(cloud_region), zone_id) | ||
| subscription_path = SubscriptionPath(project_number, location, subscription_id) | ||
|
|
||
| with SubscriberClient() as subscriber_client: | ||
| streaming_pull_future = subscriber_client.subscribe( | ||
| subscription_path, | ||
| callback=callback, | ||
| per_partition_flow_control_settings=DISABLED_FLOW_CONTROL, | ||
| ) | ||
|
|
||
| streaming_pull_future.result() | ||
|
|
||
| Subscriber Callbacks | ||
| -------------------- | ||
|
|
||
| Received messages are processed in a callback function. This callback function | ||
| only takes one argument of type :class:`google.cloud.pubsub_v1.subscriber.message.Message`. | ||
| After this message has been processed, the function should either call | ||
| :meth:`~.pubsub_v1.subscriber.message.Message.ack` to acknowledge the message or | ||
| :meth:`~.pubsub_v1.subscriber.message.Message.nack` to send a negative acknowledgement. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| def callback(message): | ||
| message_data = message.data.decode("utf-8") | ||
| print(f"Received {message_data}.") | ||
| message.ack() | ||
|
|
||
| Flow Control Settings | ||
| --------------------- | ||
|
|
||
| Flow control settings are applied per partition. | ||
| They control when to pause the message stream to a partition so the server temporarily | ||
| stops sending out more messages (known as outstanding messages) from this partition. | ||
|
|
||
|
dpcollins-google marked this conversation as resolved.
|
||
| You can configure flow control settings by setting the maximum number and size of | ||
| outstanding messages. The message stream is paused when either condition is met. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| from google.cloud.pubsublite.types import FlowControlSettings | ||
|
|
||
| flow_control_settings = FlowControlSettings( | ||
| # 1,000 outstanding messages. Must be >0. | ||
| messages_outstanding=1000, | ||
| # 10 MiB. Must be greater than the allowed size of the largest message (1 MiB). | ||
| bytes_outstanding=10 * 1024 * 1024, | ||
| ) | ||
|
|
||
| You may also turn off flow control settings by setting it to | ||
| :class:`google.cloud.pubsublite.types.DISABLED_FLOW_CONTROL`. | ||
|
|
||
| API Reference | ||
| ------------- | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 2 | ||
|
|
||
| api/client | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Pub/Sub Lite Client Types | ||
| ========================= | ||
|
|
||
| .. automodule:: google.cloud.pubsublite.types | ||
| :members: | ||
| :noindex: | ||
|
|
||
| .. autoclass:: google.cloud.pubsublite_v1.Cursor | ||
| :members: | ||
| :noindex: | ||
|
|
||
| .. autoclass:: google.cloud.pubsublite_v1.Subscription | ||
| :members: | ||
| :noindex: | ||
|
|
||
| .. autoclass:: google.cloud.pubsublite_v1.Topic | ||
| :members: | ||
| :noindex: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,19 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # 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. | ||
|
|
||
| import pkg_resources | ||
|
|
||
| pkg_resources.declare_namespace(__name__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,19 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # 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. | ||
|
|
||
| import pkg_resources | ||
|
|
||
| pkg_resources.declare_namespace(__name__) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.