google-cloud-pubsub 0.32.1 → 0.32.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48356ab57faedf9942a2ad5d402c6f71297bc5a05f3b39e5479deb3f3be58546
4
- data.tar.gz: a7e64b049fb79b6bc0adcc619ca98de9a7234c16be32c5e3a8dd601267df065b
3
+ metadata.gz: 02df7490b94ade13d3c63495002c52b2d207eea1c607a3043b2610a0f4bc285f
4
+ data.tar.gz: 1386f2606152b290a445e1d7e9869da0d7cfc2d59bb3b9b2baf720a229a45e2a
5
5
  SHA512:
6
- metadata.gz: e2b484c364e220f79e2ae876614947731fa54a008703ce70ba9a78bea5462c20a2a05d236296cc3f44ebd0ef1b7a9408d7036016722eed922520a2bad3749065
7
- data.tar.gz: bdca017d6084369de21feec4a31ed23c224b5526048d4f3f01a3d05559b5db5477fe71768080f15d0fa42cfaf3f7c26bec2b04bcd7b2d6af5c46a1380ea27f60
6
+ metadata.gz: 99ff80e29fa39ae47633ab1dcfd82a141825833cbb38329ee8b827fdb17006fd80e988c71075cdcd563a04336283f8ba7b2e9dc6d3d50346abf36d217d6cc654
7
+ data.tar.gz: 891c467d54a0355228b3108d096b4e220702c1ec4bfb393f83b5e2c878c616d378999e442ba80948fed1af4cc91c64bd431e757cc1b415368901cbb6836c6208
data/AUTHENTICATION.md ADDED
@@ -0,0 +1,178 @@
1
+ # Authentication
2
+
3
+ In general, the google-cloud-pubsub library uses [Service
4
+ Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
5
+ credentials to connect to Google Cloud services. When running on Compute Engine
6
+ the credentials will be discovered automatically. When running on other
7
+ environments, the Service Account credentials can be specified by providing the
8
+ path to the [JSON
9
+ keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys) for
10
+ the account (or the JSON itself) in environment variables. Additionally, Cloud
11
+ SDK credentials can also be discovered automatically, but this is only
12
+ recommended during development.
13
+
14
+ ## Project and Credential Lookup
15
+
16
+ The google-cloud-pubsub library aims to make authentication as simple as
17
+ possible, and provides several mechanisms to configure your system without
18
+ providing **Project ID** and **Service Account Credentials** directly in code.
19
+
20
+ **Project ID** is discovered in the following order:
21
+
22
+ 1. Specify project ID in method arguments
23
+ 2. Specify project ID in configuration
24
+ 3. Discover project ID in environment variables
25
+ 4. Discover GCE project ID
26
+
27
+ **Credentials** are discovered in the following order:
28
+
29
+ 1. Specify credentials in method arguments
30
+ 2. Specify credentials in configuration
31
+ 3. Discover credentials path in environment variables
32
+ 4. Discover credentials JSON in environment variables
33
+ 5. Discover credentials file in the Cloud SDK's path
34
+ 6. Discover GCE credentials
35
+
36
+ ### Google Cloud Platform environments
37
+
38
+ While running on Google Cloud Platform environments such as Google Compute
39
+ Engine, Google App Engine and Google Kubernetes Engine, no extra work is needed.
40
+ The **Project ID** and **Credentials** and are discovered automatically. Code
41
+ should be written as if already authenticated. Just be sure when you [set up the
42
+ GCE instance][gce-how-to], you add the correct scopes for the APIs you want to
43
+ access. For example:
44
+
45
+ * **All APIs**
46
+ * `https://www.googleapis.com/auth/cloud-platform`
47
+ * `https://www.googleapis.com/auth/cloud-platform.read-only`
48
+ * **BigQuery**
49
+ * `https://www.googleapis.com/auth/bigquery`
50
+ * `https://www.googleapis.com/auth/bigquery.insertdata`
51
+ * **Compute Engine**
52
+ * `https://www.googleapis.com/auth/compute`
53
+ * **Datastore**
54
+ * `https://www.googleapis.com/auth/datastore`
55
+ * `https://www.googleapis.com/auth/userinfo.email`
56
+ * **DNS**
57
+ * `https://www.googleapis.com/auth/ndev.clouddns.readwrite`
58
+ * **Pub/Sub**
59
+ * `https://www.googleapis.com/auth/pubsub`
60
+ * **Storage**
61
+ * `https://www.googleapis.com/auth/devstorage.full_control`
62
+ * `https://www.googleapis.com/auth/devstorage.read_only`
63
+ * `https://www.googleapis.com/auth/devstorage.read_write`
64
+
65
+ ### Environment Variables
66
+
67
+ The **Project ID** and **Credentials JSON** can be placed in environment
68
+ variables instead of declaring them directly in code. Each service has its own
69
+ environment variable, allowing for different service accounts to be used for
70
+ different services. (See the READMEs for the individual service gems for
71
+ details.) The path to the **Credentials JSON** file can be stored in the
72
+ environment variable, or the **Credentials JSON** itself can be stored for
73
+ environments such as Docker containers where writing files is difficult or not
74
+ encouraged.
75
+
76
+ The environment variables that Pub/Sub checks for project ID are:
77
+
78
+ 1. `PUBSUB_PROJECT`
79
+ 2. `GOOGLE_CLOUD_PROJECT`
80
+
81
+ The environment variables that Pub/Sub checks for credentials are configured on {Google::Cloud::Pubsub::V1::Credentials}:
82
+
83
+ 1. `PUBSUB_CREDENTIALS` - Path to JSON file, or JSON contents
84
+ 2. `PUBSUB_KEYFILE` - Path to JSON file, or JSON contents
85
+ 3. `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
86
+ 4. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
87
+ 5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
88
+
89
+ ```ruby
90
+ require "google/cloud/pubsub"
91
+
92
+ ENV["PUBSUB_PROJECT"] = "my-project-id"
93
+ ENV["PUBSUB_CREDENTIALS"] = "path/to/keyfile.json"
94
+
95
+ pubsub = Google::Cloud::Pubsub.new
96
+ ```
97
+
98
+ ### Configuration
99
+
100
+ The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
101
+
102
+ ```ruby
103
+ require "google/cloud/pubsub"
104
+
105
+ Google::Cloud::Pubsub.configure do |config|
106
+ config.project_id = "my-project-id"
107
+ config.credentials = "path/to/keyfile.json"
108
+ end
109
+
110
+ pubsub = Google::Cloud::Pubsub.new
111
+ ```
112
+
113
+ ### Cloud SDK
114
+
115
+ This option allows for an easy way to authenticate during development. If
116
+ credentials are not provided in code or in environment variables, then Cloud SDK
117
+ credentials are discovered.
118
+
119
+ To configure your system for this, simply:
120
+
121
+ 1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
122
+ 2. Authenticate using OAuth 2.0 `$ gcloud auth login`
123
+ 3. Write code as if already authenticated.
124
+
125
+ **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
126
+ *should* only be used during development.
127
+
128
+ [gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
129
+ [dev-console]: https://console.cloud.google.com/project
130
+
131
+ [enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
132
+
133
+ [create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
134
+ [create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
135
+ [reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
136
+
137
+ ## Creating a Service Account
138
+
139
+ Google Cloud requires a **Project ID** and **Service Account Credentials** to
140
+ connect to the APIs. You will use the **Project ID** and **JSON key file** to
141
+ connect to most services with google-cloud-pubsub.
142
+
143
+ If you are not running this client on Google Compute Engine, you need a Google
144
+ Developers service account.
145
+
146
+ 1. Visit the [Google Developers Console][dev-console].
147
+ 1. Create a new project or click on an existing project.
148
+ 1. Activate the slide-out navigation tray and select **API Manager**. From
149
+ here, you will enable the APIs that your application requires.
150
+
151
+ ![Enable the APIs that your application requires][enable-apis]
152
+
153
+ *Note: You may need to enable billing in order to use these services.*
154
+
155
+ 1. Select **Credentials** from the side navigation.
156
+
157
+ You should see a screen like one of the following.
158
+
159
+ ![Create a new service account][create-new-service-account]
160
+
161
+ ![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
162
+
163
+ Find the "Add credentials" drop down and select "Service account" to be
164
+ guided through downloading a new JSON key file.
165
+
166
+ If you want to re-use an existing service account, you can easily generate a
167
+ new key file. Just select the account you wish to re-use, and click "Generate
168
+ new JSON key":
169
+
170
+ ![Re-use an existing service account][reuse-service-account]
171
+
172
+ The key file you download will be used by this library to authenticate API
173
+ requests and should be stored in a secure location.
174
+
175
+ ## Troubleshooting
176
+
177
+ If you're having trouble authenticating you can ask for help by following the
178
+ {file:TROUBLESHOOTING.md Troubleshooting Guide}.
data/CHANGELOG.md ADDED
@@ -0,0 +1,161 @@
1
+ # Release History
2
+
3
+ ### 0.32.2 / 2018-09-12
4
+
5
+ * Add missing documentation files to package.
6
+
7
+ ### 0.32.1 / 2018-09-10
8
+
9
+ * Fix issue where client_config was not being used on publisher API calls.
10
+ * Update documentation.
11
+
12
+ ### 0.32.0 / 2018-08-14
13
+
14
+ * Updated Subscriber implementation
15
+ * Revised shutdown mechanics
16
+ * Fixes stop and wait! would hanging indefinitely.
17
+ * Reduce the number of GRPC warnings printed.
18
+ * Added error callbacks to the API
19
+ * Use error handler to be notified when unhandled errors
20
+ occur on a subscriber's stream thread.
21
+ * Documentation updates.
22
+
23
+ ### 0.31.1 / 2018-08-14
24
+
25
+ * Fix bug in AsyncUnaryPusher,
26
+ * The modify_ack_deadline requests were malformed.
27
+
28
+ ### 0.31.0 / 2018-06-12
29
+
30
+ * Switch Subscriber to use unary RPC calls for ack/modack.
31
+ * Reduce number of String objects that are garbage collected.
32
+ * Documentation updates.
33
+
34
+ ### 0.30.2 / 2018-04-02
35
+
36
+ * Subscriber stability enhancements.
37
+ * Subscriber performance enhancements.
38
+
39
+ ### 0.30.1 / 2018-03-08
40
+
41
+ * Fix Subscriber thread leak.
42
+
43
+ ### 0.30.0 / 2018-02-27
44
+
45
+ * Support Shared Configuration.
46
+ * Fix issue with IAM Policy not refreshing properly.
47
+
48
+ ### 0.29.0 / 2017-12-19
49
+
50
+ * Update Subscriber's receipt of received messages.
51
+ * Refactor Subscriber implementation to fix some threading bugs.
52
+ * Update google-gax dependency to 1.0.
53
+
54
+ ### 0.28.1 / 2017-11-21
55
+
56
+ * Remove warning when connecting to Pub/Sub Emulator.
57
+
58
+ ### 0.28.0 / 2017-11-14
59
+
60
+ * Add `Google::Cloud::Pubsub::Credentials` class.
61
+ * Rename constructor arguments to `project_id` and `credentials`.
62
+ (The previous arguments `project` and `keyfile` are still supported.)
63
+ * Document `Google::Auth::Credentials` as `credentials` value.
64
+ * Update generated low level GAPIC code.
65
+ * Updated `google-gax` (`grpc`, `google-protobuf`), `googleauth` dependencies.
66
+
67
+ ### 0.27.2 / 2017-10-18
68
+
69
+ * Update documentation
70
+
71
+ ### 0.27.1 / 2017-10-11
72
+
73
+ * Add keepalive to gRPC connections.
74
+ * Update Subscriber Streaming Messages error handling
75
+ * Fix link in README
76
+
77
+ ### 0.27.0 / 2017-08-10
78
+
79
+ This is a major release that offers new functionality. It adds the ability to asynchronously publish batches of messages when a threshold is met (batch message count, total batch size, batch age). It also adds the ability to receive and acknowledge messages via multiple streams.
80
+
81
+ * Publishing Messages Asynchronously
82
+ * `Topic#publish_async` and `AsyncPublisher` added
83
+ * `AsyncPublisher` can be stopped
84
+ * `PublishResult` object is yielded from `Topic#publish_async`
85
+ * Subscriber Streaming Messages
86
+ * `Subscription#listen` changed to return a `Subscriber` object
87
+ * `Subscriber` can open multiple streams to pull messages
88
+ * `Subscriber` must be started to begin streaming messages
89
+ * `Subscriber` can be stopped
90
+ * `Subscriber`'s received messages are leased until acknowledged or rejected
91
+ * Other Additions
92
+ * `ReceivedMessage#reject!` method added (aliased as `nack!` and `ignore!`)
93
+ * `Message#published_at` attribute was added
94
+ * Removals
95
+ * `Project#publish` method has been removed
96
+ * `Project#subscribe` method has been removed
97
+ * `Project#topic` method argument `autocreate` was removed
98
+ * `Subscription#pull` method argument `autoack` was removed
99
+ * `Subscription#wait_for_messages` method argument `autoack` was removed
100
+
101
+ ### 0.26.0 / 2017-07-11
102
+
103
+ * Update GAPIC configuration to exclude `UNAVAILABLE` errors from automatic retry.
104
+ * Update initialization to raise a better error if project ID is not specified.
105
+
106
+ ### 0.25.0 / 2017-06-01
107
+
108
+ * Add Snapshot and Subscription#seek.
109
+ * Add Subscription#retain_acked and Subscription#retention.
110
+ * Update gem spec homepage links.
111
+ * Remove memoization of Policy.
112
+ * Remove force parameter from Subscription#policy and Topic#policy.
113
+ * Remove Policy#deep_dup.
114
+ * Configure gRPC max_send_message_length and max_receive_message_length
115
+ to accommodate max message size > 4 MB.
116
+
117
+ ### 0.24.0 / 2017-03-31
118
+
119
+ * Updated documentation
120
+ * Updated retry configuration for pull requests
121
+ * Automatic retry on `UNAVAILABLE` errors
122
+
123
+ ### 0.23.2 / 2017-03-03
124
+
125
+ * No public API changes.
126
+ * Update GRPC header value sent to the Pub/Sub API.
127
+
128
+ ### 0.23.1 / 2017-03-01
129
+
130
+ * No public API changes.
131
+ * Update GRPC header value sent to the Pub/Sub API.
132
+ * Low level API adds new Protobuf types and GAPIC methods.
133
+
134
+ ### 0.23.0 / 2017-02-21
135
+
136
+ * Add emulator_host parameter
137
+ * Fix GRPC retry bug
138
+ * The client_config data structure has replaced retry_codes/retry_codes_def with retry_codes
139
+ * Update GRPC/Protobuf/GAX dependencies
140
+
141
+ ### 0.22.0 / 2017-01-26
142
+
143
+ * Change class names in low-level API (GAPIC)
144
+ * Change method parameters in low-level API (GAPIC)
145
+ * Add LICENSE to package.
146
+
147
+ ### 0.21.0 / 2016-10-20
148
+
149
+ * New service constructor Google::Cloud::Pubsub.new
150
+ * New constructor argument client_config
151
+
152
+ ### 0.20.1 / 2016-09-02
153
+
154
+ * Fix an issue with the GRPC client and forked sub-processes
155
+
156
+ ### 0.20.0 / 2016-08-26
157
+
158
+ This gem contains the Google Cloud Pub/Sub service implementation for the `google-cloud` gem. The `google-cloud` gem replaces the old `gcloud` gem. Legacy code can continue to use the `gcloud` gem.
159
+
160
+ * Namespace is now `Google::Cloud`
161
+ * The `google-cloud` gem is now an umbrella package for individual gems
@@ -0,0 +1,40 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct.
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or reject
24
+ comments, commits, code, wiki edits, issues, and other contributions that are
25
+ not aligned to this Code of Conduct. By adopting this Code of Conduct, project
26
+ maintainers commit themselves to fairly and consistently applying these
27
+ principles to every aspect of managing this project. Project maintainers who do
28
+ not follow or enforce the Code of Conduct may be permanently removed from the
29
+ project team.
30
+
31
+ This code of conduct applies both within project spaces and in public spaces
32
+ when an individual is representing the project or its community.
33
+
34
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
35
+ reported by opening an issue or contacting one or more of the project
36
+ maintainers.
37
+
38
+ This Code of Conduct is adapted from the [Contributor
39
+ Covenant](http://contributor-covenant.org), version 1.2.0, available at
40
+ [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,188 @@
1
+ # Contributing to Google Cloud Pub/Sub
2
+
3
+ 1. **Sign one of the contributor license agreements below.**
4
+ 2. Fork the repo, develop and test your code changes.
5
+ 3. Send a pull request.
6
+
7
+ ## Contributor License Agreements
8
+
9
+ Before we can accept your pull requests you'll need to sign a Contributor
10
+ License Agreement (CLA):
11
+
12
+ - **If you are an individual writing original source code** and **you own the
13
+ intellectual property**, then you'll need to sign an [individual
14
+ CLA](https://developers.google.com/open-source/cla/individual).
15
+ - **If you work for a company that wants to allow you to contribute your work**,
16
+ then you'll need to sign a [corporate
17
+ CLA](https://developers.google.com/open-source/cla/corporate).
18
+
19
+ You can sign these electronically (just scroll to the bottom). After that, we'll
20
+ be able to accept your pull requests.
21
+
22
+ ## Setup
23
+
24
+ In order to use the google-cloud-pubsub console and run the project's tests,
25
+ there is a small amount of setup:
26
+
27
+ 1. Install Ruby. google-cloud-pubsub requires Ruby 2.3+. You may choose to
28
+ manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
+ [rbenv](https://github.com/rbenv/rbenv), or
30
+ [chruby](https://github.com/postmodern/chruby).
31
+
32
+ 2. Install [Bundler](http://bundler.io/).
33
+
34
+ ```sh
35
+ $ gem install bundler
36
+ ```
37
+
38
+ 3. Install the top-level project dependencies.
39
+
40
+ ```sh
41
+ $ bundle install
42
+ ```
43
+
44
+ 4. Install the Pub/Sub dependencies.
45
+
46
+ ```sh
47
+ $ cd google-cloud-pubsub/
48
+ $ bundle exec rake bundleupdate
49
+ ```
50
+
51
+ ## Console
52
+
53
+ In order to run code interactively, you can automatically load
54
+ google-cloud-pubsub and its dependencies in IRB. This requires that your
55
+ developer environment has already been configured by following the steps
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
+ can be created with:
58
+
59
+ ```sh
60
+ $ cd google-cloud-pubsub/
61
+ $ bundle exec rake console
62
+ ```
63
+
64
+ ## Pub/Sub Tests
65
+
66
+ Tests are very important part of google-cloud-pubsub. All contributions
67
+ should include tests that ensure the contributed code behaves as expected.
68
+
69
+ To run the unit tests, documentation tests, and code style checks together for a
70
+ package:
71
+
72
+ ``` sh
73
+ $ cd google-cloud-pubsub/
74
+ $ bundle exec rake ci
75
+ ```
76
+
77
+ To run the command above, plus all acceptance tests, use `rake ci:acceptance` or
78
+ its handy alias, `rake ci:a`.
79
+
80
+ ### Pub/Sub Unit Tests
81
+
82
+
83
+ The project uses the [minitest](https://github.com/seattlerb/minitest) library,
84
+ including [specs](https://github.com/seattlerb/minitest#specs),
85
+ [mocks](https://github.com/seattlerb/minitest#mocks) and
86
+ [minitest-autotest](https://github.com/seattlerb/minitest-autotest).
87
+
88
+ To run the Pub/Sub unit tests:
89
+
90
+ ``` sh
91
+ $ cd google-cloud-pubsub/
92
+ $ bundle exec rake test
93
+ ```
94
+
95
+ ### Pub/Sub Documentation Tests
96
+
97
+ The project tests the code examples in the gem's
98
+ [YARD](https://github.com/lsegal/yard)-based documentation.
99
+
100
+ The example testing functions in a way that is very similar to unit testing, and
101
+ in fact the library providing it,
102
+ [yard-doctest](https://github.com/p0deje/yard-doctest), is based on the
103
+ project's unit test library, [minitest](https://github.com/seattlerb/minitest).
104
+
105
+ To run the Pub/Sub documentation tests:
106
+
107
+ ``` sh
108
+ $ cd google-cloud-pubsub/
109
+ $ bundle exec rake doctest
110
+ ```
111
+
112
+ If you add, remove or modify documentation examples when working on a pull
113
+ request, you may need to update the setup for the tests. The stubs and mocks
114
+ required to run the tests are located in `support/doctest_helper.rb`. Please
115
+ note that much of the setup is matched by the title of the
116
+ [`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag.
117
+ If you alter an example's title, you may encounter breaking tests.
118
+
119
+ ### Pub/Sub Acceptance Tests
120
+
121
+ The Pub/Sub acceptance tests interact with the live service API. Follow the
122
+ instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
123
+ the Pub/Sub API. Occasionally, some API features may not yet be generally
124
+ available, making it difficult for some contributors to successfully run the
125
+ entire acceptance test suite. However, please ensure that you do successfully
126
+ run acceptance tests for any code areas covered by your pull request.
127
+
128
+ To run the acceptance tests, first create and configure a project in the Google
129
+ Developers Console, as described in the {file:AUTHENTICATION.md Authentication
130
+ guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
131
+ the KEYFILE location on your system.
132
+
133
+ Before you can run the Pub/Sub acceptance tests, you must first create indexes
134
+ used in the tests.
135
+
136
+ #### Running the Pub/Sub acceptance tests
137
+
138
+ To run the Pub/Sub acceptance tests:
139
+
140
+ ``` sh
141
+ $ cd google-cloud-pubsub/
142
+ $ bundle exec rake acceptance[\\{my-project-id},\\{/path/to/keyfile.json}]
143
+ ```
144
+
145
+ Or, if you prefer you can store the values in the `GCLOUD_TEST_PROJECT` and
146
+ `GCLOUD_TEST_KEYFILE` environment variables:
147
+
148
+ ``` sh
149
+ $ cd google-cloud-pubsub/
150
+ $ export GCLOUD_TEST_PROJECT=\\{my-project-id}
151
+ $ export GCLOUD_TEST_KEYFILE=\\{/path/to/keyfile.json}
152
+ $ bundle exec rake acceptance
153
+ ```
154
+
155
+ If you want to use a different project and credentials for acceptance tests, you
156
+ can use the more specific `PUBSUB_TEST_PROJECT` and `PUBSUB_TEST_KEYFILE`
157
+ environment variables:
158
+
159
+ ``` sh
160
+ $ cd google-cloud-pubsub/
161
+ $ export PUBSUB_TEST_PROJECT=\\{my-project-id}
162
+ $ export PUBSUB_TEST_KEYFILE=\\{/path/to/keyfile.json}
163
+ $ bundle exec rake acceptance
164
+ ```
165
+
166
+ ## Coding Style
167
+
168
+ Please follow the established coding style in the library. The style is is
169
+ largely based on [The Ruby Style
170
+ Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based
171
+ on seattle-style:
172
+
173
+ * Avoid parenthesis when possible, including in method definitions.
174
+ * Always use double quotes strings. ([Option
175
+ B](https://github.com/bbatsov/ruby-style-guide#strings))
176
+
177
+ You can check your code against these rules by running Rubocop like so:
178
+
179
+ ```sh
180
+ $ cd google-cloud-pubsub/
181
+ $ bundle exec rake rubocop
182
+ ```
183
+
184
+ ## Code of Conduct
185
+
186
+ Please note that this project is released with a Contributor Code of Conduct. By
187
+ participating in this project you agree to abide by its terms. See
188
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
data/EMULATOR.md ADDED
@@ -0,0 +1,37 @@
1
+ # Google Cloud Pub/Sub Emulator
2
+
3
+ To develop and test your application locally, you can use the [Google Cloud
4
+ Pub/Sub Emulator](https://cloud.google.com/pubsub/emulator), which provides
5
+ [local emulation](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/)
6
+ of the production Google Cloud Pub/Sub environment. You can start the Google
7
+ Cloud Pub/Sub emulator using the `gcloud` command-line tool.
8
+
9
+ To configure your ruby code to use the emulator, set the `PUBSUB_EMULATOR_HOST`
10
+ environment variable to the host and port where the emulator is running. The
11
+ value can be set as an environment variable in the shell running the ruby code,
12
+ or can be set directly in the ruby code as shown below.
13
+
14
+ ```ruby
15
+ require "google/cloud/pubsub"
16
+
17
+ # Make Pub/Sub use the emulator
18
+ ENV["PUBSUB_EMULATOR_HOST"] = "localhost:8918"
19
+
20
+ pubsub = Google::Cloud::Pubsub.new "emulator-project-id"
21
+
22
+ # Get a topic in the current project
23
+ my_topic = pubsub.new_topic "my-topic"
24
+ my_topic.name #=> "projects/emulator-project-id/topics/my-topic"
25
+ ```
26
+
27
+ Or by providing the `emulator_host` argument:
28
+
29
+ ```ruby
30
+ require "google/cloud/pubsub"
31
+
32
+ pubsub = Google::Cloud::Pubsub.new emulator_host: "localhost:8918"
33
+
34
+ # Get a topic in the current project
35
+ my_topic = pubsub.new_topic "my-topic"
36
+ my_topic.name #=> "projects/emulator-project-id/topics/my-topic"
37
+ ```
data/LOGGING.md ADDED
@@ -0,0 +1,32 @@
1
+ # Enabling gRPC Logging
2
+
3
+ To enable logging for this library, set the logger for the underlying
4
+ [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
5
+ that you set may be a Ruby stdlib
6
+ [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
7
+ shown below, or a
8
+ [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger)
9
+ that will write logs to [Stackdriver
10
+ Logging](https://cloud.google.com/logging/). See
11
+ [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
12
+ and the gRPC
13
+ [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb)
14
+ for additional information.
15
+
16
+ Configuring a Ruby stdlib logger:
17
+
18
+ ```ruby
19
+ require "logger"
20
+
21
+ module MyLogger
22
+ LOGGER = Logger.new $stderr, level: Logger::WARN
23
+ def logger
24
+ LOGGER
25
+ end
26
+ end
27
+
28
+ # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
29
+ module GRPC
30
+ extend MyLogger
31
+ end
32
+ ```
data/OVERVIEW.md ADDED
@@ -0,0 +1,435 @@
1
+ # Google Cloud Pub/Sub
2
+
3
+ Google Cloud Pub/Sub is designed to provide reliable, many-to-many, asynchronous
4
+ messaging between applications. Publisher applications can send messages to a
5
+ "topic" and other applications can subscribe to that topic to receive the
6
+ messages. By decoupling senders and receivers, Google Cloud Pub/Sub allows
7
+ developers to communicate between independently written applications.
8
+
9
+ The goal of google-cloud is to provide an API that is comfortable to Rubyists.
10
+ Your authentication credentials are detected automatically in Google Cloud
11
+ Platform environments such as Google Compute Engine, Google App Engine and
12
+ Google Kubernetes Engine. In other environments you can configure authentication
13
+ easily, either directly in your code or via environment variables. Read more
14
+ about the options for connecting in the {file:AUTHENTICATION.md Authentication
15
+ Guide}.
16
+
17
+ ```ruby
18
+ require "google/cloud/pubsub"
19
+
20
+ pubsub = Google::Cloud::Pubsub.new
21
+
22
+ topic = pubsub.topic "my-topic"
23
+ topic.publish "task completed"
24
+ ```
25
+
26
+ To learn more about Pub/Sub, read the [Google Cloud Pub/Sub Overview
27
+ ](https://cloud.google.com/pubsub/overview).
28
+
29
+ ## Retrieving Topics
30
+
31
+ A Topic is a named resource to which messages are sent by publishers. A Topic is
32
+ found by its name. (See {Google::Cloud::Pubsub::Project#topic Project#topic})
33
+
34
+ ```ruby
35
+ require "google/cloud/pubsub"
36
+
37
+ pubsub = Google::Cloud::Pubsub.new
38
+ topic = pubsub.topic "my-topic"
39
+ ```
40
+
41
+ ## Creating a Topic
42
+
43
+ A Topic is created from a Project. (See
44
+ {Google::Cloud::Pubsub::Project#create_topic Project#create_topic})
45
+
46
+ ```ruby
47
+ require "google/cloud/pubsub"
48
+
49
+ pubsub = Google::Cloud::Pubsub.new
50
+ topic = pubsub.create_topic "my-topic"
51
+ ```
52
+
53
+ ## Retrieving Subscriptions
54
+
55
+ A Subscription is a named resource representing the stream of messages from a
56
+ single, specific Topic, to be delivered to the subscribing application. A
57
+ Subscription is found by its name. (See
58
+ {Google::Cloud::Pubsub::Topic#subscription Topic#subscription})
59
+
60
+ ```ruby
61
+ require "google/cloud/pubsub"
62
+
63
+ pubsub = Google::Cloud::Pubsub.new
64
+
65
+ topic = pubsub.topic "my-topic"
66
+ subscription = topic.subscription "my-topic-subscription"
67
+ puts subscription.name
68
+ ```
69
+
70
+ ## Creating a Subscription
71
+
72
+ A Subscription is created from a Topic. (See
73
+ {Google::Cloud::Pubsub::Topic#subscribe Topic#subscribe})
74
+
75
+ ```ruby
76
+ require "google/cloud/pubsub"
77
+
78
+ pubsub = Google::Cloud::Pubsub.new
79
+
80
+ topic = pubsub.topic "my-topic"
81
+ sub = topic.subscribe "my-topic-sub"
82
+ puts sub.name # => "my-topic-sub"
83
+ ```
84
+
85
+ The subscription can be created that specifies the number of seconds to wait to
86
+ be acknowledged as well as an endpoint URL to push the messages to:
87
+
88
+ ```ruby
89
+ require "google/cloud/pubsub"
90
+
91
+ pubsub = Google::Cloud::Pubsub.new
92
+
93
+ topic = pubsub.topic "my-topic"
94
+ sub = topic.subscribe "my-topic-sub",
95
+ deadline: 120,
96
+ endpoint: "https://example.com/push"
97
+ ```
98
+
99
+ ## Publishing Messages
100
+
101
+ Messages are published to a topic. Any message published to a topic without a
102
+ subscription will be lost. Ensure the topic has a subscription before
103
+ publishing. (See {Google::Cloud::Pubsub::Topic#publish Topic#publish})
104
+
105
+ ```ruby
106
+ require "google/cloud/pubsub"
107
+
108
+ pubsub = Google::Cloud::Pubsub.new
109
+
110
+ topic = pubsub.topic "my-topic"
111
+ msg = topic.publish "task completed"
112
+ ```
113
+
114
+ Messages can also be published with attributes:
115
+
116
+ ```ruby
117
+ require "google/cloud/pubsub"
118
+
119
+ pubsub = Google::Cloud::Pubsub.new
120
+
121
+ topic = pubsub.topic "my-topic"
122
+ msg = topic.publish "task completed",
123
+ foo: :bar,
124
+ this: :that
125
+ ```
126
+
127
+ Messages can also be published in batches asynchronously using `publish_async`.
128
+ (See {Google::Cloud::Pubsub::Topic#publish_async Topic#publish_async} and
129
+ {Google::Cloud::Pubsub::AsyncPublisher AsyncPublisher})
130
+
131
+ ```ruby
132
+ require "google/cloud/pubsub"
133
+
134
+ pubsub = Google::Cloud::Pubsub.new
135
+
136
+ topic = pubsub.topic "my-topic"
137
+ topic.publish_async "task completed" do |result|
138
+ if result.succeeded?
139
+ log_publish_success result.data
140
+ else
141
+ log_publish_failure result.data, result.error
142
+ end
143
+ end
144
+
145
+ topic.async_publisher.stop.wait!
146
+ ```
147
+
148
+ Or multiple messages can be published in batches at the same time by passing a
149
+ block to `publish`. (See {Google::Cloud::Pubsub::BatchPublisher BatchPublisher})
150
+
151
+ ```ruby
152
+ require "google/cloud/pubsub"
153
+
154
+ pubsub = Google::Cloud::Pubsub.new
155
+
156
+ topic = pubsub.topic "my-topic"
157
+ msgs = topic.publish do |batch|
158
+ batch.publish "task 1 completed", foo: :bar
159
+ batch.publish "task 2 completed", foo: :baz
160
+ batch.publish "task 3 completed", foo: :bif
161
+ end
162
+ ```
163
+
164
+ ## Receiving messages
165
+
166
+ Messages can be streamed from a subscription with a subscriber object that is
167
+ created using `listen`. (See {Google::Cloud::Pubsub::Subscription#listen
168
+ Subscription#listen} and {Google::Cloud::Pubsub::Subscriber Subscriber})
169
+
170
+ ```ruby
171
+ require "google/cloud/pubsub"
172
+
173
+ pubsub = Google::Cloud::Pubsub.new
174
+
175
+ sub = pubsub.subscription "my-topic-sub"
176
+
177
+ subscriber = sub.listen do |received_message|
178
+ # process message
179
+ received_message.acknowledge!
180
+ end
181
+
182
+ # Start background threads that will call the block passed to listen.
183
+ subscriber.start
184
+
185
+ # Shut down the subscriber when ready to stop receiving messages.
186
+ subscriber.stop.wait!
187
+ ```
188
+
189
+ Messages also can be pulled directly in a one-time operation. (See
190
+ {Google::Cloud::Pubsub::Subscription#pull Subscription#pull})
191
+
192
+ ```ruby
193
+ require "google/cloud/pubsub"
194
+
195
+ pubsub = Google::Cloud::Pubsub.new
196
+
197
+ sub = pubsub.subscription "my-topic-sub"
198
+ received_messages = sub.pull
199
+ ```
200
+
201
+ A maximum number of messages to pull can be specified:
202
+
203
+ ```ruby
204
+ require "google/cloud/pubsub"
205
+
206
+ pubsub = Google::Cloud::Pubsub.new
207
+
208
+ sub = pubsub.subscription "my-topic-sub"
209
+ received_messages = sub.pull max: 10
210
+ ```
211
+
212
+ ## Acknowledging a Message
213
+
214
+ Messages that are received can be acknowledged in Pub/Sub, marking the message
215
+ to be removed so it cannot be pulled again.
216
+
217
+ A Message that can be acknowledged is called a ReceivedMessage. ReceivedMessages
218
+ can be acknowledged one at a time: (See
219
+ {Google::Cloud::Pubsub::ReceivedMessage#acknowledge!
220
+ ReceivedMessage#acknowledge!})
221
+
222
+ ```ruby
223
+ require "google/cloud/pubsub"
224
+
225
+ pubsub = Google::Cloud::Pubsub.new
226
+
227
+ sub = pubsub.subscription "my-topic-sub"
228
+
229
+ subscriber = sub.listen do |received_message|
230
+ # process message
231
+ received_message.acknowledge!
232
+ end
233
+
234
+ # Start background threads that will call the block passed to listen.
235
+ subscriber.start
236
+
237
+ # Shut down the subscriber when ready to stop receiving messages.
238
+ subscriber.stop.wait!
239
+ ```
240
+
241
+ Or, multiple messages can be acknowledged in a single API call: (See
242
+ {Google::Cloud::Pubsub::Subscription#acknowledge Subscription#acknowledge})
243
+
244
+ ```ruby
245
+ require "google/cloud/pubsub"
246
+
247
+ pubsub = Google::Cloud::Pubsub.new
248
+
249
+ sub = pubsub.subscription "my-topic-sub"
250
+ received_messages = sub.pull
251
+ sub.acknowledge received_messages
252
+ ```
253
+
254
+ ## Modifying a Deadline
255
+
256
+ A message must be acknowledged after it is pulled, or Pub/Sub will mark the
257
+ message for redelivery. The message acknowledgement deadline can delayed if more
258
+ time is needed. This will allow more time to process the message before the
259
+ message is marked for redelivery. (See
260
+ {Google::Cloud::Pubsub::ReceivedMessage#delay! ReceivedMessage#delay!})
261
+
262
+ ```ruby
263
+ require "google/cloud/pubsub"
264
+
265
+ pubsub = Google::Cloud::Pubsub.new
266
+
267
+ sub = pubsub.subscription "my-topic-sub"
268
+ subscriber = sub.listen do |received_message|
269
+ puts received_message.message.data
270
+
271
+ # Delay for 2 minutes
272
+ received_message.delay! 120
273
+ end
274
+
275
+ # Start background threads that will call the block passed to listen.
276
+ subscriber.start
277
+
278
+ # Shut down the subscriber when ready to stop receiving messages.
279
+ subscriber.stop.wait!
280
+ ```
281
+
282
+ The message can also be made available for immediate redelivery:
283
+
284
+ ```ruby
285
+ require "google/cloud/pubsub"
286
+
287
+ pubsub = Google::Cloud::Pubsub.new
288
+
289
+ sub = pubsub.subscription "my-topic-sub"
290
+ subscriber = sub.listen do |received_message|
291
+ puts received_message.message.data
292
+
293
+ # Mark for redelivery
294
+ received_message.reject!
295
+ end
296
+
297
+ # Start background threads that will call the block passed to listen.
298
+ subscriber.start
299
+
300
+ # Shut down the subscriber when ready to stop receiving messages.
301
+ subscriber.stop.wait!
302
+ ```
303
+
304
+ Multiple messages can be delayed or made available for immediate redelivery:
305
+ (See {Google::Cloud::Pubsub::Subscription#delay Subscription#delay})
306
+
307
+ ```ruby
308
+ require "google/cloud/pubsub"
309
+
310
+ pubsub = Google::Cloud::Pubsub.new
311
+
312
+ sub = pubsub.subscription "my-topic-sub"
313
+ received_messages = sub.pull
314
+ sub.delay 120, received_messages
315
+ ```
316
+
317
+ ## Creating a snapshot and using seek
318
+
319
+ You can create a snapshot to retain the existing backlog on a subscription. The
320
+ snapshot will hold the messages in the subscription's backlog that are
321
+ unacknowledged upon the successful completion of the `create_snapshot`
322
+ operation.
323
+
324
+ Later, you can use `seek` to reset the subscription's backlog to the snapshot.
325
+
326
+ (See {Google::Cloud::Pubsub::Subscription#create_snapshot
327
+ Subscription#create_snapshot} and {Google::Cloud::Pubsub::Subscription#seek
328
+ Subscription#seek})
329
+
330
+ ```ruby
331
+ require "google/cloud/pubsub"
332
+
333
+ pubsub = Google::Cloud::Pubsub.new
334
+
335
+ sub = pubsub.subscription "my-topic-sub"
336
+
337
+ snapshot = sub.create_snapshot
338
+
339
+ received_messages = sub.pull
340
+ sub.acknowledge received_messages
341
+
342
+ sub.seek snapshot
343
+ ```
344
+
345
+ ## Listening for Messages
346
+
347
+ A subscriber object can be created using `listen`, which streams messages from
348
+ the backend and processes them as they are received. (See
349
+ {Google::Cloud::Pubsub::Subscription#listen Subscription#listen} and
350
+ {Google::Cloud::Pubsub::Subscriber Subscriber})
351
+
352
+ ```ruby
353
+ require "google/cloud/pubsub"
354
+
355
+ pubsub = Google::Cloud::Pubsub.new
356
+
357
+ sub = pubsub.subscription "my-topic-sub"
358
+
359
+ subscriber = sub.listen do |received_message|
360
+ # process message
361
+ received_message.acknowledge!
362
+ end
363
+
364
+ # Start background threads that will call the block passed to listen.
365
+ subscriber.start
366
+
367
+ # Shut down the subscriber when ready to stop receiving messages.
368
+ subscriber.stop.wait!
369
+ ```
370
+
371
+ The subscriber object can be configured to control the number of concurrent
372
+ streams to open, the number of received messages to be collected, and the number
373
+ of threads each stream opens for concurrent calls made to handle the received
374
+ messages.
375
+
376
+ ```ruby
377
+ require "google/cloud/pubsub"
378
+
379
+ pubsub = Google::Cloud::Pubsub.new
380
+
381
+ sub = pubsub.subscription "my-topic-sub"
382
+
383
+ subscriber = sub.listen threads: { callback: 16 } do |received_message|
384
+ # store the message somewhere before acknowledging
385
+ store_in_backend received_message.data # takes a few seconds
386
+ received_message.acknowledge!
387
+ end
388
+
389
+ # Start background threads that will call the block passed to listen.
390
+ subscriber.start
391
+ ```
392
+
393
+ ## Working Across Projects
394
+
395
+ All calls to the Pub/Sub service use the same project and credentials provided
396
+ to the {Google::Cloud::Pubsub.new Pubsub.new} method. However, it is common to
397
+ reference topics or subscriptions in other projects, which can be achieved by
398
+ using the `project` option. The main credentials must have permissions to the
399
+ topics and subscriptions in other projects.
400
+
401
+ ```ruby
402
+ require "google/cloud/pubsub"
403
+
404
+ pubsub = Google::Cloud::Pubsub.new # my-project
405
+
406
+ # Get a topic in the current project
407
+ my_topic = pubsub.topic "my-topic"
408
+ my_topic.name #=> "projects/my-project/topics/my-topic"
409
+ # Get a topic in another project
410
+ other_topic = pubsub.topic "other-topic", project: "other-project-id"
411
+ other_topic.name #=> "projects/other-project-id/topics/other-topic"
412
+ ```
413
+
414
+ It is possible to create a subscription in the current project that pulls
415
+ from a topic in another project:
416
+
417
+ ```ruby
418
+ require "google/cloud/pubsub"
419
+
420
+ pubsub = Google::Cloud::Pubsub.new # my-project
421
+
422
+ # Get a topic in another project
423
+ topic = pubsub.topic "other-topic", project: "other-project-id"
424
+ # Create a subscription in the current project that pulls from
425
+ # the topic in another project
426
+ sub = topic.subscribe "my-sub"
427
+ sub.name #=> "projects/my-project/subscriptions/my-sub"
428
+ sub.topic.name #=> "projects/other-project-id/topics/other-topic"
429
+ ```
430
+
431
+ ## Additional information
432
+
433
+ Google Cloud Pub/Sub can be configured to use an emulator or to enable gRPC's
434
+ logging. To learn more, see the {file:EMULATOR.md Emulator guide} and
435
+ {file:LOGGING.md Logging guide}.
@@ -0,0 +1,37 @@
1
+ # Troubleshooting
2
+
3
+ ## Where can I get more help?
4
+
5
+ ### Ask the Community
6
+
7
+ If you have a question about how to use a Google Cloud client library in your
8
+ project or are stuck in the Developer's console and don't know where to turn,
9
+ it's possible your questions have already been addressed by the community.
10
+
11
+ First, check out the appropriate tags on StackOverflow:
12
+ - [`google-cloud-platform+ruby+pubsub`][so-ruby]
13
+
14
+ Next, try searching through the issues on GitHub:
15
+
16
+ - [`api:pubsub` issues][gh-search-ruby]
17
+
18
+ Still nothing?
19
+
20
+ ### Ask the Developers
21
+
22
+ If you're experiencing a bug with the code, or have an idea for how it can be
23
+ improved, *please* create a new issue on GitHub so we can talk about it.
24
+
25
+ - [New issue][gh-ruby]
26
+
27
+ Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
+ can use the "ruby" channel for general Ruby questions, or use the
29
+ "google-cloud-ruby" channel if you have questions about this gem in particular.
30
+
31
+ [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+pubsub
32
+
33
+ [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+pubsub%22
34
+
35
+ [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
36
+
37
+ [slack-ruby]: https://gcp-slack.appspot.com/
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Pubsub
19
- VERSION = "0.32.1".freeze
19
+ VERSION = "0.32.2".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.1
4
+ version: 0.32.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-10 00:00:00.000000000 Z
12
+ date: 2018-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -216,8 +216,15 @@ extensions: []
216
216
  extra_rdoc_files: []
217
217
  files:
218
218
  - ".yardopts"
219
+ - AUTHENTICATION.md
220
+ - CHANGELOG.md
221
+ - CODE_OF_CONDUCT.md
222
+ - CONTRIBUTING.md
223
+ - EMULATOR.md
219
224
  - LICENSE
220
- - README.md
225
+ - LOGGING.md
226
+ - OVERVIEW.md
227
+ - TROUBLESHOOTING.md
221
228
  - lib/google-cloud-pubsub.rb
222
229
  - lib/google/cloud/pubsub.rb
223
230
  - lib/google/cloud/pubsub/async_publisher.rb
data/README.md DELETED
@@ -1,117 +0,0 @@
1
- # google-cloud-pubsub
2
-
3
- [Google Cloud Pub/Sub](https://cloud.google.com/pubsub/) ([docs](https://cloud.google.com/pubsub/docs/reference/rest/)) is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a “topic” and other applications can subscribe to that topic to receive the messages. By decoupling senders and receivers, Google Cloud Pub/Sub allows developers to communicate between independently written applications.
4
-
5
- - [google-cloud-pubsub API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest)
6
- - [google-cloud-pubsub on RubyGems](https://rubygems.org/gems/google-cloud-pubsub)
7
- - [Google Cloud Pub/Sub documentation](https://cloud.google.com/pubsub/docs)
8
-
9
- ## Quick Start
10
-
11
- ```sh
12
- $ gem install google-cloud-pubsub
13
- ```
14
-
15
- ## Authentication
16
-
17
- This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
18
-
19
- Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.AUTHENTICATION).
20
-
21
- ## Example
22
-
23
- ```ruby
24
- require "google/cloud/pubsub"
25
-
26
- pubsub = Google::Cloud::Pubsub.new(
27
- project_id: "my-project",
28
- credentials: "/path/to/keyfile.json"
29
- )
30
-
31
- # Retrieve a topic
32
- topic = pubsub.topic "my-topic"
33
-
34
- # Publish a new message
35
- msg = topic.publish "new-message"
36
-
37
- # Retrieve a subscription
38
- sub = pubsub.subscription "my-topic-sub"
39
-
40
- # Create a subscriber to listen for available messages
41
- subscriber = sub.listen do |received_message|
42
- # process message
43
- received_message.acknowledge!
44
- end
45
-
46
- # Start background threads that will call the block passed to listen.
47
- subscriber.start
48
-
49
- # Shut down the subscriber when ready to stop receiving messages.
50
- subscriber.stop.wait!
51
- ```
52
-
53
- ## Enabling Logging
54
-
55
- To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
56
-
57
- Configuring a Ruby stdlib logger:
58
-
59
- ```ruby
60
- require "logger"
61
-
62
- module MyLogger
63
- LOGGER = Logger.new $stderr, level: Logger::WARN
64
- def logger
65
- LOGGER
66
- end
67
- end
68
-
69
- # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
70
- module GRPC
71
- extend MyLogger
72
- end
73
- ```
74
-
75
- ## Supported Ruby Versions
76
-
77
- This library is supported on Ruby 2.3+.
78
-
79
- Google provides official support for Ruby versions that are actively supported
80
- by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
81
- security maintenance, and not end of life. Currently, this means Ruby 2.3 and
82
- later. Older versions of Ruby _may_ still work, but are unsupported and not
83
- recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
84
- about the Ruby support schedule.
85
-
86
- ## Versioning
87
-
88
- This library follows [Semantic Versioning](http://semver.org/).
89
-
90
- It is currently in major version zero (0.y.z), which means that anything may
91
- change at any time and the public API should not be considered stable.
92
-
93
- ## Contributing
94
-
95
- Contributions to this library are always welcome and highly encouraged.
96
-
97
- See the [Contributing
98
- Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.CONTRIBUTING)
99
- for more information on how to get started.
100
-
101
- Please note that this project is released with a Contributor Code of Conduct. By
102
- participating in this project you agree to abide by its terms. See [Code of
103
- Conduct](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.CODE_OF_CONDUCT)
104
- for more information.
105
-
106
- ## License
107
-
108
- This library is licensed under Apache 2.0. Full license text is available in
109
- [LICENSE](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-pubsub/latest/file.LICENSE).
110
-
111
- ## Support
112
-
113
- Please [report bugs at the project on
114
- Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues). Don't
115
- hesitate to [ask
116
- questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
117
- about the client or APIs on [StackOverflow](http://stackoverflow.com).