Skip to content

Commit

Permalink
samples: add schema samples (#306)
Browse files Browse the repository at this point in the history
* samples: create, delete, get, list samples

* add publish and subscribe with avro schema samples

* add publish and subscribe with proto schema samples

* add protoc compiled class

* address leah's and peter's comments

* avoid using google.auth.default() for testing

* use choice in argparse

* update python to python3 in readme
  • Loading branch information
anguillanneuf authored Mar 9, 2021
1 parent e2678d4 commit 4080b0a
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 5 deletions.
52 changes: 47 additions & 5 deletions samples/snippets/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ To run this sample:

.. code-block:: bash
$ python quickstart/pub.py
$ python3 quickstart/pub.py
Quickstart (Subscriber)
Expand All @@ -94,7 +94,7 @@ To run this sample:

.. code-block:: bash
$ python quickstart/sub.py
$ python3 quickstart/sub.py
Publisher
Expand All @@ -110,7 +110,7 @@ To run this sample:

.. code-block:: bash
$ python publisher.py
$ python3 publisher.py
usage: publisher.py [-h]
project_id
Expand Down Expand Up @@ -168,7 +168,7 @@ To run this sample:

.. code-block:: bash
$ python subscriber.py
$ python3 subscriber.py
usage: subscriber.py [-h]
project_id
Expand Down Expand Up @@ -232,7 +232,7 @@ To run this sample:

.. code-block:: bash
$ python iam.py
$ python3 iam.py
usage: iam.py [-h]
project_id
Expand Down Expand Up @@ -266,6 +266,48 @@ To run this sample:
Schema
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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




To run this sample:

.. code-block:: bash
$ python3 schema.py
usage: schema.py [-h]
project_id
{create-avro,create-proto,get,list,delete,create-topic,publish-avro,publish-proto,receive-avro,receive-proto}
...
This application demonstrates how to perform basic schema operations
using 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
{create-avro,create-proto,get,list,delete,create-topic,publish-avro,publish-proto,receive-avro,receive-proto}
create-avro Create a schema resource from an Avro schema file formatted in JSON.
create-proto Create a schema resource from a protobuf schema file.
get Get a schema resource.
list List schema resources.
delete Delete a schema resource.
create-topic Create a topic resource with a schema.
publish-avro Pulbish a BINARY or JSON encoded message to a topic configured with an Avro schema.
publish-proto Publish a BINARY or JSON encoded message to a topic configured with a protobuf schema.
receive-avro Receive and decode messages sent to a topic with an Avro schema.
receive-proto Receive and decode messages sent to a topic with a protobuf schema.
optional arguments:
-h, --help show this help message and exit
The client library
Expand Down
1 change: 1 addition & 0 deletions samples/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
google-cloud-pubsub==2.4.0
avro==1.10.1
18 changes: 18 additions & 0 deletions samples/snippets/resources/us-states.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"type":"record",
"name":"State",
"namespace":"utilities",
"doc":"A list of states in the United States of America.",
"fields":[
{
"name":"name",
"type":"string",
"doc":"The common name of the state."
},
{
"name":"post_abbr",
"type":"string",
"doc":"The postal code abbreviation of the state."
}
]
}
8 changes: 8 additions & 0 deletions samples/snippets/resources/us-states.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";

package utilities;

message StateProto {
string name = 1;
string post_abbr = 2;
}
Loading

0 comments on commit 4080b0a

Please sign in to comment.