fluent-plugin-gcloud-pubsub-custom-subscriber 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +25 -0
- data/CHANGELOG.md +134 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +178 -0
- data/Rakefile +12 -0
- data/fluent-plugin-gcloud-pubsub-custom.gemspec +24 -0
- data/lib/fluent/plugin/gcloud_pubsub/client.rb +80 -0
- data/lib/fluent/plugin/in_gcloud_pubsub.rb +253 -0
- data/lib/fluent/plugin/out_gcloud_pubsub.rb +110 -0
- data/test/plugin/test_in_gcloud_pubsub.rb +387 -0
- data/test/plugin/test_out_gcloud_pubsub.rb +226 -0
- data/test/test_helper.rb +31 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c40c4cd8a4d0c00706354f721a7d152c10fdc7bfe8ce52bdc39b268d74e4dbb
|
4
|
+
data.tar.gz: dfbeb82161e39ffd4c3b6795a5adc1b595852f210f2d6ea109af81cafa9c5821
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 053474f74e5dbf96d413ab4f4c57f0ccc98631578ea6b7e4d95f1a95533f65a7fabc5109ebe9292de32637d59b30187652ea31bf03d9fcb260ea24ad461ad3bb
|
7
|
+
data.tar.gz: 03a60c08384edf78977d4814ed9d27fecf43a8ac1e014b6b730c4873ab1521fee459746155b1e746c6112823a75bdb062bdc23e99b0a74d69a76445bf5ab8937
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.1
|
5
|
+
- 2.2
|
6
|
+
- 2.3.6
|
7
|
+
- 2.4.3
|
8
|
+
- 2.5.0
|
9
|
+
- ruby-head
|
10
|
+
|
11
|
+
gemfile:
|
12
|
+
- Gemfile
|
13
|
+
|
14
|
+
branches:
|
15
|
+
only:
|
16
|
+
- master
|
17
|
+
|
18
|
+
before_install: gem update bundler
|
19
|
+
script: bundle exec rake test
|
20
|
+
|
21
|
+
sudo: false
|
22
|
+
|
23
|
+
matrix:
|
24
|
+
allow_failures:
|
25
|
+
- rvm: ruby-head
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
## ChangeLog
|
2
|
+
|
3
|
+
### Release 1.3.1 - 2018/06/08
|
4
|
+
|
5
|
+
- Input plugin
|
6
|
+
- Dumps raw string to logs for parsing errors
|
7
|
+
|
8
|
+
### Release 1.3.0 - 2018/05/18
|
9
|
+
|
10
|
+
- Make attributes available
|
11
|
+
|
12
|
+
### Release 1.2.0 - 2018/04/24
|
13
|
+
|
14
|
+
- Output plugin
|
15
|
+
- Support inject section
|
16
|
+
|
17
|
+
### Release 1.1.0 - 2018/03/30
|
18
|
+
|
19
|
+
- Output plugin
|
20
|
+
- The placeholder is now available in topic param
|
21
|
+
|
22
|
+
### Release 1.0.3 - 2018/03/29
|
23
|
+
|
24
|
+
- Bump up google-cloud-pubsub to v0.30.x
|
25
|
+
- Make config file Fluentd v1 compatible
|
26
|
+
|
27
|
+
### Release 1.0.2 - 2017/09/11
|
28
|
+
|
29
|
+
- Bump up google-cloud-pubsub to v0.27.x
|
30
|
+
|
31
|
+
### Release 1.0.1 - 2017/09/05
|
32
|
+
|
33
|
+
- Bump up google-cloud-pubsub to v0.26.x
|
34
|
+
|
35
|
+
### Release 1.0.0 - 2017/06/23
|
36
|
+
|
37
|
+
- Fluentd v0.14 ready
|
38
|
+
- Fluentd v0.12 is not supported in the later version
|
39
|
+
|
40
|
+
### Release 0.4.6 - 2017/05/14
|
41
|
+
|
42
|
+
- Output plugin
|
43
|
+
- Make messages exceeding configured size not be published because Pub/Sub clients cannot receive it
|
44
|
+
|
45
|
+
### Release 0.4.5 - 2017/04/02
|
46
|
+
|
47
|
+
- Bump up google-cloud-pubsub to v0.24.x
|
48
|
+
|
49
|
+
### Release 0.4.4 - 2017/03/07
|
50
|
+
|
51
|
+
- Bump up google-cloud-pubsub to v0.23.x
|
52
|
+
|
53
|
+
### Release 0.4.3 - 2017/02/16
|
54
|
+
|
55
|
+
- Input plugin
|
56
|
+
- Add "status" method to the http rpc api
|
57
|
+
|
58
|
+
### Release 0.4.2 - 2017/02/03
|
59
|
+
|
60
|
+
- Make retry to get topic/subscription when Pub/Sub API returns 50x code
|
61
|
+
|
62
|
+
### Release 0.4.1 - 2017/02/02
|
63
|
+
|
64
|
+
- Bump up google-cloud-pubsub to v0.22.x
|
65
|
+
- Input plugin
|
66
|
+
- Rescue 50x errors on acknowledge api
|
67
|
+
|
68
|
+
### Release 0.4.0 - 2017/01/21
|
69
|
+
|
70
|
+
- Input plugin
|
71
|
+
- Add feature to use record key as tag
|
72
|
+
|
73
|
+
### Release 0.3.4 - 2017/01/03
|
74
|
+
|
75
|
+
- Output plugin
|
76
|
+
- Rescue 50x errors
|
77
|
+
- Input plugin
|
78
|
+
- Guard emit to be called with multi-threading
|
79
|
+
- Rescue 50x errors
|
80
|
+
- Enabled to select whether to raise an exception if message processing failed
|
81
|
+
|
82
|
+
### Release 0.3.3 - 2016/12/03
|
83
|
+
|
84
|
+
- Input plugin
|
85
|
+
- Fix undefined variable error
|
86
|
+
|
87
|
+
### Release 0.3.2 - 2016/11/13
|
88
|
+
|
89
|
+
- Add plugin param desc
|
90
|
+
- Input plugin
|
91
|
+
- Improve handling to acknowledge messages
|
92
|
+
|
93
|
+
### Release 0.3.1 - 2016/11/03
|
94
|
+
|
95
|
+
- Output plugin
|
96
|
+
- Improve error handling
|
97
|
+
|
98
|
+
### Release 0.3.0 - 2016/10/30
|
99
|
+
|
100
|
+
- Bump up google-cloud-pubsub to v0.21
|
101
|
+
- Input plugin
|
102
|
+
- Add multithreaded pulling feature
|
103
|
+
|
104
|
+
### Release 0.2.0 - 2016/10/15
|
105
|
+
|
106
|
+
- Input plugin
|
107
|
+
- Add HTTP RPC feature
|
108
|
+
|
109
|
+
### Release 0.1.4 - 2016/09/19
|
110
|
+
|
111
|
+
- Input plugin
|
112
|
+
- `pull_interval` can be specified float value
|
113
|
+
- `topic` must be specified
|
114
|
+
|
115
|
+
### Release 0.1.3 - 2016/09/17
|
116
|
+
|
117
|
+
- Input plugin
|
118
|
+
- Fix error handling and add debug logging
|
119
|
+
|
120
|
+
### Release 0.1.2 - 2016/09/11
|
121
|
+
|
122
|
+
- Output plugin
|
123
|
+
- Change default max message size and add debug message
|
124
|
+
|
125
|
+
### Release 0.1.1 - 2016/08/27
|
126
|
+
|
127
|
+
- Bump up google-cloud-pubsub (gcloud-ruby) to 0.20
|
128
|
+
|
129
|
+
### Release 0.1.0 - 2016/08/22
|
130
|
+
|
131
|
+
- Use formatter / parser plugin and add format configuration
|
132
|
+
- Bump up gcloud-ruby to 0.12
|
133
|
+
- Remove dependency on lightening buffer
|
134
|
+
- Fix error caused by Pub/Sub quotas
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 mdoi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# fluent-plugin-gcloud-pubsub-custom
|
2
|
+
|
3
|
+
[](https://travis-ci.org/mia-0032/fluent-plugin-gcloud-pubsub-custom)
|
4
|
+
[](http://badge.fury.io/rb/fluent-plugin-gcloud-pubsub-custom)
|
5
|
+
|
6
|
+
This plugin is forked from https://github.com/mdoi/fluent-plugin-gcloud-pubsub
|
7
|
+
|
8
|
+
## Overview
|
9
|
+
|
10
|
+
[Google Cloud Pub/Sub](https://cloud.google.com/pubsub/) Input/Output(BufferedOutput) plugin for [Fluentd](http://www.fluentd.org/) with [google-cloud](https://googlecloudplatform.github.io/google-cloud-ruby/) gem
|
11
|
+
|
12
|
+
- Publish messages to Google Cloud Pub/Sub
|
13
|
+
- Pull messages from Google Cloud Pub/Sub
|
14
|
+
|
15
|
+
## Preparation
|
16
|
+
|
17
|
+
- Create a project on Google Developer Console
|
18
|
+
- Add a topic of Cloud Pub/Sub to the project
|
19
|
+
- Add a pull style subscription to the topic
|
20
|
+
- Download your credential (json) or [set scope on GCE instance](https://cloud.google.com/compute/docs/api/how-tos/authorization)
|
21
|
+
|
22
|
+
When using output plugin, you need to grant Pub/Sub Publisher and Pub/Sub Viewer role to IAM.
|
23
|
+
|
24
|
+
Also, when using input plugin, you need to grant Pub/Sub Subscriber and Pub/Sub Viewer role to IAM.
|
25
|
+
|
26
|
+
## Requirements
|
27
|
+
|
28
|
+
| fluent-plugin-gcloud-pubsub-custom | fluentd | ruby |
|
29
|
+
|------------------------|---------|------|
|
30
|
+
| >= 1.0.0 | >= v0.14.0 | >= 2.1 |
|
31
|
+
| < 1.0.0 | >= v0.12.0 | >= 1.9 |
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
Install by gem:
|
36
|
+
|
37
|
+
```shell
|
38
|
+
$ gem install fluent-plugin-gcloud-pubsub-custom
|
39
|
+
```
|
40
|
+
|
41
|
+
**Caution**
|
42
|
+
|
43
|
+
This plugin doesn't work in [td-agent](http://docs.fluentd.org/articles/install-by-rpm).
|
44
|
+
|
45
|
+
Please use in [Fluentd installed by gem](http://docs.fluentd.org/articles/install-by-gem).
|
46
|
+
|
47
|
+
## Configuration
|
48
|
+
|
49
|
+
### Publish messages
|
50
|
+
|
51
|
+
Use `gcloud_pubsub` output plugin.
|
52
|
+
|
53
|
+
```
|
54
|
+
<match example.publish>
|
55
|
+
@type gcloud_pubsub
|
56
|
+
project <YOUR PROJECT>
|
57
|
+
key <YOUR KEY>
|
58
|
+
topic <YOUR TOPIC>
|
59
|
+
autocreate_topic false
|
60
|
+
max_messages 1000
|
61
|
+
max_total_size 9800000
|
62
|
+
max_message_size 4000000
|
63
|
+
<buffer>
|
64
|
+
@type memory
|
65
|
+
flush_interval 1s
|
66
|
+
</buffer>
|
67
|
+
<format>
|
68
|
+
@type json
|
69
|
+
</format>
|
70
|
+
</match>
|
71
|
+
```
|
72
|
+
|
73
|
+
- `project` (optional)
|
74
|
+
- Set your GCP project.
|
75
|
+
- Running fluentd on GCP, you don't have to specify.
|
76
|
+
- You can also use environment variable such as `GCLOUD_PROJECT`.
|
77
|
+
- `key` (optional)
|
78
|
+
- Set your credential file path.
|
79
|
+
- Running fluentd on GCP, you can use scope instead of specifying this.
|
80
|
+
- You can also use environment variable such as `GCLOUD_KEYFILE`.
|
81
|
+
- `topic` (required)
|
82
|
+
- Set topic name to publish.
|
83
|
+
- You can use placeholder in this param. See: https://docs.fluentd.org/v1.0/articles/buffer-section
|
84
|
+
- `autocreate_topic` (optional, default: `false`)
|
85
|
+
- If set to `true`, specified topic will be created when it doesn't exist.
|
86
|
+
- `max_messages` (optional, default: `1000`)
|
87
|
+
- Publishing messages count per request to Cloud Pub/Sub.
|
88
|
+
- See https://cloud.google.com/pubsub/quotas#other_limits
|
89
|
+
- `max_total_size` (optional, default: `9800000` = `9.8MB`)
|
90
|
+
- Publishing messages bytesize per request to Cloud Pub/Sub. This parameter affects only message size. You should specify a little smaller value than quota.
|
91
|
+
- See https://cloud.google.com/pubsub/quotas#other_limits
|
92
|
+
- `max_message_size` (optional, default: `4000000` = `4MB`)
|
93
|
+
- Messages exceeding `max_message_size` are not published because Pub/Sub clients cannot receive it.
|
94
|
+
- `attribute_keys` (optional, default: `[]`)
|
95
|
+
- Publishing the set fields as attributes.
|
96
|
+
|
97
|
+
### Pull messages
|
98
|
+
|
99
|
+
Use `gcloud_pubsub` input plugin.
|
100
|
+
|
101
|
+
```
|
102
|
+
<source>
|
103
|
+
@type gcloud_pubsub
|
104
|
+
tag example.pull
|
105
|
+
project <YOUR PROJECT>
|
106
|
+
key <YOUR KEY>
|
107
|
+
topic <YOUR TOPIC>
|
108
|
+
subscription <YOUR SUBSCRIPTION>
|
109
|
+
max_messages 1000
|
110
|
+
return_immediately true
|
111
|
+
pull_interval 0.5
|
112
|
+
pull_threads 2
|
113
|
+
parse_error_action exception
|
114
|
+
enable_rpc true
|
115
|
+
rpc_bind 0.0.0.0
|
116
|
+
rpc_port 24680
|
117
|
+
<parse>
|
118
|
+
@type json
|
119
|
+
</parse>
|
120
|
+
</source>
|
121
|
+
```
|
122
|
+
|
123
|
+
- `tag` (required)
|
124
|
+
- Set tag of messages.
|
125
|
+
- If `tag_key` is specified, `tag` is used as tag when record don't have specified key.
|
126
|
+
- `tag_key` (optional)
|
127
|
+
- Set key to be used as tag.
|
128
|
+
- `project` (optional)
|
129
|
+
- Set your GCP project
|
130
|
+
- Running fluentd on GCP, you don't have to specify.
|
131
|
+
- You can also use environment variable such as `GCLOUD_PROJECT`.
|
132
|
+
- `key` (optional)
|
133
|
+
- Set your credential file path.
|
134
|
+
- Running fluentd on GCP, you can use scope instead of specifying this.
|
135
|
+
- You can also use environment variable such as `GCLOUD_KEYFILE`.
|
136
|
+
- `topic` (required)
|
137
|
+
- Set topic name to pull.
|
138
|
+
- `subscription` (required)
|
139
|
+
- Set subscription name to pull.
|
140
|
+
- `max_messages` (optional, default: `100`)
|
141
|
+
- See maxMessages on https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/pull
|
142
|
+
- `return_immediately` (optional, default: `true`)
|
143
|
+
- See returnImmediately on https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/pull
|
144
|
+
- If `return_immediately` is `true` or pulling message is stopped by HTTP RPC, this plugin wait `pull_interval` each pull.
|
145
|
+
- `pull_interval` (optional, default: `5.0`)
|
146
|
+
- Pulling messages by intervals of specified seconds.
|
147
|
+
- `pull_threads` (optional, default: `1`)
|
148
|
+
- Set number of threads to pull messages.
|
149
|
+
- `attribute_keys` (optional, default: `[]`)
|
150
|
+
- Specify the key of the attribute to be emitted as the field of record.
|
151
|
+
- `parse_error_action` (optional, default: `exception`)
|
152
|
+
- Set error type when parsing messages fails.
|
153
|
+
- `exception`: Raise exception. Messages are not acknowledged.
|
154
|
+
- `warning`: Only logging as warning.
|
155
|
+
- `enable_rpc` (optional, default: `false`)
|
156
|
+
- If `true` is specified, HTTP RPC to stop or start pulling message is enabled.
|
157
|
+
- `rpc_bind` (optional, default: `0.0.0.0`)
|
158
|
+
- Bind IP address for HTTP RPC.
|
159
|
+
- `rpc_port` (optional, default: `24680`)
|
160
|
+
- Port for HTTP RPC.
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
1. Fork it
|
165
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
166
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
167
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
168
|
+
5. Create a new Pull Request
|
169
|
+
|
170
|
+
## TODO
|
171
|
+
|
172
|
+
- Add `tag` attribute in output plugin and use `tag` attribute as tag in input plugin.
|
173
|
+
- Send ack after other output plugin committed (if possible).
|
174
|
+
|
175
|
+
## Authors
|
176
|
+
|
177
|
+
- [@mdoi](https://github.com/mdoi) : First author
|
178
|
+
- [@mia-0032](https://github.com/mia-0032) : This version author
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
7
|
+
test.libs << 'lib' << 'test'
|
8
|
+
test.test_files = FileList['test/plugin/test_*.rb']
|
9
|
+
test.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => [:build]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-gcloud-pubsub-custom-subscriber"
|
6
|
+
gem.description = "Google Cloud Pub/Sub input/output plugin for Fluentd event collector without auto-create topic requiring only Pub/Sub subscriber ACL"
|
7
|
+
gem.license = "MIT"
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = "1.3.1"
|
10
|
+
gem.authors = ["BL-Logging-Engineer"]
|
11
|
+
gem.has_rdoc = false
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
|
17
|
+
gem.add_runtime_dependency "fluentd", [">= 0.14.15", "< 2"]
|
18
|
+
gem.add_runtime_dependency "google-cloud-pubsub", "~> 0.30.0"
|
19
|
+
|
20
|
+
gem.add_development_dependency "bundler"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "test-unit"
|
23
|
+
gem.add_development_dependency "test-unit-rr"
|
24
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'google/cloud/pubsub'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
module GcloudPubSub
|
5
|
+
class Error < StandardError
|
6
|
+
end
|
7
|
+
class RetryableError < Error
|
8
|
+
end
|
9
|
+
|
10
|
+
class Message
|
11
|
+
attr_reader :message, :attributes
|
12
|
+
def initialize(message, attributes={})
|
13
|
+
@message = message
|
14
|
+
@attributes = attributes
|
15
|
+
end
|
16
|
+
|
17
|
+
def bytesize()
|
18
|
+
attr_size = 0
|
19
|
+
@attributes.each do |key, val|
|
20
|
+
attr_size += key.bytesize + val.bytesize
|
21
|
+
end
|
22
|
+
@message.bytesize + attr_size
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Publisher
|
27
|
+
def initialize(project, key, autocreate_topic)
|
28
|
+
@pubsub = Google::Cloud::Pubsub.new project_id: project, credentials: key
|
29
|
+
@autocreate_topic = autocreate_topic
|
30
|
+
@topics = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def topic(topic_name)
|
34
|
+
return @topics[topic_name] if @topics.has_key? topic_name
|
35
|
+
|
36
|
+
client = @pubsub.topic topic_name
|
37
|
+
if client.nil? && @autocreate_topic
|
38
|
+
client = @pubsub.create_topic topic_name
|
39
|
+
end
|
40
|
+
if client.nil?
|
41
|
+
raise Error.new "topic:#{topic_name} does not exist."
|
42
|
+
end
|
43
|
+
|
44
|
+
@topics[topic_name] = client
|
45
|
+
client
|
46
|
+
end
|
47
|
+
|
48
|
+
def publish(topic_name, messages)
|
49
|
+
topic(topic_name).publish do |batch|
|
50
|
+
messages.each do |m|
|
51
|
+
batch.publish m.message, m.attributes
|
52
|
+
end
|
53
|
+
end
|
54
|
+
rescue Google::Cloud::UnavailableError, Google::Cloud::DeadlineExceededError, Google::Cloud::InternalError => ex
|
55
|
+
raise RetryableError.new "Google api returns error:#{ex.class.to_s} message:#{ex.to_s}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Subscriber
|
60
|
+
def initialize(project, key, topic_name, subscription_name)
|
61
|
+
pubsub = Google::Cloud::Pubsub.new project_id: project, credentials: key
|
62
|
+
topic = pubsub.topic topic_name
|
63
|
+
@client = topic.subscription subscription_name
|
64
|
+
raise Error.new "subscription:#{subscription_name} does not exist." if @client.nil?
|
65
|
+
end
|
66
|
+
|
67
|
+
def pull(immediate, max)
|
68
|
+
@client.pull immediate: immediate, max: max
|
69
|
+
rescue Google::Cloud::UnavailableError, Google::Cloud::DeadlineExceededError, Google::Cloud::InternalError => ex
|
70
|
+
raise RetryableError.new "Google pull api returns error:#{ex.class.to_s} message:#{ex.to_s}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def acknowledge(messages)
|
74
|
+
@client.acknowledge messages
|
75
|
+
rescue Google::Cloud::UnavailableError, Google::Cloud::DeadlineExceededError, Google::Cloud::InternalError => ex
|
76
|
+
raise RetryableError.new "Google acknowledge api returns error:#{ex.class.to_s} message:#{ex.to_s}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|