Skip to content
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

samples: add samples from pubsub/cloud-client #134

Merged
merged 103 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
87077b8
Add pubsub publisher and subscriber samples
Aug 24, 2016
b01f29c
Update readme
Aug 24, 2016
338ef98
Add pubsub iam samples
Aug 25, 2016
f6fb8d8
Fix lint issue
Sep 1, 2016
b64ac3e
Auto-update dependencies. [(#540)](https://github.com/GoogleCloudPlat…
dpebot Sep 23, 2016
bbad144
Auto-update dependencies. [(#542)](https://github.com/GoogleCloudPlat…
dpebot Sep 26, 2016
d710b0f
Move to google-cloud [(#544)](https://github.com/GoogleCloudPlatform/…
Sep 30, 2016
f531f9a
Add new "quickstart" samples [(#547)](https://github.com/GoogleCloudP…
jmdobry Oct 5, 2016
3ff1de9
Quickstart tests [(#569)](https://github.com/GoogleCloudPlatform/pyth…
Oct 12, 2016
26903ff
Generate readmes for most service samples [(#599)](https://github.com…
Oct 24, 2016
f7a45e8
Update samples to support latest Google Cloud Python [(#656)](https:/…
Nov 15, 2016
1e93ba5
Auto-update dependencies. [(#715)](https://github.com/GoogleCloudPlat…
dpebot Dec 13, 2016
e18f581
Fix pubusb tests
Feb 16, 2017
5d64699
Auto-update dependencies. [(#825)](https://github.com/GoogleCloudPlat…
dpebot Mar 11, 2017
50982b7
Auto-update dependencies. [(#876)](https://github.com/GoogleCloudPlat…
dpebot Apr 4, 2017
daeca5c
Fix reference to our testing tools
Apr 12, 2017
558ed2c
Re-generate all readmes
Apr 27, 2017
eba2d3c
Auto-update dependencies. [(#922)](https://github.com/GoogleCloudPlat…
dpebot May 1, 2017
5541966
Fix README rst links [(#962)](https://github.com/GoogleCloudPlatform/…
waprin May 24, 2017
3667523
Auto-update dependencies. [(#1004)](https://github.com/GoogleCloudPla…
dpebot Jun 27, 2017
362342e
Auto-update dependencies. [(#1055)](https://github.com/GoogleCloudPla…
dpebot Aug 7, 2017
4fce50d
Update pubsub samples [(#1092)](https://github.com/GoogleCloudPlatfor…
Aug 28, 2017
00ced55
Fix argpraser for pubsub subscriber
Aug 28, 2017
8d65d81
Add comment about result blocking in pubsub samples
Aug 28, 2017
b39cc76
Auto-update dependencies. [(#1097)](https://github.com/GoogleCloudPla…
dpebot Sep 12, 2017
80b77fd
Update all generated readme auth instructions [(#1121)](https://githu…
Sep 18, 2017
75851b5
Added Link to Python Setup Guide [(#1158)](https://github.com/GoogleC…
Oct 12, 2017
a36f6f3
Auto-update dependencies. [(#1138)](https://github.com/GoogleCloudPla…
dpebot Oct 23, 2017
ad66781
Fix a few more lint issues
Oct 24, 2017
43c2c7b
Add Snippet for Listing All Subscriptions in a Project [(#1169)](http…
Oct 31, 2017
a04a141
Auto-update dependencies. [(#1186)](https://github.com/GoogleCloudPla…
dpebot Nov 1, 2017
8e9600c
Auto-update dependencies. [(#1234)](https://github.com/GoogleCloudPla…
dpebot Nov 28, 2017
d693f16
Auto-update dependencies. [(#1239)](https://github.com/GoogleCloudPla…
dpebot Nov 30, 2017
479e9f7
Added "Open in Cloud Shell" buttons to README files [(#1254)](https:/…
Dec 7, 2017
2e3d6bc
Auto-update dependencies. [(#1263)](https://github.com/GoogleCloudPla…
dpebot Dec 11, 2017
da60c6d
Auto-update dependencies. [(#1272)](https://github.com/GoogleCloudPla…
dpebot Dec 12, 2017
33b431b
Auto-update dependencies. [(#1282)](https://github.com/GoogleCloudPla…
dpebot Jan 2, 2018
7b9dc49
Add listen for errors sample. [(#1306)](https://github.com/GoogleClou…
noerog Jan 8, 2018
308acd4
Fix subscription.open get called twice in the client libraries [(#132…
luxiangu Jan 17, 2018
4a63dad
Add tests for creating push subscription. [(#1332)](https://github.co…
noerog Jan 25, 2018
bab86e0
Add create push subscription sample. [(#1331)](https://github.com/Goo…
noerog Jan 25, 2018
6604913
Update API version and body. [(#1326)](https://github.com/GoogleCloud…
noerog Jan 25, 2018
7eb862a
Add sample for updating a subscription. [(#1335)](https://github.com/…
noerog Feb 2, 2018
d939761
Change update_subscription to change endpoint URL. [(#1344)](https://…
noerog Feb 5, 2018
66b555a
Auto-update dependencies. [(#1359)](https://github.com/GoogleCloudPla…
dpebot Feb 26, 2018
078e624
Auto-update dependencies. [(#1389)](https://github.com/GoogleCloudPla…
dpebot Mar 8, 2018
deed374
Added sample for publishing/receiving messages with custom attributes…
Mar 16, 2018
ac6d331
Auto-update dependencies.
dpebot Apr 2, 2018
a3552d2
Regenerate the README files and fix the Open in Cloud Shell link for …
Apr 7, 2018
a91495d
Update READMEs to fix numbering and add git clone [(#1464)](https://g…
frankyn Apr 26, 2018
779ef8b
PubSub: adds region tags and updates existing to standard [(#1491)](h…
alixhami May 21, 2018
915f209
Pubsub: Add missing region tag [(#1498)](https://github.com/GoogleClo…
alixhami May 22, 2018
3a8a6f1
Add the Pub/Sub handle_publisher_error sample [(#1440)](https://githu…
Jun 21, 2018
dec4b94
Resolved conflicts.
michaelawyu Jun 29, 2018
43200bf
Merge branch 'dpebot-repositorygardener' despite flaky dataproc tests
michaelawyu Jun 29, 2018
2b6e80f
Modified publisher with error handling [(#1568)](https://github.com/G…
anguillanneuf Jul 19, 2018
57581be
Updated google-cloud-pubsub to version 0.35 [(#1624)](https://github.…
anguillanneuf Aug 10, 2018
f4fa8b6
Added timeout in error handling [(#1636)](https://github.com/GoogleC…
anguillanneuf Aug 15, 2018
e52c36c
Auto-update dependencies. [(#1658)](https://github.com/GoogleCloudPla…
dpebot Aug 28, 2018
6f59e2a
Added sample for Pub/Sub synchronous pull subscriber [(#1673)](https:…
anguillanneuf Aug 30, 2018
8dd5132
Updated variable name [(#1680)](https://github.com/GoogleCloudPlatfor…
anguillanneuf Aug 31, 2018
e1e090a
Fixed return object from `subscriber.subscribe()` [(#1685)](https://g…
anguillanneuf Sep 7, 2018
ff097db
Pub/Sub: synchronous pull with lease management [(#1701)](https://git…
anguillanneuf Sep 14, 2018
acf0703
Pub/Sub: moved import statements inside region tags [(#1753)](https:/…
anguillanneuf Oct 12, 2018
0b31997
Pub/Sub end-to-end sample [(#1800)](https://github.com/GoogleCloudPla…
anguillanneuf Oct 30, 2018
824c9fa
Add test for updating a subscription. [(#1336)](https://github.com/Go…
noerog Dec 7, 2018
99cbe6e
Fix update test to use new endpoint [(#1925)](https://github.com/Goog…
engelke Dec 13, 2018
1a49ed8
Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPla…
dpebot Feb 6, 2019
0ca9ca0
Cloud Pub/Sub Quickstart V2 [(#2004)](https://github.com/GoogleCloudP…
anguillanneuf Feb 12, 2019
446869b
Pub/Sub: publish with error-handling comments [(#2222)](https://githu…
anguillanneuf Jun 14, 2019
e27f549
Resolve all futures [(#2231)](https://github.com/GoogleCloudPlatform/…
anguillanneuf Jun 20, 2019
ae4819a
Pub/Sub: add publish retry sample [(#2273)](https://github.com/Google…
anguillanneuf Jul 22, 2019
f395682
Fix a TODO comment on pubsub/cloud-client/subscriber.py [(#2302)](htt…
Jul 30, 2019
d1a0809
Print actual number of messages pulled [(#2078)](https://github.com/G…
olivercoad Aug 12, 2019
3133b6c
Pub/Sub: fix subscriber async region tag mistake [(#2334)](https://gi…
anguillanneuf Aug 13, 2019
66079c0
Pub/Sub: update retry settings in sample [(#2395)](https://github.com…
anguillanneuf Sep 12, 2019
a12a12b
Pub/Sub: improve pub.py [(#2403)](https://github.com/GoogleCloudPlatf…
anguillanneuf Sep 17, 2019
3bad54d
Adds updates for samples profiler ... vision [(#2439)](https://github…
gguuss Oct 7, 2019
aa682cc
Pub/Sub: update how subscriber client listens to StreamingPullFuture …
anguillanneuf Oct 21, 2019
6e46e5d
Pub/Sub: update how to test with mock [(#2555)](https://github.com/Go…
anguillanneuf Dec 11, 2019
55cbff6
Pub/Sub: remove infinite while loops in subscriber examples [(#2604)]…
anguillanneuf Dec 12, 2019
a17393c
Pub/Sub: add timeout in argparse [(#2637)](https://github.com/GoogleC…
anguillanneuf Dec 18, 2019
1487d88
Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPla…
dpebot Dec 21, 2019
59bb594
remove publish concurrency control sample [(#2960)](https://github.co…
anguillanneuf Feb 24, 2020
1aa99f8
Pub/Sub: remove unreferenced samples [(#2986)](https://github.com/Goo…
anguillanneuf Feb 26, 2020
65e9621
Pub/Sub: add SubscriberClient.close() to examples [(#3118)](https://g…
anguillanneuf Mar 23, 2020
ea2f0a4
Pub/Sub: update publish with batch settings sample [(#3137)](https://…
anguillanneuf Mar 25, 2020
f5125db
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg Apr 2, 2020
0cdeb82
chore: remove gcp-devrel-py-tools from iot and pubsub [(#3470)](https…
Apr 23, 2020
f8274ab
Update dependency google-cloud-pubsub to v1.4.2 in Storage and Pub/Su…
busunkim96 Apr 24, 2020
8adb97a
chore: some lint fixes [(#3748)](https://github.com/GoogleCloudPlatfo…
May 13, 2020
3b081ee
chore(deps): update dependency google-cloud-pubsub to v1.4.3 [(#3725)…
renovate-bot May 13, 2020
64fad27
chore(deps): update dependency google-cloud-pubsub to v1.5.0 [(#3781)…
renovate-bot May 21, 2020
0e7e03e
samples: add Pub/Sub dead letter queue samples [(#3904)](https://gith…
anguillanneuf May 30, 2020
25bf5c3
fix: make timeout an optional positional arg [(#3938)](https://github…
anguillanneuf Jun 3, 2020
89debfc
fix: replace name with id in samples [(#3953)](https://github.com/Goo…
anguillanneuf Jun 4, 2020
0e325bf
Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](https://g…
kurtisvg Jun 9, 2020
2c87a45
nit: remove redundant/wrong Pub/Sub region tag [(#4027)](https://gith…
anguillanneuf Jun 11, 2020
470db86
Pub/Sub: wrap subscriber in a with block and add comments [(#4070)](h…
anguillanneuf Jun 12, 2020
f91f578
Update dependency google-cloud-pubsub to v1.6.0 [(#4039)](https://git…
renovate-bot Jun 20, 2020
84013c6
Merge branch 'snippets-samples' into add-snippets-samples
plamut Jun 25, 2020
5083332
chore: update templates
plamut Jun 26, 2020
ba494c1
Merge branch 'master' into add-snippets-samples
plamut Jun 26, 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
11 changes: 11 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Code owners file.
# This file controls who is tagged for review for any given pull request.
#
# For syntax help see:
# https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax


# The python-samples-owners team is the default owner for anything not
# explicitly taken by someone else.

/samples/ @anguillanneuf @hongalex @googleapis/python-samples-owners
1 change: 1 addition & 0 deletions samples/AUTHORING_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md
1 change: 1 addition & 0 deletions samples/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/CONTRIBUTING.md
282 changes: 282 additions & 0 deletions samples/snippets/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@

.. This file is automatically generated. Do not edit this file directly.

Google Cloud Pub/Sub Python Samples
===============================================================================

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=pubsub/cloud-client/README.rst
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



This directory contains samples for Google Cloud Pub/Sub. `Google Cloud Pub/Sub`_ is a fully-managed real-time messaging service that allows you to send and receive messages between independent applications.




.. _Google Cloud Pub/Sub: https://cloud.google.com/pubsub/docs


Setup
-------------------------------------------------------------------------------



Authentication
++++++++++++++

This sample requires you to have authentication setup. Refer to the
`Authentication Getting Started Guide`_ for instructions on setting up
credentials for applications.

.. _Authentication Getting Started Guide:
https://cloud.google.com/docs/authentication/getting-started




Install Dependencies
++++++++++++++++++++

#. Clone python-docs-samples and change directory to the sample directory you want to use.

.. code-block:: bash

$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-        $ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
+        $ git clone https://github.com/googleapis/python-pubsub.git


#. Install `pip`_ and `virtualenv`_ if you do not already have them. You may want to refer to the `Python Development Environment Setup Guide`_ for Google Cloud Platform for instructions.

.. _Python Development Environment Setup Guide:
https://cloud.google.com/python/setup

#. Create a virtualenv. Samples are compatible with Python 3.6+.

.. code-block:: bash

$ virtualenv env
$ source env/bin/activate

#. Install the dependencies needed to run the samples.

.. code-block:: bash

$ pip install -r requirements.txt

.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/






Samples
-------------------------------------------------------------------------------


Quickstart
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=pubsub/cloud-client/quickstart.py,pubsub/cloud-client/README.rst




To run this sample:

.. code-block:: bash

$ python quickstart.py




Publisher
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=pubsub/cloud-client/publisher.py,pubsub/cloud-client/README.rst




To run this sample:

.. code-block:: bash

$ python publisher.py


usage: publisher.py [-h]
project_id
{list,create,delete,publish,publish-with-custom-attributes,publish-with-error-handler,publish-with-batch-settings,publish-with-retry-settings}
...

This application demonstrates how to perform basic operations on topics
with the Cloud Pub/Sub API.

For more information, see the README.md under /pubsub and the documentation
at https://cloud.google.com/pubsub/docs.

positional arguments:
project_id Your Google Cloud project ID
{list,create,delete,publish,publish-with-custom-attributes,publish-with-error-handler,publish-with-batch-settings,publish-with-retry-settings}
list Lists all Pub/Sub topics in the given project.
create Create a new Pub/Sub topic.
delete Deletes an existing Pub/Sub topic.
publish Publishes multiple messages to a Pub/Sub topic.
publish-with-custom-attributes
Publishes multiple messages with custom attributes to
a Pub/Sub topic.
publish-with-error-handler
Publishes multiple messages to a Pub/Sub topic with an
error handler.
publish-with-batch-settings
Publishes multiple messages to a Pub/Sub topic with
batch settings.
publish-with-retry-settings
Publishes messages with custom retry settings.

optional arguments:
-h, --help show this help message and exit





Subscribers
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=pubsub/cloud-client/subscriber.py,pubsub/cloud-client/README.rst




To run this sample:

.. code-block:: bash

$ python subscriber.py


usage: subscriber.py [-h]
project_id
{list-in-topic,list-in-project,create,create-with-dead-letter-policy,create-push,delete,update-push,update-dead-letter-policy,remove-dead-letter-policy,receive,receive-custom-attributes,receive-flow-control,receive-synchronously,receive-synchronously-with-lease,listen-for-errors,receive-messages-with-delivery-attempts}
...

This application demonstrates how to perform basic operations on
subscriptions with the Cloud Pub/Sub API.

For more information, see the README.md under /pubsub and the documentation
at https://cloud.google.com/pubsub/docs.

positional arguments:
project_id Your Google Cloud project ID
{list-in-topic,list-in-project,create,create-with-dead-letter-policy,create-push,delete,update-push,update-dead-letter-policy,remove-dead-letter-policy,receive,receive-custom-attributes,receive-flow-control,receive-synchronously,receive-synchronously-with-lease,listen-for-errors,receive-messages-with-delivery-attempts}
list-in-topic Lists all subscriptions for a given topic.
list-in-project Lists all subscriptions in the current project.
create Create a new pull subscription on the given topic.
create-with-dead-letter-policy
Create a subscription with dead letter policy.
create-push Create a new push subscription on the given topic.
delete Deletes an existing Pub/Sub topic.
update-push Updates an existing Pub/Sub subscription's push
endpoint URL. Note that certain properties of a
subscription, such as its topic, are not modifiable.
update-dead-letter-policy
Update a subscription's dead letter policy.
remove-dead-letter-policy
Remove dead letter policy from a subscription.
receive Receives messages from a pull subscription.
receive-custom-attributes
Receives messages from a pull subscription.
receive-flow-control
Receives messages from a pull subscription with flow
control.
receive-synchronously
Pulling messages synchronously.
receive-synchronously-with-lease
Pulling messages synchronously with lease management
listen-for-errors Receives messages and catches errors from a pull
subscription.
receive-messages-with-delivery-attempts

optional arguments:
-h, --help show this help message and exit





Identity and Access Management
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=pubsub/cloud-client/iam.py,pubsub/cloud-client/README.rst




To run this sample:

.. code-block:: bash

$ python iam.py


usage: iam.py [-h]
project
{get-topic-policy,get-subscription-policy,set-topic-policy,set-subscription-policy,check-topic-permissions,check-subscription-permissions}
...

This application demonstrates how to perform basic operations on IAM
policies with the Cloud Pub/Sub API.

For more information, see the README.md under /pubsub and the documentation
at https://cloud.google.com/pubsub/docs.

positional arguments:
project Your Google Cloud project ID
{get-topic-policy,get-subscription-policy,set-topic-policy,set-subscription-policy,check-topic-permissions,check-subscription-permissions}
get-topic-policy Prints the IAM policy for the given topic.
get-subscription-policy
Prints the IAM policy for the given subscription.
set-topic-policy Sets the IAM policy for a topic.
set-subscription-policy
Sets the IAM policy for a topic.
check-topic-permissions
Checks to which permissions are available on the given
topic.
check-subscription-permissions
Checks to which permissions are available on the given
subscription.

optional arguments:
-h, --help show this help message and exit









The client library
-------------------------------------------------------------------------------

This sample uses the `Google Cloud Client Library for Python`_.
You can read the documentation for more details on API usage and use GitHub
to `browse the source`_ and `report issues`_.

.. _Google Cloud Client Library for Python:
https://googlecloudplatform.github.io/google-cloud-python/
.. _browse the source:
https://github.com/GoogleCloudPlatform/google-cloud-python
.. _report issues:
https://github.com/GoogleCloudPlatform/google-cloud-python/issues



.. _Google Cloud SDK: https://cloud.google.com/sdk/
30 changes: 30 additions & 0 deletions samples/snippets/README.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is used to generate README.rst

product:
name: Google Cloud Pub/Sub
short_name: Cloud Pub/Sub
url: https://cloud.google.com/pubsub/docs
description: >
`Google Cloud Pub/Sub`_ is a fully-managed real-time messaging service that
allows you to send and receive messages between independent applications.

setup:
- auth
- install_deps

samples:
- name: Quickstart
file: quickstart.py
Comment on lines +16 to +17
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that this file doesn't exist.

- name: Publisher
file: publisher.py
show_help: true
- name: Subscribers
file: subscriber.py
show_help: true
- name: Identity and Access Management
file: iam.py
show_help: true

cloud_client_library: true

folder: pubsub/cloud-client
Loading